Calling a Windows API Function

Project:This information applies to the following project types:

InstallScript
InstallScript MSI

You can call a Windows API function from within your InstallScript code.

To call a Windows API function:

1. At the beginning of the script, prototype the function using the following syntax:

prototype ReturnType DLLName.FunctionName( ParamType1, ParamType2, ... )

For example:

prototype INT User.LoadString( INT, SHORT, BYREF WSTRING, INT );

Use Dumpbin.exe with the /EXPORTS option to determine which functions reside in any of the Windows API DLLs Kernel32.dll, User32.dll, and GDI32.dll. To determine the return type and parameter types for a function, consult a Windows programming reference such as the Microsoft Development Library (MSDL).

Note:You can specify the return type to be one of the following InstallScript data types: BOOL, CHAR, HWND, INT, LONG, LPSTR, NUMBER, POINTER, or SHORT. If a return type is not specified, InstallShield assumes that the DLL function returns a 4-byte value.

2. Call the function as you would call any other function. For example:

nResult = LoadString( iInstance, nStringID, szMyString, MAX_SIZE );

3. To get extended error information if the function fails, check the value of the Err object’s LastDllError property. (It is not possible to call the Windows API function GetLastError to get extended error information, since the setup itself changes this value before returning control to the script.)