473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# to CLI call fails somewhere...

I have the below C# definitions and function call to an unsafe C++/CLI
function in an external dll. When debugging the calls step by step everything
seems to work, but if I just run everything through without stopping I get
the following error:

"
Debug Assertion Failed!

Program: .....myprogram. .
File: dbgheap.c
Line: 1279

Expression: _CrtIsValidHeap Pointer(pUserDa ta)

....
"

If I press ignore three times the whole application crashes. Here is the code:

[DllImport(g_wra pper_dll_path)]
unsafe static extern int GetEncoders(
void* dvpsdk,
ref int[] devices_ids);

IntPtr m_DVPSDK_ptr;
void* l_ptr = m_DVPSDK_ptr.To Pointer();
int l_result = GetEncoders(
l_ptr,
ref m_devs_ids);

The C++/CLI functions:

extern "C" int GetEncoders(
System::IntPtr dvpsdk,
array<int>^ devices_ids)
{
return AdvantechImpl:: GetEncoders(
(DVP1412DLL*) dvpsdk.ToPointe r(),
devices_ids);
}

const int GetEncoders(
DVP1412DLL* dvpsdk,
array<int>^ devices_ids)
{
int l_nr_of_devices =
dvpsdk->DVP1412_GetNoO fDevices();

if (l_nr_of_device s == 0)
{
return -3;
}

int* l_tmp = new int[devices_ids->Length];

int l_res = dvpsdk->DVP1412_InitSD K(
l_nr_of_devices ,
l_tmp);

if (l_res == SUCCEEDED)
{
for (int l_i = 0; l_i < devices_ids->Length; ++l_i)
{
devices_ids[l_i] = l_tmp[l_i];
}

l_res = dvpsdk->DVP1412_CloseS DK();
return l_nr_of_devices ;
}
else
{
return l_res;
}
}

Oct 5 '07 #1
2 2291
I should add that m_devs_ids has the following definition:

[MarshalAs(Unman agedType.ByValA rray, SizeConst = g_max_devices)]
int[] m_devs_ids = new int[g_max_devices];
"Joachim" wrote:
I have the below C# definitions and function call to an unsafe C++/CLI
function in an external dll. When debugging the calls step by step everything
seems to work, but if I just run everything through without stopping I get
the following error:

"
Debug Assertion Failed!

Program: .....myprogram. .
File: dbgheap.c
Line: 1279

Expression: _CrtIsValidHeap Pointer(pUserDa ta)

...
"

If I press ignore three times the whole application crashes. Here is the code:

[DllImport(g_wra pper_dll_path)]
unsafe static extern int GetEncoders(
void* dvpsdk,
ref int[] devices_ids);

IntPtr m_DVPSDK_ptr;
void* l_ptr = m_DVPSDK_ptr.To Pointer();
int l_result = GetEncoders(
l_ptr,
ref m_devs_ids);

The C++/CLI functions:

extern "C" int GetEncoders(
System::IntPtr dvpsdk,
array<int>^ devices_ids)
{
return AdvantechImpl:: GetEncoders(
(DVP1412DLL*) dvpsdk.ToPointe r(),
devices_ids);
}

const int GetEncoders(
DVP1412DLL* dvpsdk,
array<int>^ devices_ids)
{
int l_nr_of_devices =
dvpsdk->DVP1412_GetNoO fDevices();

if (l_nr_of_device s == 0)
{
return -3;
}

int* l_tmp = new int[devices_ids->Length];

int l_res = dvpsdk->DVP1412_InitSD K(
l_nr_of_devices ,
l_tmp);

if (l_res == SUCCEEDED)
{
for (int l_i = 0; l_i < devices_ids->Length; ++l_i)
{
devices_ids[l_i] = l_tmp[l_i];
}

l_res = dvpsdk->DVP1412_CloseS DK();
return l_nr_of_devices ;
}
else
{
return l_res;
}
}
Oct 5 '07 #2

"Joachim" <Jo*****@discus sions.microsoft .comwrote in message
news:19******** *************** ***********@mic rosoft.com...
>I have the below C# definitions and function call to an unsafe C++/CLI
function in an external dll. When debugging the calls step by step
everything
seems to work, but if I just run everything through without stopping I get
the following error:

"
Debug Assertion Failed!

Program: .....myprogram. .
File: dbgheap.c
Line: 1279

Expression: _CrtIsValidHeap Pointer(pUserDa ta)

...
"

If I press ignore three times the whole application crashes. Here is the
code:

[DllImport(g_wra pper_dll_path)]
unsafe static extern int GetEncoders(
void* dvpsdk,
ref int[] devices_ids);

IntPtr m_DVPSDK_ptr;
void* l_ptr = m_DVPSDK_ptr.To Pointer();
int l_result = GetEncoders(
l_ptr,
ref m_devs_ids);

The C++/CLI functions:

extern "C" int GetEncoders(
System::IntPtr dvpsdk,
array<int>^ devices_ids)
{
return AdvantechImpl:: GetEncoders(
(DVP1412DLL*) dvpsdk.ToPointe r(),
devices_ids);
}

const int GetEncoders(
DVP1412DLL* dvpsdk,
array<int>^ devices_ids)
{
int l_nr_of_devices =
dvpsdk->DVP1412_GetNoO fDevices();

if (l_nr_of_device s == 0)
{
return -3;
}

int* l_tmp = new int[devices_ids->Length];

int l_res = dvpsdk->DVP1412_InitSD K(
l_nr_of_devices ,
l_tmp);
When l_nr_of_devices devices_ids->Length, this function overflows the
buffer and corrupts the heap.

Also, where is l_tmp freed (you must call delete[])?

>
if (l_res == SUCCEEDED)
{
for (int l_i = 0; l_i < devices_ids->Length; ++l_i)
{
devices_ids[l_i] = l_tmp[l_i];
}

l_res = dvpsdk->DVP1412_CloseS DK();
return l_nr_of_devices ;
}
else
{
return l_res;
}
}
Oct 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3911
by: Andy | last post by:
Hi, I've got some code which uses various "On Error" statements to try to trap some errors in VB6. When I try it on one machine (WinXP SP1) it works fine, but on another machine (WinXP SP2) it fails to trap the error and so the code fails. e.g. On Error Resume Next debug.print 3/0
4
1345
by: Brano Zarnovican | last post by:
Hi ! If I define 'f' like this def f(a): print a then, the call with keywords f(1, optional=2)
3
2669
by: jasonkester | last post by:
Just a heads up for anybody that comes across this in the future. Noticed a strange behavior in RegExp.test() today. Check out the following code. It will alternately display "chokes" and null, as every second call to .test() fails. <script> var str = "RegExp (chokes) on this every 2nd time"; var re = /chokes/g;
2
1495
by: Yogi21 | last post by:
Hi I have a sorted array containing strings. I am iterating through the array and clearing the contents one by one using "array.BinarySearch" to find each element. So far so good. But the moment I come to the last element, the BinarySearch method fails.It gives me a return value which is negative although the element is very much there. I am...
1
18051
by: drewmania001 | last post by:
i've read various info on the web including the following http://php.mirrors.ilisys.com.au/manual/en/ref.mysqli.php mySQL Version 4.1.16 PHP Version 5.1.2 with Zend Engine v2.1.0 OS Windows NT SERVER(2003) 5.2 build 3790 see http://drew.bounceme.net/phpinfo.php for more details
2
8675
by: Toolsmith | last post by:
The following code: C# code: Directory.CreateDirectory("D:\\somewhere\\somewhereelse\\here\\") works, but the following does flags the error: An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
54
5162
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor, ~MyLogClass(), I call: tw.WriteLine("some stuff"); tw.Close();
2
8396
by: rdilipk | last post by:
I am posting at the end of this post some code that P/Invoke's SetSystemTime to set the local system time. This call fails -- i.e the time is not set and the API returns false. However calling Marshal.GetLastWin32Error immediately afterwards returns an errorcode of 0 indicating that the operation somehow executed successfully. This is a...
2
1179
by: Philippe Poulard | last post by:
Hi folks ! I have some code like this that passes an anonymous function: foo.bar(p1, function(p2) { alert(p2); }); in foo.bar, i create a button with a listener; when it is executed, the following code fails to run:
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.