GetModuleFileName

2.x

  int GetModuleFileName(hinst, lpszFilename, cbFileName)    
  HINSTANCE hinst; /* handle of module, */  
  LPSTR lpszFilename; /* address of buffer for filename */
  int cbFileName; /* maximum number of bytes to copy */

The GetModuleFileName function retrieves the full path and filename of the executable file from which the specified module was loaded.

Parameters

hinst

Identifies the module or the instance of the module.

lpszFilename

Points to the buffer that is to receive the null-terminated filename.

cbFileName

Specifies the maximum number of bytes to copy, including the terminating null character. The filename is truncated if it is longer than cbFileName. This parameter should be set to the length of the filename buffer.

Return Value

The return value specifies the length, in bytes, of the string copied to the specified buffer, if the function is successful. Otherwise, it is zero.

Example

The following example retrieves an application's filename by using the instance handle passed to the application in the WinMain function:

int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hPrevInst,
    LPSTR lpCmdLine, int nCmdShow)
{
    char szModuleName[260];

    GetModuleFileName(hinst, szModuleName, sizeof(szModuleName));
}

See Also

GetModuleHandle