Call C# COM objects from C++

G

Guest

I wrote a C# class library with tlb output,so i can call it from C++ codes.

My code in C# like:

[Guid("...")]
public struct item
{
string key;
double val;
}

[Guid("...")]
public interface IFirst
{
string try();
item[] tryAgain();
}

[Guid("...")]
public class First : IFirst
{
public string try(){...}
public item[] tryAgain(){...}
}

My code in C++ like:

IFirstPtr p;
p.CreateInstance(__uuidof(First));
_bstr_t bt = p->try();
SAFEARRAY* psa = p->tryAgain();

Well,my problem is here:
the p->try() call is processed OK,and i got the correct return values.
while the p->tryAgain() call failed,as i debugged into the .tli code
generated by IDE,
i found the HRESULT code of the raw_tryAgain() call is 0X80028019,says "old
format or invalid type library",which i thought meant nothing to me.

So,could anybody help me?
I am using VS.Net 2003.

Whyithappen
 
N

Nicholas Paldino [.NET/C# MVP]

Whyithappen,

I would try removing the Guid attribute from the struct, as I don't
think you need it.

Also, are you strong naming your assemblies, as well as placing the Guid
attribute on the assembly level?

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