Call C# COM objects from C++

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top