简体   繁体   English

为什么COM方法调用返回RPC_S_INTERNAL_ERROR?

[英]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.

相关问题 为什么 SerialPort 的 ReadByte 方法返回的是 Int 而不是 Byte? - Why Does SerialPort's ReadByte Method Return an Int instead of a Byte? 为什么对COM组件的调用仅使用VisualStudio QuickWatch窗口返回值? - Why does a call to a COM component only return values using the VisualStudio QuickWatch window? 如何在另一个方法内部模拟方法调用的返回 - How to mock a return of method call internal a other method 为什么这次调用更新电子邮件主题会返回错误? - Why does this call to update the email subject return an error? 此方法的return语句返回什么? - What does this method's return statement return? 为什么此方法返回 boolean? - Why does this method return a boolean? 为什么C#不允许我在return语句中调用void方法? - Why does C# not allow me to call a void method as part of the return statement? 为什么 WebApi 在 json 响应中返回内部 class 的属性 - Why does WebApi return property of internal class in json response 错误:从未调用过的方法上的“找不到 RPC 方法” - Error: "RPC method not found" on method that was never called 为什么方法调用将非易失性变量的值刷新到主线程? - Why does a method call flush the nonvolatile variable's value to the main thread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM