【发布时间】:2020-07-07 22:14:33
【问题描述】:
我按照文章中提到的步骤,
创建了一个 64 位 COM DLL (MyCOMdll.dll) 并创建了一个类 COMServer,如下所示,
namespace MyCOMdll
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[GuidAttribute("SOMGUID")]
public class COMServer
{
public ComServer() { }
public void TestMethod()
{
MathClass mathObj = new MathClass();
mathObj.Calc();
}
}
}
然后使用下面的命令使用 64 位版本的 Regasm 注册 MyCOMdll.dll,
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe MyCOMdll.dll /codebase
然后按照上述文章中的说明添加以下注册表项,
Windows 注册表编辑器 5.00 版
[HKEY_CLASSES_ROOT\AppID\{GUIDOFCOMSERVER}]
"DllSurrogate"=""
[HKEY_CLASSES_ROOT\CLSID\{GUIDOFCOMSERVER}]
"AppID"="{GUIDOFCOMSERVER}"
然后从 32 位控制台应用程序调用 TestMethod 如下,
// Access COM Object through registered Class Id
Type ComType = Type.GetTypeFromProgID("MyCOMdll.ComServer");
// Create an instance of the COM object
// This will invoke the default constructor of class ComServer
object ComObject = Activator.CreateInstance(ComType);
// Calling the Method "TestMethod" from 64-Bit COM server
ComType.InvokeMember("TestMethod", BindingFlags.InvokeMethod, null, ComObject, null);
当从 32 位控制台应用程序中使用此客户端代码时,它可以正常工作,没有任何问题。 我尝试从 32 位 Windows 服务中使用相同的代码,然后在这一行出现异常失败,
MathClass mathObj = new MathClass();
从 Windows 服务中使用 64 位 outproc 代理 dll 时是否需要进行任何特殊设置?
【问题讨论】:
-
请分享异常详情。
-
@OguzOzgul ,我发现 Utility.dll 的依赖 dll(Mathclass 在 Utility.dll 中定义)丢失。现在将这些依赖项的目录添加到 PATH 变量中。它工作正常。
标签: c# com 64-bit out-of-process