English help on website



dllfuncw関数(Ver9.24対応版)
目次DLL呼び出し機能− dllfuncw関数
dllfuncのUnicode版です。

DLL内の関数を呼び出し、数値を受け取ります。
関数のパラメータの文字列部分はUnicodeです。
Unicodeかどうかの違いは、DLL側にあります。マクロ上では文字列がUnicodeかどうかの違いはありません。

loaddll文で読み込んだ単一のDLLの場合:
第1パラメータで指定された呼び出し先名をDLLから探し、その関数を呼び出します。
第2パラメータ以降には、文字列、数値などが自由に記述できます。
DLLの返す値がそのままdllfunc関数の返り値となります。
例: #ret = dllfuncw( "FuncName", ... , "Unicode文字列", ... );

loaddll関数で読み込んだDLLの場合:
第1パラメータに識別値のパラメータを付けると、関数を呼ぶことができます。
この場合、第2パラメータが呼び出し先名、第3パラメータ以降がDLLの関数に渡すパラメータになります。
例: #ret = dllfuncw( #dll, "FuncName", ... , "Unicode文字列", ... );



マクロののサンプル
loaddll "C:\\folder\\test.dll";

#a = dllfuncw("Func_for_dllfuncw",1,"a");
message str(#a);

endmacro;



DLL側のサンプル(簡単な例)
#include <windows.h>

extern "C" __declspec( dllexport )
INT_PTR _cdecl Func_for_dllfuncw( INT_PTR n, WCHAR* pwsz ) {
    INT_PTR nReturn = n + 22222;
    OutputDebugStringW( pwsz );
    return nReturn;
}




DLL側のサンプル(V8.66以降のパラメータのチェックに対応した例)
#include <windows.h>

extern "C" __declspec( dllexport )
INT_PTR _cdecl Func_for_dllfuncw( INT_PTR n, WCHAR* pwsz ) {
    HINSTANCE hinstExe = GetModuleHandle( NULL );
    int (WINAPI* pfnHidemaru_GetDllFuncCalledType)( int n );
    (FARPROC&)pfnHidemaru_GetDllFuncCalledType= GetProcAddress( hinstExe, "Hidemaru_GetDllFuncCalledType" );
    if( pfnHidemaru_GetDllFuncCalledType != NULL ) {
        //V8.66以降:正しく呼ばれているかチェック可能
        int returnType = pfnHidemaru_GetDllFuncCalledType(0); //返り値
        if( returnType != DLLFUNCRETURN_INT ) {               //return (INT_PTR)...
            return 0;
        }
        int paramType1 = pfnHidemaru_GetDllFuncCalledType(1); //第1パラメータ
        if( paramType1 != DLLFUNCPARAM_INT ) {                //int n
            return 0;
        }
        int paramType2 = pfnHidemaru_GetDllFuncCalledType(2); //第2パラメータ
        if( paramType2 != DLLFUNCPARAM_WCHAR_PTR ) {          //WCHAR* pwsz
            return 0;
        }
    } else {
        //V8.66未満:間違って呼ばれているかどうかは判断できない
    }
    
    //ここからパラメータ等を想定通りに扱う
    INT_PTR nReturn = n + 22222;
    OutputDebugStringW( pwsz );
    return nReturn;
}