无法从返回值指向接口的指针调用方法 [英] Cannot call method from return value's pointer to interface
问题描述
   
当我尝试访问界面的功能时,我从方法调用中收到错误。
My_DLL :: IStubRequest * request = NULL;
CoCreateInstance(__ uuidof(My_DLL :: StubRequest),NULL,CLSCTX_INPROC_SERVER,__ uuidof(My_DLL :: IStubRequest),(void **)& request); //还行吧。
My_DLL :: IStubResponse * response = NULL;
request-> DoSomething((My_DLL :: _ StubResponse **)& response); // HRESULT没问题,但在没有返回值的方法上使用它会导致System.AccessViolationExceptionresponse-> Print(); // System.AccessViolationException
BSTR * valuePtr = NULL;
response-> GetValue(valuePtr); //这不行
C#中的Stub *类如下:
命名空间com.myApp.msg
{
公共接口IStubRequest
{
StubResponse DoSomething();
}
公共类StubRequest:IStubRequest
{
public StubRequest()
{
}
public StubResponse DoSomething()
{
//做某事并返回StubResponse
}
}
公共接口IStubResponse
{
string GetValue() ;void Print();
}
公共类StubResponse:IStubResponse
{
private string value = null;
public StubResponse(string value)
{
this.value = value;
}
公共字符串GetValue()
{
返回值;
}public void Print(){
Console.WriteLine(" hello world");
}
}
}
GetValue()调用会产生一个弹出窗口,说明是
>运行时检查失败#0 - ESP的值未在函数调用中正确保存。这通常是调用使用一个调用约定声明的函数的结果,该函数使用不同的调用约定声明的函数。
如何修复它?
$
$
您好,
My_DLL :: IStubRequest是用户定义的类型。它是什么类型的?
并在用户定义的类型My_DLL :: IStubRequest中向我们展示GetValue的声明(s?)。
问候,吉
I am getting error from a method call when I try to access the functions of an interface.
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
The Stub* classes in C# are as follows:
namespace com.myApp.msg { public interface IStubRequest { StubResponse DoSomething(); } public class StubRequest : IStubRequest { public StubRequest() { } public StubResponse DoSomething() { //do something and return StubResponse } } public interface IStubResponse { string GetValue();
void Print(); } public class StubResponse : IStubResponse { private string value = null; public StubResponse(string value) { this.value = value; } public string GetValue() { return value; }
public void 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.
How to fix it?
Hello,
My_DLL::IStubRequest is a user defined type. What type is it?
And show us the declaration(s?) of GetValue in your user defined type My_DLL::IStubRequest.
Regards, Guido
这篇关于无法从返回值指向接口的指针调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!