Hi GURUs,
I have created a new COM DLL and just wondering how to return a new COM object.
Here is my code to return a new object.
Code:
HRESULT __stdcall CMainTestClass::GetSamTest(IAdd **ppRetVal)
{
CAddClass *pAddClass = new CAddClass();
*ppRetVal = pAddClass;
return S_OK;
}
When I call this function in C#, it gave me this error:
The runtime has encountered a fatal error. The address of the error was at 0x7f628678, on thread 0x105c. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
My C# code:
Code:
MyTestLib.MainTestClass oMainObject = new MyTestLib.MainTestClass();
MyTestLib.AddClass addObject = (oMainObject .GetSamTest() as MyTestLib.AddClass );
MessageBox.Show(addObject.DoTheAddition().ToString()); //it fails here
Thanks for any help