【问题标题】:C# Com Interop Method is not a member of errorC# Com Interop Method 不是错误的成员
【发布时间】:2016-04-08 07:41:50
【问题描述】:

我有一个暴露给 COM 的 C# dll,当我尝试编译 c++ 应用程序时出现以下错误:

error C2039: 'ValidateCredentials_2' : is not a member of '_com_ptr_t<class _com_IIID<struct ExactaLogin::IAuthorizerInterop,&struct __s_GUID _GUID_00020400_0000_0000_c000_000000000046> >'

当我编译 c++ dll 时,我在我正在执行的 #import 生成的 tlh 文件中看到以下内容:

//
// Forward references and typedefs
//

struct __declspec(uuid("4b547e3d-3d30-4981-9999-f72f52a4fc01"))
/* dispinterface */ IAuthorizerInterop;
struct /* coclass */ AuthorizerInterop;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(IAuthorizerInterop, __uuidof(IDispatch));

//
// Type library items
//
struct __declspec(uuid("4b547e3d-3d30-4981-9999-f72f52a4fc01"))
IAuthorizerInterop : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    // Methods:
    VARIANT_BOOL ValidateCredentials (
        _bstr_t applicationName,
        _bstr_t domainName,
        _bstr_t domainUserNameToAuthenticate,
        _bstr_t domainPasswordToAuthenticate );
    VARIANT_BOOL ValidateCredentials_2 (
        _bstr_t applicationName,
        _bstr_t domainUserNameToAuthenticate,
        _bstr_t domainPasswordToAuthenticate );
};

我在 c++ 中定义了我的对象,如下所示:

#import "ExactaLogin.tlb"
using namespace ExactaLogin;

IAuthorizerInteropPtr m_spDomainLoginAuthorizer;

我的 c# 类定义如下:

[Guid("45329257-BFF4-4CF7-9A83-22D87A1FB757")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ExactaLogin.AuthorizerInterop")]
[ComVisible(true)]
public class AuthorizerInterop : IAuthorizerInterop

[Guid("4B547E3D-3D30-4981-9999-F72F52A4FC01")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface IAuthorizerInterop

不太清楚发生了什么。如果我将代码更改为使用ValidateCredentials 而不是ValidateCredentials_2,则会导致相同的错误。

编辑

我在c++应用中调用方法如下

m_spDomainLoginAuthorizer.ValidateCredentials_2(_bstr_t(m_szAppName), _bstr_t(m_szUserName), _bstr_t(m_szPassword));

【问题讨论】:

    标签: c# c++ com


    【解决方案1】:

    我在上面犯了一个非常愚蠢的错误。

    显然应该像指针一样访问调用。所以解决方法是:

    m_spDomainLoginAuthorizer->ValidateCredentials_2(_bstr_t(m_szAppName), _bstr_t(m_szUserName), _bstr_t(m_szPassword));
    

    而不是

    m_spDomainLoginAuthorizer.ValidateCredentials_2(_bstr_t(m_szAppName), _bstr_t(m_szUserName), _bstr_t(m_szPassword));
    

    -&gt; 而不是.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2018-09-10
      • 2020-11-17
      • 2016-04-07
      相关资源
      最近更新 更多