【发布时间】:2013-05-03 23:06:12
【问题描述】:
我有一个要在我的 php 应用程序中使用的 .net dll
我已经在 .net 应用程序上测试了 dll,它运行良好
我的 C# 类:
namespace CryptoCs
{
[Guid("15D16831-D6BE-43C4-AB4F-F0BAA35987DB")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CryptoCs")]
[ComVisible(true)]
public class Crypto : iCryptoCs
{
public Crypto()
{
}
public bool Login(string username, string password)
{
// some code
}
}
[Guid("5BDBB53A-571A-4EC7-B37E-A4D2A6A54DEB")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface iCryptoCs
{
[DispId(1)]
bool Login(string username, string password);
}
}
我的使用代码是:
$crypto = new COM('CryptoCs.Crypto');
此页面出现此错误:
创建 COM 对象失败
我尝试使用 gacutil.exe 注册 dll,结果是:
程序集成功添加到缓存中
但错误没有修复
我试过regasm.exe,结果是:
类型注册成功
还是一样的错误
我尝试了 REGSVR32.exe,但它给了我这个错误:
找不到入口点
我在 windows server 2003 sp2 上使用 vs2010 .net4
【问题讨论】:
-
.NET 程序集的标准注册工具确实是 regasm.exe,如果您不将其放入 GAC(但您将其放入 GAC),则带有 /Codebase。您在 php 中使用的 progid 应该与您指定的相同,因此是“CryptoCs”,而不是“CryptoCs.Crypto”。另外,去掉所有的 ClassInterface 和 InterfaceType 属性,最好使用默认值。
-
@SimonMourier 我将不得不等到星期六来测试这个。无论如何,谢谢。
-
@SimonMourier 工作!!!!!!你有我的感激之情,谢谢。请添加您的答案,以便我标记它。