English help on website



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

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

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

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



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

$a = dllfuncstrw("Func_for_dllfuncstrw",1,"yyy");
message $a;

endmacro;



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

extern "C" __declspec( dllexport )
WCHAR* _cdecl Func_for_dllfuncstrw( INT_PTR n, WCHAR* pwsz ) {
    INT_PTR nDummy = n + 44444;
    OutputDebugStringW( pwsz );
    return L"abc";
}





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

extern "C" __declspec( dllexport )
WCHAR* _cdecl Func_for_dllfuncstrw( 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_WCHAR_PTR ) {         //return (WCHAR*)...
            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 nDummy = n + 44444;
    OutputDebugStringW( pwsz );
    return L"abc";
}