[英]Passing CStrings between projects in same solution
this is my class 这是我的课
namespace AuthenticationAdapter
{
class OPENID_EXPORT_API AuthenticationHelper
{
public:
static CString isOpenIdAuthentication( CString hostUrl, bool &isOpenId );
static CString Authenticate( CString hostUrl, CString& tokenId);
};
};
this is openidExport.h 这是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
this is the implementation 这是实现
namespace AuthenticationAdapter
{
CString AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
}
this is the call 这是电话
CString error = AuthenticationAdapter::AuthenticationHelper::isOpenIdAuthentication(
url,
connection->m_isOpenId);
and this is the error, both projects use unicode, i can get round it by using LPCTSTR instead, but i would love to know what the problem is. 这是错误,两个项目都使用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)
It seems you are exporting CString
at the DLL interface boundaries. 似乎您正在DLL接口边界处导出CString
。 If so, make sure that all the projects using that DLL and the DLL itself are dynamically linked to the same flavor of the CRT and MFC libraries. 如果是这样,请确保所有使用该DLL的项目以及DLL本身都动态链接到CRT和MFC库的相同 样式 。
In addition, in your question code you wrote an explicit fixed __declspec(dllexport)
: 另外,在您的问题代码中,您编写了一个明确的固定__declspec(dllexport)
:
namespace AuthenticationAdapter { class __declspec(dllexport) AuthenticationHelper { public: static CString isOpenIdAuthentication( CString hostUrl, bool &isOpenId ); static CString Authenticate( CString hostUrl, CString& tokenId); }; }
You should dllexport
when building the DLL, but dllimport
when using it in client projects. 构建DLL时应使用dllexport
,但在客户端项目中使用 dllimport
时应使用 dllimport
。
So, consider using an adaptable dllimport
/ dllexport
pattern, eg: 因此,请考虑使用自适应的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
{
...
In the DLL implementation .cpp
file: 在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 ...
You declare your isOpenIdAuthentication
method in your class, but you probably don't implement it anywhere. 您在类中声明了isOpenIdAuthentication
方法,但您可能未在任何地方实现它。
Update: You should include both the namespace and class in the signature. 更新:您应该在签名中同时包含名称空间和类。 Also, you should not declare your namespace again. 同样,您不应再次声明您的名称空间。
This: 这个:
namespace AuthenticationAdapter
{
CString AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
}
Should be: 应该:
CString AuthenticationHelper::AuthenticationHelper::isOpenIdAuthentication( CString hostUrl,bool &isOpenId )
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.