J
John Gallagher
I'm experiencing some confusion with converting double pointer in C#.
i'm calling a C api, but returning no values. I suspect I have issues
with my memory allocation in c#. Any help or pointers would be
appreciated. Thanks.
C code example:
typedef struct
{
unsigned char **test_list;
int count;
} GET_LIST;
memset( list, 0, sizeof( GET_LIST ) );
memset( display_list, 0, sizeof( GET_LIST ) );
GET_LIST *list,
GET_LIST *display_list
list->test_list=(uchar**)malloc( 10 * sizeof( uchar * ) );
display_list->test_list=(uchar**)malloc(10 * sizeof( uchar* ));
for (i = 0; i < list->10; i++ )
list->test_list = (uchar *)malloc( 256 * sizeof( uchar ) );
for (i = 0; i < display_opt->10; i++ )
display_list->test_list = (uchar *)malloc( 256 * sizeof( uchar ));
C# code example:
public struct GET_LIST
{
public IntPtr test_list;
public Int32 count;
}
_list = new GET_LIST();
_display_list = new GET_LIST();
_list.test_list = Marshal.AllocCoTaskMem(10 * 256);
intRetCode = TestWrapper.api_call(ref _list );
if (_list.count > 0 )
{
_display_list.test_list = Marshal.AllocCoTaskMem(10 * 256);;
intRetCode = TestWrapper.disp_fnct(ref _list, ref _display_list );
}
i'm calling a C api, but returning no values. I suspect I have issues
with my memory allocation in c#. Any help or pointers would be
appreciated. Thanks.
C code example:
typedef struct
{
unsigned char **test_list;
int count;
} GET_LIST;
memset( list, 0, sizeof( GET_LIST ) );
memset( display_list, 0, sizeof( GET_LIST ) );
GET_LIST *list,
GET_LIST *display_list
list->test_list=(uchar**)malloc( 10 * sizeof( uchar * ) );
display_list->test_list=(uchar**)malloc(10 * sizeof( uchar* ));
for (i = 0; i < list->10; i++ )
list->test_list = (uchar *)malloc( 256 * sizeof( uchar ) );
for (i = 0; i < display_opt->10; i++ )
display_list->test_list = (uchar *)malloc( 256 * sizeof( uchar ));
C# code example:
public struct GET_LIST
{
public IntPtr test_list;
public Int32 count;
}
_list = new GET_LIST();
_display_list = new GET_LIST();
_list.test_list = Marshal.AllocCoTaskMem(10 * 256);
intRetCode = TestWrapper.api_call(ref _list );
if (_list.count > 0 )
{
_display_list.test_list = Marshal.AllocCoTaskMem(10 * 256);;
intRetCode = TestWrapper.disp_fnct(ref _list, ref _display_list );
}