StormLib API Reference



bool WINAPI SFileOpenFileEx(
  HANDLE hMpq,                      // Archive handle
  const char * szFileName,          // Name of the file to open
  DWORD dwSearchScope,              // Specifies the scope for the file.
  HANDLE * phFile                   // Pointer to file handle

Function SFileOpenFileEx opens a file from MPQ archive. The file is only open for read. The file must be closed by calling SFileCloseFile. All files must be closed before the MPQ archive is closed.


[in] Handle to an open archive.
[in] Name or index of the file to open.
[in] Value that specifies how exactly the file should be open. It can be one of the following values:
Value Meaning
The file is open from the MPQ. This is the default value. hMpq must be valid if SFILE_OPEN_FROM_MPQ is specified.
Opens a local file instead. The file is open using CreateFileEx with GENERIC_READ access and FILE_SHARE_READ mode.
When calling this function in Storm.dll, set this parameter to zero.
[out] Pointer to a variable of HANDLE type, that will receive HANDLE to the open file.

Return Value

When the function succeeds, it returns nonzero and phFile contains the handle of the opened file. When the file cannot be open, function returns false and GetLastError gives the error code.


The function always tries to open file with the specified locale first. If such file doesn't exist in the MPQ, the function tries to open file with neutral language ID.

When the archive is a patched archive, then the following StormLib functions behave dfferently:

When the caller doesn't know the proper file name, a pseudo name can be used. The pseudo name is in the form of (case sensitive). The numeric part of the file is the index in the file table. The open operation succeeds only if any of the following conditions is true:

Availability in Storm.dll

Available in Storm.dll Yes
Ordinal number in Storm.dll 1.00 79 (0x04F)
Ordinal number in Storm.dll 1.09 268 (0x10C)