當前位置:編程學習大全網 - 編程軟體 - c語言寫的程序怎麽樣生成.dll文件?

c語言寫的程序怎麽樣生成.dll文件?

dll制作步驟:

1.編寫dll函數實現源代碼hello.c

#include

int say_hello(char* name)

{

printf( "hello %s\n ", name);

return 1;

}

2.編寫dll函數輸出定義文件hello.def.

LIBRARY hello

EXPORTS

say_hello @1

3.編譯dll源碼,生成dll,lib文件.

3.1 新建命令行窗口

3.2 設置PATH ? INCLUDE ? LIB 3個環境變量.

SET PATH=K:\vcnet\vc7\bin;%PATH%

SET INCLUDE=K:\vcnet\vc7\include;%INCLUDE%

SET LIB=K:\vsnet\Vc7\lib;%LIB%

3.3 編譯hello.c

cd K:\Source\dllsample (hello.c和hello.def所在目錄)

cl /c hello.c

3.4 鏈接hello.obj,生成hello.dll,hello.lib兩個文件.

link /def:hello.def /dll hello.obj

4.測試dll函數.

4.1 編寫測試代碼 test.c

extern int say_hello(char* name);

int main(int argc,char** argv)

{

say_hello( "robbie ");

return 0;

}

4.2 編譯測試代碼test.c

cl /c test.c

4.3 鏈接test.obj和 hello.lib,生成可執行文件test.exe

link test.obj hello.lib

4.4 運行test.exe,屏幕輸出:

hello robbie

至此,壹個dll構造完畢.

  • 上一篇:亂紀元和恒紀元真實存在嗎?
  • 下一篇:c連接sqlserver 2000,我只需要連接到數據庫,能取到數據就行,不需要對數據庫的內容進行更改。
  • copyright 2024編程學習大全網