C#Com Interop方法不是错误的成员

时间:2016-01-04 16:26:50

标签: c# c++ com

我有一个C#dll我已经暴露给COM,当我尝试编译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 ++在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));

1 个答案:

答案 0 :(得分:0)

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

显然应该像指针那样访问调用。所以修复是:

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));

->代替.