VBでは使う機会はなさそう。じゃあC言語だと使う機会はあるのか?正直、知らん。
'モジュールをロードする
'ロードしたモジュールを開放する
'モジュール内の関数のアドレスを取得する
'----------------------------------------------------------------------- ' 関数名 : IsDllFunc ' 機能 : DLL内の関数の有無をチェックする ' 引数 : (in) DllName … dllファイル名 ' (in) DllFunc … dllファイルの関数名 ' 戻り値 : -1(=True)…正常終了 ' 1…DLLファイルが存在しない ' 2…DLLファイルは存在するが、関数は存在しない '----------------------------------------------------------------------- Public Function IsDllFunction(ByVal DllName As String, _ ByVal DllFunc As String) As Long Dim hLibrary As Long '正常終了値を割り当てちゃえ IsDllFunction = True '返り値が0であれば、DLLファイルは存在しない hLibrary = LoadLibrary(DllName) If hLibrary = 0 Then IsDllFunction = 1 Exit Function End If 'モジュール内に関数が存在するかどうかの取得 If GetProcAddress(hLibrary, DllFunc) = 0 Then IsDllFunction = 2 Exit Function End If 'ロードしたモジュールを開放する Call FreeLibrary(hLibrary) End Function 呼び出し側はこんな感じでどうぞ。 Private Sub Command1_Click() Dim FuncRet As Long FuncRet = IsDllFunction("kernel32.dll", "CopyFileA") Select Case FuncRet Case True Debug.Print "関数は存在する" Case 1 Debug.Print "DLLファイルが存在しない" Case 2 Debug.Print "関数は存在しない" End Select End Sub |