G
Guest
Hi we have a 3rd party in process com dll, which was written In C++ and our
client is in c#.
All is working fine apart from we get a callback from the DLL which contains
an array of structures.
The callback signature looks like this,
With the list stored in the radioSubscriberAttributes3List, which is defined
in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_GetRadioSubscribersConfirmation(uint
radioSubscriberAttributes3ListSize, ref tcsRadioSubscriberAttributes3_t
radioSubscriberAttributes3List, tcsBoolean_t endOfCollection, short cookie);
trouble is we only get the first structure back, if I use the code below.
tcsRadioSubscriberAttributes3_t[] DATA = new
tcsRadioSubscriberAttributes3_t[3];
temp = Marshal.AllocCoTaskMem(IntPtr.Size);
buffer = Marshal.AllocCoTaskMem(IntPtr.Size);
//get the address in buffer
Marshal.StructureToPtr(radioSubscriberAttributes3List, buffer, true);
temp = buffer;
for(int a=0; a<radioSubscriberAttributes3ListSize; a++ )
{
DATA[a] =
(tcsRadioSubscriberAttributes3_t)Marshal.PtrToStructure(temp,radioSubscriberAttributes3List.GetType());
temp = (IntPtr)((int)buffer +
Marshal.SizeOf(radioSubscriberAttributes3List.GetType()));
}
I guess StructureToPtr copies the first item from the list passed to us,
into managed memory, and not the rest.
Any help, as if we don’t get this working we will have to write the client
in Delphi !!!!
Cheers Rich.
client is in c#.
All is working fine apart from we get a callback from the DLL which contains
an array of structures.
The callback signature looks like this,
With the list stored in the radioSubscriberAttributes3List, which is defined
in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_GetRadioSubscribersConfirmation(uint
radioSubscriberAttributes3ListSize, ref tcsRadioSubscriberAttributes3_t
radioSubscriberAttributes3List, tcsBoolean_t endOfCollection, short cookie);
trouble is we only get the first structure back, if I use the code below.
tcsRadioSubscriberAttributes3_t[] DATA = new
tcsRadioSubscriberAttributes3_t[3];
temp = Marshal.AllocCoTaskMem(IntPtr.Size);
buffer = Marshal.AllocCoTaskMem(IntPtr.Size);
//get the address in buffer
Marshal.StructureToPtr(radioSubscriberAttributes3List, buffer, true);
temp = buffer;
for(int a=0; a<radioSubscriberAttributes3ListSize; a++ )
{
DATA[a] =
(tcsRadioSubscriberAttributes3_t)Marshal.PtrToStructure(temp,radioSubscriberAttributes3List.GetType());
temp = (IntPtr)((int)buffer +
Marshal.SizeOf(radioSubscriberAttributes3List.GetType()));
}
I guess StructureToPtr copies the first item from the list passed to us,
into managed memory, and not the rest.
Any help, as if we don’t get this working we will have to write the client
in Delphi !!!!
Cheers Rich.