gpt4 book ai didi

c# - 0x800401f3 COMInterop Dll 类字符串无效

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:27:04 24 4
gpt4 key购买 nike

我有一个注册为 COM Interop 的 C# Dll:

[Guid("B41C2229-DBBD-4614-AE28-BFAE82B10F20")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ITestCls
{
[DispId(1)]
string test(string input);
}

[Guid("5E88B6B8-AE17-40A0-917A-51DEBD818145")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("TestNm.TestCls")]
public class TestCls : ITestCls
{
public string test(string input)
{
Console.WriteLine("INSIDE CS :: ");
return "CS :: ARE YOU TESTING WITH THIS INPUT " + input;
}
}

我试图从我的 C++ 代码中调用相同的方法:

    CoInitialize(NULL); 
std::cout << data << '\n';
_bstr_t bstrt(data);
BSTR lResult;
CComQIPtr<IWPrint> iWrapClass;
HRESULT hresult;
hresult = iWrapClass.CoCreateInstance(L"TestNm.TestCls");
printf("0x%08lx", hresult);
if (SUCCEEDED (hresult))
{
iWrapClass->test(bstrt,&lResult);
wprintf(L"Response %s\n", lResult);
}
CoUninitialize();
return lResult;

当我从其他机器运行相同的 HRESULT 时,我的开发机器一切正常:

 0x800401f3 

我是否遗漏了一些注册信息?

谢谢

最佳答案

故障排除时要尝试的几件事:

  • 将托管程序集的 objective-c PU 平台设置为 x86(32 位);
  • 确保程序集有一个 strong name ;
  • 在目标机器上,使用 32 位版本的 RegAsm.exe(C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe不是 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe).
  • 使用 RegAsm.exe/codebase 在目标机器上注册它(为此需要一个强大的程序集名称)。

关于c# - 0x800401f3 COMInterop Dll 类字符串无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17673418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com