简体   繁体   English

在同一解决方案中的项目之间传递CString

[英]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本身都动态链接CRTMFC库的相同 样式


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.

相关问题 同一解决方案中项目之间的链接问题(Exe依赖于Lib) - Link problem between projects in same solution (Exe depends on Lib) 如何在同一解决方案中的项目之间共享变量? - How to share variable between projects in the same solution? 同一解决方案中不同项目之间的引用(Visual Studio 2012) - Reference between different projects in the same solution (Visual Studio 2012) 无法在同一解决方案中的 2 个项目之间链接,并且我没有用于其他依赖项的 .Lib 文件 - Cannot Link between 2 projects in the same solution, and i dont have a .Lib File for additional dependencies GoogleTest在同一解决方案中几个C ++项目 - GoogleTest several C++ projects in the same solution 处理解决方案中多个项目中的相同头文件 - handling same header files in multiple projects in a solution 在同一解决方案中将头文件用于多个项目 - Using header files with multiple projects in same solution 在同一解决方案中的两个项目之间通过 TCP 套接字实时流式传输 C++ 结构数据的最佳方法是什么? - What is the best way for streaming C++ struct data through TCP socket in Real-time between two projects in the same solution? 什么接口会将cstrings,数组和其他类型复制到相同类型的实例? - What interface will copy cstrings, arrays, and other types to instances of the same type? 如何在同一个解决方案中包含其他项目的头文件? - How to include header files of another projects in the same solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM