VB と VC で作る DLL について質問
以下のような DEF ファイルを用いない DLL を VC++4 で作成した場合,VB4 からは呼び出せない.
(エラーコード:49 「DLL が正しく呼び出せません。」)
/////////////////////////////////// VB //////////////////////////////////
Option Explicit
Declare Function Add Lib "test32.dll" (ByVal nLeft As Integer, ByVal nRight As Integer) As Integer
Sub main()
Dim iRet As Integer
Dim nLeft As Integer, nRight As Integer
nLeft = 4: nRight = 3
iRet = Add(nLeft, nRight)
End Sub
/////////////////////////////////// VB //////////////////////////////////
/////////////////////////////////// VC //////////////////////////////////
__declspec(dllexport) int Add (int nLeft, int nRight)
{
return ( nLeft + nRight );
}
/////////////////////////////////// VC //////////////////////////////////
DEF ファイルを用いないで,VB4 から呼び出すには以下の様にする.
/////////////////////////////////// VB //////////////////////////////////
Declare Function Add Lib "test32.dll" Alias "_Add@8" (ByVal nLeft As Long, ByVal nRight As Long) As Long
>/////////////////////////////////// VC //////////////////////////////////
#ifdef __cplusplus
extern "C"
#endif
__declspec(dllexport) int __stdcall Add(int nLeft, int nRight)
VB で Aliasを書かずに済ませるには DEF ファイルを使用する.
------ VB ------
Declare Function Add Lib "test32.dll" (ByVal nLeft As Integer, ByVal nRight As Integer) As Integer
------ VC ------
int WINAPI Add(int nLeft, int nRight)
--- VCの.DEF ---
EXPORTS
Add
----------------
__declspecは名前の変換規則が同一の処理系どうし(VC++どうし?)での結合用途である.
参照
VBから呼び出し可能なDLL宣言
DEFファイル
VC4以降での32bit DLLの作り方