Search code examples
inno-setuppascalscript

Defining structure with wide character pointer field in Inno Setup Unicode


Some external libraries, notably Windows API, use structure types with some fields being a pointer to a character array.

Inno Setup Unicode does not have PChar (PWideChar) type. How do I define a structure, that uses fields of wide character array pointer type?

For example how do I define SHFILEOPSTRUCT structure?

type
  TSHFileOpStruct = record
    hwnd: HWND;
    wFunc: UINT;
    pFrom: // what type?
    pTo: // what type?
    fFlags: Word;
    fAnyOperationsAborted: BOOL; 
    hNameMappings: HWND;
    lpszProgressTitle: // what type?
  end; 

Solution

  • Use string type. In Inno Setup Unicode Pascal Script the string type is automatically marshaled to PWideChar-like type in some contexts:

    • In record definitions (what the question is about).
    • In argument and return-type declarations of external functions.

    So the definition of SHFILEOPSTRUCT structure is:

    type
      TSHFileOpStruct = record
        hwnd: HWND;
        wFunc: UINT;
        pFrom: string;
        pTo: string;
        fFlags: Word;
        fAnyOperationsAborted: BOOL; 
        hNameMappings: HWND;
        lpszProgressTitle: string;
      end; 
    

    For a use, see Inno Setup invoke or replicate native Windows file copy operation.

    In all (?) other contexts, the string keeps its unique intrinsic function from Pascal language.