InstallScript コードで、Windows API を呼び出す方法を紹介します。
対象プロジェクト:InstallScript、InstallScript MSI プロジェクト
InstallScript コードの中から、Windows API を呼び出すことができます。
文字列変数を引数として使用するWindows API関数には「A」ANSI、「W」Unicode の2種類が
あり、「W」の Windows API や DLL関数を使用する場合は、WSTRINGデータ型を使用できます。
[使用例]
16進表記の文字列を数値に変換する WindowsAPI 関数 StrToIntEx を例として、サンプル
コードを記載します。
StrToIntEx には ANSI 版である StrToIntExA と、Unicode 版である StrToIntExW が存在します。
例1)ANSI 版 StrToIntExA のサンプル
------------------------------------------------------------------------------------------------
#include "ifx.h"
#define STIF_SUPPORT_HEX 0x00000001
//プロトタイプ宣言で、STRING 型を使用
prototype Shlwapi.StrToIntExA (BYREF STRING, LONG, POINTER );
function OnBegin()
STRING szHexString;
NUMBER nvInteger;
BOOL bResult;
begin
szHexString = "0x001A";
SprintfBox( INFORMATION, "Hex String", "szHexString = %s", szHexString );
bResult = StrToIntExA ( szHexString, STIF_SUPPORT_HEX, &nvInteger);
if ( bResult = TRUE ) then
SprintfBox( INFORMATION, "Integer", "nvInteger = %d", nvInteger );
else
MessageBox( "StrToInEx failed.", SEVERE );
endif;
end;
------------------------------------------------------------------------------------------------
例2)Unicode 版 StrToIntExW のサンプル
------------------------------------------------------------------------------------------------
#include "ifx.h"
#define STIF_SUPPORT_HEX 0x00000001
//プロトタイプ宣言で、WSTRING 型を使用
prototype Shlwapi.StrToIntExW (BYREF WSTRING, LONG, POINTER );
function OnBegin()
WSTRING szHexString;
NUMBER nvInteger;
BOOL bResult;
begin
szHexString = "0x001A";
SprintfBox( INFORMATION, "Hex String", "szHexString = %s", szHexString );
bResult = StrToIntExW ( szHexString, STIF_SUPPORT_HEX, &nvInteger);
if ( bResult = TRUE ) then
SprintfBox( INFORMATION, "Integer", "nvInteger = %d", nvInteger );
else
MessageBox( "StrToInEx failed.", SEVERE );
endif;
end;
------------------------------------------------------------------------------------------------