GetModuleFileName example
GetModuleFileName function is used to give the fully qualified path of the module passed.
Syntax:
Return Value:Length of the strring that is copied in the buffer in characters.
Syntax:
DWORD WINAPI GetModuleFileName( _In_opt_ HMODULE hModule, _Out_ LPTSTR lpFilename, _In_ DWORD nSize );
Parameters:
hModule: Handle to the loaded module. If you pass NULL as the first argument , it gives us the path of the executable file of the current file
lpFileName: Pointer to the buffer where the fully qualified path will be stored.
nSize: The size of the lpFileName Buffer passed in TCHARs.
Return Value:Length of the strring that is copied in the buffer in characters.
Example:
GetModule.cpp:
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR path[100];
DWORD length;
length = GetModuleFileName(NULL, path, 1000);
printf("Length: %d \t Path :%ls\n", length, path);
getchar();
return 0;
}
Comments
Post a Comment