【发布时间】: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));
【问题讨论】: