English help on website



dllfuncstr関数(Ver9.30対応版)
目次DLL呼び出し機能− dllfuncstr関数
DLL内の関数を呼び出し、文字列を受け取ります。
受け取る文字列も、関数のパラメータの文字列部分も、非Unicodeです。

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

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



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

$a = dllfuncstr("Func_for_dllfuncstr",1,"xxx");
message $a;

endmacro;



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

extern "C" __declspec( dllexport )
char* _cdecl Func_for_dllfuncstr( INT_PTR n, char* psz ) {
    INT_PTR nDummy = n + 33333;
    OutputDebugStringA( psz );
    return "abc";
}




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

extern "C" __declspec( dllexport )
char* _cdecl Func_for_dllfuncstr( INT_PTR n, char* psz ) {
    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_CHAR_PTR ) {          //return (char*)
            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_CHAR_PTR ) {           //char* psz
            return 0;
        }
    } else {
        //V8.66未満:間違って呼ばれているかどうかは判断できない
    }
    
    //ここからパラメータ等を想定通りに扱う
    INT_PTR nDummy = n + 33333;
    OutputDebugStringA( psz );
    return "abc";
}