Reputation: 15
I am trying to use GetProcessImageFileNameW in a Windows kernel driver.
LPWSTR path[MAX_PATH];
if(GetProcessImageFileNameW(hProcess, path, MAX_PATH) == 0)
{
DbgPrint("Can't get the process image name");
return;
}
But when I build there is a compiler error "Using uninitialized memory 'path'"
How can I solve it?
Upvotes: 0
Views: 255
Reputation: 597036
LPWSTR
is a single wchar_t*
pointer. So LPWSTR path[MAX_PATH];
is creating an array of wchar_t*
pointers.
However, GetProcessImageFileNameW()
takes an LPWSTR
parameter, where the documentation says:
lpImageFileName
A pointer to a buffer that receives the full path to the executable file.
That means GetProcessImageFileNameW()
wants a pointer to an array of wchar_t
characters, which it will then fill as needed.
An array decays into a pointer to its 1st element. So, you are passing a wchar_t**
where a wchar_t*
is expected. I'm surprised you are not getting a compiler error about a type mismatch, rather than an error about uninitialized memory.
Try this instead:
WCHAR path[MAX_PATH] = {};
if (!GetProcessImageFileNameW(hProcess, path, MAX_PATH))
{
DbgPrint("Can't get the process image name");
return;
}
Upvotes: 5