2010-10-28 89 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