2013-08-16 41 views
-2

你好我每一個想從C++代碼創建一個簡單的dll文件在visual basic 10中但這裏得到一些錯誤是代碼 這個dll的功能是輸入任何名稱並顯示的名字,當被其他應用程序(兩者都是控制檯應用程序)試圖讓win32控制檯dll文件,但有一些問題

//This is demo.h file 
#ifdef DEMODLL_EXPORTS 
#define DEMODLL_API __declspec(dllexport) 
#else 
#define DEMO_API __declspec(dllimport) 
#endif 

namespace Demo 
{ 
class mydemo 
{ 
char name[30]; 
public: 
    static DEMODLL_API char getdata(char name); 
    static DEMODLL_API char displaydata(char name); 
}; 
} 

調用,這是demo.cpp文件

#include "stdafx.h" 
#include "demo.h" 
#include <stdexcept> 

using namespace std; 
namespace Demo 
{ 
char mydemo :: getdata(char name) 
char mydemo :: displaydata(char name) 
{ 
    return name; 
} 
} 

這些都是錯誤

demo.h(13): error C2144: syntax error : 'char' should be preceded by ';' 
demo.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
demo.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
demo.h(14): error C2144: syntax error : 'char' should be preceded by ';' 
demo.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
demo.h(14): error C2086: 'int Demo::mydemo::DEMODLL_API' : redefinition 
demo.h(13) : see declaration of 'Demo::mydemo::DEMODLL_API' 
demo.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
demo.cpp(12): error C2144: syntax error : 'char' should be preceded by ';' 
demo.cpp(12): error C2761: 'char Demo::mydemo::getdata(char)' : member function redeclaration not allowed 

請幫我

回答

0
#ifdef DEMODLL_EXPORTS 
#define DEMODLL_API __declspec(dllexport) 
#else 
#define DEMO_API __declspec(dllimport) 
#endif 

您正在定義時DEMODLL_EXPORTS定義一個宏,不同的宏(用不同的名稱)時,不定義DEMODLL_EXPORTS。在出現這些錯誤的版本中,符號DEMODLL_API未被定義爲宏,因此編譯器認爲它是一個標識符(從未聲明過)。

char mydemo :: getdata(char name) 
char mydemo :: displaydata(char name) {...} 

這並沒有太大的意義。您是否計劃提供getdata的機構?