[英]Passing CStrings between projects in same solution
这是我的课
namespace AuthenticationAdapter
{
class OPENID_EXPORT_API AuthenticationHelper
{
public:
static CString isOpenIdAuthentication( CString hostUrl, bool &isOpenId );
static CString Authenticate( CString hostUrl, CString& tokenId);
};
};
这是openidExport.h
#ifndef OPENIDEXPORT_H
#define OPENIDEXPORT_H
#ifdef OPENID_EXPORT
#define OPENID_EXPORT_API __declspec(dllexport)
#else
#define OPENID_EXPORT_API __declspec(dllimport)
#endif
#endif
这是实现
namespace AuthenticationAdapter
{
CString AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
}
这是电话
CString error = AuthenticationAdapter::AuthenticationHelper::isOpenIdAuthentication(
url,
connection->m_isOpenId);
这是错误,两个项目都使用unicode,我可以改用LPCTSTR解决这个问题,但是我很想知道问题出在哪里。
error LNK2019: unresolved external symbol "public: static class
ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class
ATL::ChTraitsCRT<wchar_t> > > __cdecl
AuthenticationAdapter::AuthenticationHelper::isOpenIdAuthentication(class
ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class
ATL::ChTraitsCRT<wchar_t> > >,bool &)"
(?isOpenIdAuthentication@AuthenticationHelper@AuthenticationAdapter@@SA?AV?
$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@V34@AA_N@Z)
referenced in function "public: class CServerConnection * __thiscall
CGlobalData::getAuthDetails(wchar_t const *,wchar_t const *,int)" (?
getAuthDetails@CGlobalData@@QAEPAVCServerConnection@@PB_W0H@Z)
似乎您正在DLL接口边界处导出CString
。 如果是这样,请确保所有使用该DLL的项目以及DLL本身都动态链接到CRT和MFC库的相同 样式 。
另外,在您的问题代码中,您编写了一个明确的固定__declspec(dllexport)
:
namespace AuthenticationAdapter { class __declspec(dllexport) AuthenticationHelper { public: static CString isOpenIdAuthentication( CString hostUrl, bool &isOpenId ); static CString Authenticate( CString hostUrl, CString& tokenId); }; }
构建DLL时应使用dllexport
,但在客户端项目中使用 dllimport
时应使用 dllimport
。
因此,请考虑使用自适应的dllimport
/ dllexport
模式,例如:
// In DLL header
// Client code hasn't defined MYDLL_API,
// so dllimport in clients.
#ifndef MYDLL_API
#define MYDLL_API __declspec(dllimport)
#endif
namespace AuthenticationAdapter
{
class MYDLL_API AuthenticationHelper
{
...
在DLL实现.cpp
文件中:
// Define *before* including DLL header,
// to export DLL stuff
#define MYDLL_API __declspec(dllexport)
#include "MyDll.h" // Include DLL header
// DLL implementation code ...
您在类中声明了isOpenIdAuthentication
方法,但您可能未在任何地方实现它。
更新:您应该在签名中同时包含名称空间和类。 同样,您不应再次声明您的名称空间。
这个:
namespace AuthenticationAdapter
{
CString AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
}
应该:
CString AuthenticationHelper::AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.