COM component's C++ client works but .net client doesn't?

S

Simon LU

I have a COM component in ATL, one of its method's IDL define is as the
following:
HRESULT SetValue(long a, [in] long* b,[in]string* c, [in]VARIANT* d,
[out,retval] ConfirmVal e);
here ConfirmVal is a Enum define by IDL.

The VC++ client has no problem to call it by using smart pointer as the
followings:
long a=0;
long b=-1;
CComBSTR c=L"NAME";
d = ICxValuePtr(__uuidof(ICxValue)); //d is another smartpointer, it is a
IDispatch interface in IDL
ConfirmVal e;
ptr->SetValue(a,&b,&c,d,&e)
....

When my C# client calls it as the followings, it throws COMException with
"Unspecified error":
int a=0;
int b=-1;
string c="NAME";
CxValueObject d = new CxValueObject(); //CxValueObject is the class
corresponding to ICxValue interface in the assembly converted by tlbimp.exe
ConfirmVal e;
obj.SetValue(a, ref b, ref c, d, out e); //Throws COMException with
"Unspecified error" here
....

The signature of SetValue in C# in the assembly is void SetValue(int,ref
int,ref string,object,out ConfirmVal).

Can anybody give a clue?

Thanks in advance.

Simon
 
K

Kumar Gaurav Khanna [.NET MVP]

Hi!

Typically, when you TLBIMP a COM class, the class is actually suffixed with
the "Class" string in its .NET version, while the original class name is
actually made to be an interface. So try this:

CxValueObject d = new CxValueObjectClass();

Regards,
Gaurav Khanna

--
----------------------------------------------------------------------------
----------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/
 

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