0

我的 C++ DLL 有一个新问题...我尝试导出整个类而不是仅导出一种方法。但是程序现在不想编译,因为全局范围没有 GetUrl
这是我的“UrlConnector.h”:

#define ConnectMe __declspec( dllexport )

namespace ConnectHttps { class ConnectMe { void GetUrl(char *url, unsigned int bufferLength); }; }


这是我的 UrlConnector.cpp 中未编译的部分: 现在,我希望能够从中创建一个 DLL,并且我想制作一个测试程序来调用类和方法 GetUrl 从dll。我正在使用带有 Visual C++ DLL 的 Visual Studio 2010。 我还设法从 MSDN本教程中阅读了这个,但我似乎无法让它工作!我真的很感激任何帮助!
#include "UrlConnector.h"
#include "MyConnectionClass.h"
#include 
using namespace std;

namespace ConnectHttps { void ConnectMe::GetUrl(char* url, unsigned bufferLength) { MyConnectionClass initSec; string response = initSec.GetResult(); strncpy_s(url, bufferLength, response.c_str(), response.length()); } }


4

1 回答 1

1

除非我弄错了,否则您似乎没有给您的班级起名字。你让 ConnectMe 不是类名而是一个宏来导出你的类,但是你的类应该有一个名字

也许试试

#define EXPORT_IT __declspec( dllexport )

namespace ConnectHttps
{
    class EXPORT_IT ConnectMe
    {
        void GetUrl(char *url, unsigned int bufferLength);
    };
}

我也不是 100% 确定这一点,因为我目前无法访问编译器,但输入:

namespace ConnectHttps {
    ...
}

在您的 .cpp 文件中不正确。相反,您应该拥有:

void ConnectHttps::ConnectMe::GetUrl(char* url, unsigned bufferLength)
{
    MyConnectionClass initSec;
    string response = initSec.GetResult();
    strncpy_s(url, bufferLength, response.c_str(), response.length());
}
于 2010-10-28T14:53:39.767 回答