【问题标题】:using .net dll as com in php failed在 php 中使用 .net dll 作为 com 失败
【发布时间】: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 工作!!!!!!你有我的感激之情,谢谢。请添加您的答案,以便我标记它。

标签: c# php .net com


【解决方案1】:

.NET 程序集的标准注册工具确实是regasm.exe, with /Codebase,如果你不把它放在 GAC 中(但你显然把它放在 GAC 中)。

你在 php 中使用的 progid 应该和你在 .NET 中指定的一样,所以这里是“CryptoCs”,而不是“CryptoCs.Crypto”

另外,我建议您删除所有 ClassInterface 和 InterfaceType 属性,因为一般情况下最好使用默认值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 2018-09-13
    • 2011-07-27
    • 2021-03-19
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多