Sam Hu wrote:

> Given below code(Win32 SDK):
> 
> int /*LRESULT*/ wndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
> {
> switch(msg)
> {
> case WM_LBUTTONDOWN:
> {
> wchar* szFileName=cast(wchar*)(new wchar[1024]);// ***questioned line
> HINSTANCE hInstance=GetModuleHandleW(null);
> GetModuleFileNameW(hInstance,szFileName,1024);
> MessageBoxW(null,cast(const wchar*)szFileName, "Full Path:",
> MB_ICONINFORMATION);
> }
> 
> break;
> }
> 
> My program runs OK and can print the exe path as expected.But if I change
> wchar* szFileName=cast(wchar*)(new wchar[1024]);
> 
> to
> wchar* szFileName;
> 
> The program runs also but prints blank.Why?
> 
> Thanks for your help in advance.
> Regards,
> Sam

I guess MessageBox checks if the pointer to the message text is NULL. If it 
is NULL, it prints nothing.

You should check the return value of GetModuleFileName. It may fail for 
various reasons. I guess it fails if you pass a null pointer to it.

Also, you don't have to call GetModuleHandle to get the handle of the 
calling process' module. Just pass NULL as first argument to 
GetModuleFileName.

Reply via email to