[英]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.