起初直接把子__declspec(dllexport) 放在類宣告的地方. 發生 warning c4273 dll 鏈結不一致錯誤.
想了挺長時間才意識到是生成lib時並標頭檔案和原檔案中對函式的名字解析名字不一樣而產生的. 才想到要定義乙個巨集.
有點感嘆知識不用會也會老的. 下邊是**
//標頭檔案:testclass.h
[cpp]view plain
copy
#ifndef test_class_h__
#define test_class_h__
#include
using
namespace
std;
#ifdef serverdll_exports //在建立產生dll的工程中先把 serverdll_exports 預定義上
#define serverdll_api __declspec(dllexport)
#else
#define serverdll_api __declspec(dllimport)
#endif
class
serverdll_api testclass
; serverdll_api void
func(
void
);
#endif
//實現檔案.testclass.cpp
[c-sharp]view plain
copy
#include "testclass.h"
void
testclass::virtualfunction(
void
)
void
testclass::normalfunction(
void
)
void
func(
void
)
//除錯**
[cpp]view plain
copy
#include
#include
#include
using
namespace
std;
#pragma comment(lib, "e://myself//myproject//網路程式//serverdll//debug")
//testclass類為dll匯出的類
class
my :
public
testclass
void
normalfunction()
};
intmain(
void
)
輸出:[cpp]view plain
copy
this
is normalfunction()!
my virtualfunction()
xixi haha
liu zhiliang
請按任意鍵繼續. . .
c DLL匯出類和匯出函式
一 匯出函式 背景 匯出函式 在dll中有一張匯出表,其中有一系列函式,這些函式叫做匯出函式。這些函式可供外部程式呼叫,即這些函式都是該dll的入口點 類似main函式 不在匯出表中的函式,為該dll私有的函式,外部程式不能呼叫它們。1 沒有 declspec dllexport 將生成的測試lib...
C DLL匯出函式
有兩種方式,一是寫def檔案,二是用 declspec dllexport 修飾。相對來說,我更喜歡用後一種方式,這樣不用多寫乙個檔案。如果呼叫dll的 也是c 的,可能這樣寫沒有什麼問題,但是delphi程式呼叫的話就有問題了,c 編譯器把函式修飾名給修改了,用depends檢視dll的話能看到原...
C DLL 匯出函式名
10 05 1844292.html 經常使用vc6的dependency檢視dll匯出函式的名字,會發現有dll匯出函式的名字有時大不相同,導致不同的原因大多是和編譯dll時候指定dll匯出函式的界定符有關係。vc 支援兩種語言 即c c 這也是造成dll匯出函式差異的根源 我們用vs2008新建...