Variant problem with COM,C# ---help me

S

srinivas

Hi ,

Pls help me to solve this problem .

/* --this is one of the function in COM component */

System.int32 ProjectLIsts(LPCTSTR prj , VARIANT* prj_list)

{
prj_Lists= { ARRY OF STRUCTES . ,.ONE STRUCTE FOR EACH PROJECT }

returns TOTAL NUM of PROJECTS
}

???.
If I add this COM component to my .net project , then it converted
as

System.Int32 ListProjects (System.string , System.Object prj_list )



Then I wrote the code as

API obj=new API();
int no_of_projects;
object p;
no_of_projects =Obj. ProjectLIsts(" " , out p);

here it returns no_of_projects correctly but if I use out variable p I
got
null reference exception

How can I read the array of struct
here I got no_of_projects is correct .But how can read p data .

If I print Console.WriteLine(p.GetType())

I got Null reference exception .

Could any one help me

Regards,
Thanks in advance
 
N

Nicholas Paldino [.NET/C# MVP]

srinivas,

You can't just pass the array as a pointer to a Variant. You have to
pass a SAFEARRAY structure in order for COM interop to correctly pass the
array between .NET and COM.

Hope this helps.
 

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