[英]Why does COM method call return RPC_S_INTERNAL_ERROR?
I have a COM class programmed in C++. 我有一个用C ++编程的COM类。 It was made by a coworker who doesn't longer work here.
它是由不再在这里工作的同事制作的。
This is one line from the IDL file: 这是IDL文件的一行:
HRESULT MyMethod([out, size_is(255)] LPOLESTR arg1, [in, out] MyStruct* arg2);
When I add a reference to the C++ DLL in a C# .Net project, it's translated as follows: 当我在C#.Net项目中添加对C ++ DLL的引用时,其翻译如下:
void MyMethod([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder arg1, [In, Out] ref MyStruct arg2);
My test code is as follows: 我的测试代码如下:
StringBuilder sb = new StringBuilder();
MyStruct s = new MyStruct();
MyCOMClass c = new MyComClass();
c.MyMethod(sb, ref s);
I have also tried doing 我也尝试过
StringBuilder sb = new StringBuilder(255);
With similar results. 结果相似。
I am getting a 0x800706e6 exception, meaning RPC_S_INTERNAL_ERROR. 我收到一个0x800706e6异常,表示RPC_S_INTERNAL_ERROR。 I think the problem lies in the LPOLESTR/StringBuilder, because I have several similar projects with strings as BSTR* instead of LPOLESTR and everything works correctly (they are translated to "out String" instead of "StringBuilder").
我认为问题出在LPOLESTR / StringBuilder上,因为我有几个类似的项目,它们的字符串与BSTR *而不是LPOLESTR一样,并且一切正常(将它们转换为“ out String”而不是“ StringBuilder”)。
There is a sample app with the DLL writeen in VB6, and the method is called in this way: 有一个示例应用程序,在VB6中写入了DLL,并以这种方式调用该方法:
Dim s as MyStruct
Dim str as String * 255
Dim c as new MyComClass()
c.MyMethod(str, s)
And eveything works fine. 而且一切正常。
Any idea about what's going on? 关于发生了什么的任何想法?
I still don't know what the problem is, but I have found a solution, changing in the IDL file 我仍然不知道问题出在哪里,但是我找到了解决方案,在IDL文件中进行了更改
HRESULT MyMethod([out, size_is(255)] LPOLESTR arg1, [in, out] MyStruct* arg2);
to 至
HRESULT MyMethod([in, out] LPOLESTR arg1, [in, out] MyStruct* arg2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.