トップ 履歴 一覧 カテゴリ ソース 検索 ヘルプ RSS ログイン

Win32/WinDll-Make

INDEX

Windows用のDLLの作成手順

モジュール定義ファイル(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 <stdio.h>
#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

作成

  1. Win32 Dynamic-Link Library でプロジェクトを作成
  2. 'Source Files' にソースファイル(exdll.c (exdll.cpp))を作成
  3. 'Header Files' にヘッダファイル(example.h)を作成
  4. 'Source Files' に定義ファイル(example.def)を作成
  5. リリース(もしくはデバッグ)モードでコンパイル
cl /LD /Feexample.dll exdll.c example.def

利用

  1. コンソール/ウインドウ アプリケーションのプロジェクトを作成
  2. ソースファイル(excall.c (excall.cpp))を作成
  3. ソースファイルに、ヘッダファイル(example.h)のインポートを記述
  4. リンクライブラリに、インポートライブラリ(example.lib)を追記
  5. カレントディレクトリに、ライブラリ(example.dll)をコピー
  6. リリース(もしくはデバッグ)モードでコンパイル/実行
cl -Feexample.exe excall.c example.lib

 BCC - Borland C++ Compiler (with BCC Developer)

作成

  1. プロジェクトを作成
  2. プロジェクト設定で、ターゲットを Dynamic Link Library (-WD) に設定
  3. プロジェクト設定で、実行ファイル名を example.dll に設定
  4. ソースファイル(exdll.c (exdll.cpp))を作成
  5. ヘッダファイル(example.h)を作成
  6. 定義ファイル(example.def)を作成 ※実行ファイル名と同じにする
  7. リリース(もしくはデバッグ)モードでコンパイル
bcc32 -WD -eexample.dll exdll.c
implib example.lib example.dll

利用

  1. コンソール/ウインドウ アプリケーションのプロジェクトを作成
  2. ソースファイル(excall.c (excall.cpp))を作成
  3. ソースファイルに、ヘッダファイル(example.h)のインポートを記述
  4. リンクライブラリに、インポートライブラリ(example.lib)を追記
  5. カレントディレクトリに、ライブラリ(example.dll)をコピー
  6. リリース(もしくはデバッグ)モードでコンパイル/実行
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)

  1. ソースファイル(exdll.c (exdll.cpp))を作成
  2. ヘッダファイル(example.h)を作成
  3. 定義ファイル(example.def)を作成
  4. ソースからオブジェクトファイルを作成する
    1. gcc -o exdll.o -c exdll.c

あとわからん(--;; Coop!! DLL作成のTips 参照

最終更新時間:2011年04月15日 13時05分33秒 指摘や意見などあればSandBoxのBBSへ。