I am getting error from a method call when I try to access the functions of an interface.
1 2 3 4 5 6 7 8 9
My_DLL::IStubRequest *request = NULL;
CoCreateInstance(__uuidof(My_DLL::StubRequest), NULL, CLSCTX_INPROC_SERVER, __uuidof(My_DLL::IStubRequest), (void**)&request); //this is ok.
My_DLL::IStubResponse *response = NULL;
request->DoSomething((My_DLL::_StubResponse**) &response); //HRESULT is ok, but using it on a method without return value will cause System.AccessViolationException
response->Print();//System.AccessViolationException
BSTR * valuePtr = NULL;
response->GetValue(valuePtr); //this is not ok
namespace com.myApp.msg
{
public interface IStubRequest
{
StubResponse DoSomething();
}
publicclass StubRequest : IStubRequest
{
public StubRequest()
{
}
public StubResponse DoSomething()
{
//do something and return StubResponse
}
}
public interface IStubResponse
{
string GetValue();
void Print();
}
publicclass StubResponse : IStubResponse
{
private string value = null;
public StubResponse(string value)
{
this.value = value;
}
public string GetValue()
{
return value;
}
publicvoid Print()
{
Console.WriteLine("hello world");
}
}
}
The GetValue() call results in a popup window saying
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function declared with a different calling convention.