G
Guest
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: _CrtIsValidHeapPointer(pUserData)
....
"
If I press ignore three times the whole application crashes. Here is the code:
[DllImport(g_wrapper_dll_path)]
unsafe static extern int GetEncoders(
void* dvpsdk,
ref int[] devices_ids);
IntPtr m_DVPSDK_ptr;
void* l_ptr = m_DVPSDK_ptr.ToPointer();
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.ToPointer(),
devices_ids);
}
const int GetEncoders(
DVP1412DLL* dvpsdk,
array<int>^ devices_ids)
{
int l_nr_of_devices =
dvpsdk->DVP1412_GetNoOfDevices();
if (l_nr_of_devices == 0)
{
return -3;
}
int* l_tmp = new int[devices_ids->Length];
int l_res = dvpsdk->DVP1412_InitSDK(
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_CloseSDK();
return l_nr_of_devices;
}
else
{
return l_res;
}
}
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: _CrtIsValidHeapPointer(pUserData)
....
"
If I press ignore three times the whole application crashes. Here is the code:
[DllImport(g_wrapper_dll_path)]
unsafe static extern int GetEncoders(
void* dvpsdk,
ref int[] devices_ids);
IntPtr m_DVPSDK_ptr;
void* l_ptr = m_DVPSDK_ptr.ToPointer();
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.ToPointer(),
devices_ids);
}
const int GetEncoders(
DVP1412DLL* dvpsdk,
array<int>^ devices_ids)
{
int l_nr_of_devices =
dvpsdk->DVP1412_GetNoOfDevices();
if (l_nr_of_devices == 0)
{
return -3;
}
int* l_tmp = new int[devices_ids->Length];
int l_res = dvpsdk->DVP1412_InitSDK(
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_CloseSDK();
return l_nr_of_devices;
}
else
{
return l_res;
}
}