!!!Windows用のDLLの作成手順 {{category Windows,"C/C++",nolink}}モジュール定義ファイル(DEFファイル)を利用したDLLの作成方法です。 記憶の隅から起こしているので間違いがあるかも !!必要そうなファイル一式 記述内容の一例です。 !exdll.c (exdll.cpp) DLLに実装する処理を記述します。 #include "example.h" int example_function(int val1, int val2){ return(val1 + val2); } !example.h DLLの関数の内、公開(エクスポート)する関数宣言を記述します。構造体の定義も必要なら記述します。 #ifndef _EXAMPLE_H_ #define _EXAMPLE_H_ #ifdef __cplusplus extern "C" { #endif int example_function(int val1, int val2); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* _EXAMPLE_H_ */ !example.def エクスポートする関数を記述するモジュール定義ファイルです。 '''LIBRARY''' は、ライブラリの名前(DLL名と同じにする)。'''EXPORTS''' には、エクスポートする関数を列挙する。'''DESCRIPTION''' は、ライブラリの説明書きです。 ; example.def : DLL用のモジュール定義ファイル ;Copyright (c) 200x, example. All Rights Reserved. LIBRARY "example" DESCRIPTION 'example Windows Dynamic Link Library' EXPORTS example_function !excall.c (excall.cpp) DLLを利用するプログラムです。 #include #include "example.h" int main(int argc, char *argv[] /*, char *envp[] */){ printf("%d\n", example_function(1, 2)); return 0; } !!VC6 - Microsoft Visual C++ 6.0 !作成 +'''Win32 Dynamic-Link Library''' でプロジェクトを作成 +'Source Files' にソースファイル(exdll.c (exdll.cpp))を作成 +'Header Files' にヘッダファイル(example.h)を作成 +'Source Files' に定義ファイル(example.def)を作成 +リリース(もしくはデバッグ)モードでコンパイル cl /LD /Feexample.dll exdll.c example.def !利用 +コンソール/ウインドウ アプリケーションのプロジェクトを作成 +ソースファイル(excall.c (excall.cpp))を作成 +ソースファイルに、ヘッダファイル(example.h)のインポートを記述 +リンクライブラリに、インポートライブラリ(example.lib)を追記 +カレントディレクトリに、ライブラリ(example.dll)をコピー +リリース(もしくはデバッグ)モードでコンパイル/実行 cl -Feexample.exe excall.c example.lib !!BCC - Borland C++ Compiler (with BCC Developer) !作成 +プロジェクトを作成 +プロジェクト設定で、ターゲットを '''Dynamic Link Library (-WD)''' に設定 +プロジェクト設定で、実行ファイル名を '''example.dll''' に設定 +ソースファイル(exdll.c (exdll.cpp))を作成 +ヘッダファイル(example.h)を作成 +定義ファイル(example.def)を作成 ※実行ファイル名と同じにする +リリース(もしくはデバッグ)モードでコンパイル bcc32 -WD -eexample.dll exdll.c implib example.lib example.dll !利用 +コンソール/ウインドウ アプリケーションのプロジェクトを作成 +ソースファイル(excall.c (excall.cpp))を作成 +ソースファイルに、ヘッダファイル(example.h)のインポートを記述 +リンクライブラリに、インポートライブラリ(example.lib)を追記 +カレントディレクトリに、ライブラリ(example.dll)をコピー +リリース(もしくはデバッグ)モードでコンパイル/実行 bcc32 -WC -eexample.exe excall.c example.lib !makefileの例 example.dll : exdll.obj example.def bcc32 -WD -eexample.dll exdll.obj implib example.lib example.dll exdll.obj:exdll.c bcc32 -c exdll.c !!GCC - GNU Compiler Collection(GNU Project) +ソースファイル(exdll.c (exdll.cpp))を作成 +ヘッダファイル(example.h)を作成 +定義ファイル(example.def)を作成 +ソースからオブジェクトファイルを作成する ++gcc -o exdll.o -c exdll.c あとわからん(--;; [Coop!!|http://www.ecoop.net/coop/] [DLL作成のTips|http://www.ecoop.net/coop/tips/dll.html#DLLonGCC] 参照