2010-10-28 90 views
0

我有我的C + + DLL的新问题...我试图导出整个类而不是只有一个方法。但该计划并不想现在就编译因认为全球范围内没有任何的getURL
这里是我的“UrlConnector.h”: 错误:全球范围没有GetUrl

 
#define ConnectMe __declspec(dllexport)

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


这里是我UrlConnector.cpp的一部分,是不是编译:
 
#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()); } }

现在,我想能够从这个创建一个DLL,我想做一个测试程序从dll调用类和方法GetUrl。我正在使用Visual Studio 2010和Visual C++ DLL。
我也设法读取 this from the MSDNthis tutorial以及,但我似乎无法得到它的工作! 我真的很感激任何帮助!

回答

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()); 
} 
+0

谢谢你的快速回答...你是#1 – dirbacke 2010-10-28 16:04:22