all groups > dotnet interop > september 2005 >
You're in the

dotnet interop

group:

COMException accessing C++ COM VARIANT


COMException accessing C++ COM VARIANT sathya.krishnamurthy NO[at]SPAM gmail.com
9/28/2005 6:04:23 AM
dotnet interop:
Hello Everybody

I have an ActiveX DLL, the base implementation is

HRESULT GlobalComputeClass ([in] VARIANT *inArr, [out,retval] double
*pval);

The VARIANT array contains all doubles. The implementation is

STDMETHODIMP CMP::GlobalComputeClass (VARIANT *inArr, double *pVal) {
// Trying to access the the double array
double *internalArray;
if (SafeArrayAccessData(*inArr->pparray, (void HUGEP
**)&internalArray) != S_OK) {
cout << "Unable to access input array"<<endl;
}
....
}

The ActiveX DLL works wonderfully when I try to access the function
using Excel Macros. Now, I tried to use C# (Using Visual C# Express). I
added the PCMLibrary as a reference.

The object inside the C# is now available as
public virtual double GlobalComputeClass(ref object inArr)

static void Main(string[] args)
{
CMPLib.CMPClass test = new CMPLib.CMPClass();

Double[] fvalue = { 1, 2, 3, 4, 5 };
VariantWrapper var = new VariantWrapper(fvalue);
object mval = (object)fvalue;
try
{
double retval = test.GlobalComputeClass (ref mval);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}

This creates an exception as
"System.Runtime.InteropServices.COMException (0x80010105): The server
threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"

I tried several techniques, but since Im very new to this C#, I dont
have a clue where the problem.

Can someone please help me out ?

Thanks a lot.

Cheers
Sathya
Re: COMException accessing C++ COM VARIANT Willy Denoyette [MVP]
10/3/2005 12:00:00 AM
Hard to tell if you don't post the whole code, for instance how does this
VariantWrapper looks like?

Willy.

[quoted text, click to view]

Re: COMException accessing C++ COM VARIANT Richard T. Edwards
10/3/2005 7:12:59 AM
At the risk of getting skinned alive, I will ask. Have you tried using
marshalas yet?
[quoted text, click to view]

Re: COMException accessing C++ COM VARIANT sathya.krishnamurthy NO[at]SPAM gmail.com
10/3/2005 7:43:38 AM
Hi

Im very new to C#, Can you let me know how to specify that ?

The input function ([in] VARIANT *arr) for some reason gets translated
to (ref object). Is there any way to retain the original names ?

This works fine with VisualBasic and C++. In c# i have several problem.

Thanks for your sugeestions.

Sathya
AddThis Social Bookmark Button