Share this page 

Use Windows Resources from a DLLTag(s): WinAPI/Registry


Let's create 2 DLLs containing StringTables for a particuliar language. We create these DLLs with VC++.

First, the French DLL

  1. Select File - New
  2. Choose Win32 Dynamic Link with the name resFr
  3. It's a Simple DLL project
  4. Select Insert - Resource, and StringTable - New
  5. The Strings are
                ST_1   Ligne un
                ST_2   Ligne deux
    
  6. Save the resource as res_fr.rc and add that file to the project source folder.
  7. Select Build - set Active Configuration to Win32 Release
  8. Select Build resFr.dll

The English DLL

  1. Select File - New
  2. Choose Win32 Dynamic Link with the name resEn
  3. It's a Simple DLL project
  4. Select Insert - Resource, and StringTable - New
  5. The Strings are
                ST_1   Line one
                ST_2   Line two
    
  6. Save the resource as res_en.rc and add that file to the project source folder.
  7. Select Build - set Active Configuration to Win32 Release
  8. Select Build resEn.dll
To use these resources from PowerScript, you need the following local external function declarations.
FUNCTION  ulong LoadLibraryA (string lpLibFileName) LIBRARY "kernel32.dll"
FUNCTION  boolean FreeLibrary (ulong hLibModule) LIBRARY "Kernel32.dll"
FUNCTION  int  LoadStringA(ulong hInstance, uint UiD, ref string &
  lpBuffer, int nBufferMax) LIBRARY "user32.dll"
Then from your script
ulong lul_res
string ls_temp
constant uint ST_1 = 1
constant uint ST_2 = 2

lul_res = LoadLibraryA("resFr.dll")
ls_temp = Space(255)
LoadStringA(lul_res, ST_1, ls_temp, 255)
MessageBox("The French resource ST_1", ls_temp)
FreeLibrary(lul_res)

lul_res = LoadLibraryA("resEn.dll")
ls_temp = Space(255)
LoadStringA(lul_res, ST_2, ls_temp, 255)
MessageBox("The English resource ST_2", ls_temp)
FreeLibrary(lul_res)
From a static text constructor
ulong lul_res
string ls_temp
constant uint ST_1 = 1

lul_res = LoadLibraryA("resEn.dll")
ls_temp = Space(255)
LoadStringA(lul_res, ST_1, ls_temp, 255)
this.text = ls_temp
FreeLibrary(lul_res)