how to marshal an array of unmanaged structure into a managed array of structures.

  • Thread starter amags kumar via .NET 247
  • Start date
A

amags kumar via .NET 247

Hi,

I am writing some code to Interop with COM. I have todetermine the parameters of COM function and I am usingFUNCDESC structure from typelibrary. My question is how tomarshal the lprgelemdescParam array structures. I have thefollowing code from another post in dotnet247.

What I am trying to do is to print the function declarationdefined by FUNCDESC structure in .net. Has anyone done this ?






IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam;

int ElementDescriptionSize = Marshal.SizeOf(newCOM.ELEMDESC().GetType());



for (int i = 0; i < funcdesc.cParams; i++)

{



COM.ELEMDESC ElementDescription;

int ElementDescriptionAddress;

int ElementDescriptionArrayByteOffset;

IntPtr ElementDescriptionPointer;



ElementDescription = new COM.ELEMDESC();

ElementDescriptionArrayByteOffset = i *ElementDescriptionSize;

ElementDescriptionAddress =ElementDescriptionArrayPtr.ToInt32();

ElementDescriptionAddress +=ElementDescriptionArrayByteOffset;

ElementDescriptionPointer =(IntPtr)(ElementDescriptionAddress);

ElementDescription =(COM.ELEMDESC)(Marshal.PtrToStructure(ElementDescriptionPointer,

typeof(COM.ELEMDESC)));



string paramstring =GetStringFromTypeDesc(typeinfo, ElementDescription.tdesc);

builder.Append(paramstring);



if (i < funcdesc.cParams - 1)

{

builder.Append(", ");

}



}





Is this the correct way to do this ? I am not sure if I amgetting correct values back when I executed the above code? Iwould appreciate any help on how to marshal an array ofunmanaged structure into a managed array of structures.







Thanks

-Arul
 

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