Marshalling array of strcuture

S

Senthil

Hi,
I am using a COM component in C# client. The COM component has a method
which accepts an unallocated structure pointer. The method allocates memory
and returns filled up strcuture array. The method exceutes properly but when
the structure array is read in C# it does not return the filled in value
instaed gives garbage values..... I am not able to identify the reason for
this. Is there any link that could put more light on this?
Thanks for the help.

Sample Code:
The COM IDL conatins the structure definition.The strcuture has some enum
members.

typedef enum MY_STATUS
{
SUCCESS=100;
FAILURE=0;
}
struct MY_DATA
{
MY_STATUS s;
int size;
}

void Fill(MY_DATA ** pdata);

This method when called in C# client looks like this

void Fill(Intptr pdata)

Using StructuretoPtr a Intptr is created and passed.
Using PtrtoStructure the returned data is read. This does not return the
desired value.
 
M

Mattias Sjögren

void Fill(MY_DATA ** pdata);
This method when called in C# client looks like this

void Fill(Intptr pdata)

It should be

void Fill(out IntPtr pdata)


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top