|
-
May 1st, 2010, 12:57 PM
#1
trying to convert char* to LPCWSTR
I'm trying to use the following function:
DWORD test = GetTargetProcessIdFromWindow("Untitled - Notepad");
DWORD GetTargetProcessIdFromWindow(char * WindowName)
{
HWND targetWnd;
targetWnd = FindWindow(NULL,(LPCWSTR)WindowName);
DWORD procID = GetWindowThreadProcessId(targetWnd, NULL);
return procID;
}
but targetWnd always returns 00000. Does anyone know how to properly convert from a string to LPCWSTR ?
-
May 1st, 2010, 01:32 PM
#2
Re: trying to convert char* to LPCWSTR
 Originally Posted by dragonuv
I'm trying to use the following function:
DWORD test = GetTargetProcessIdFromWindow("Untitled - Notepad");
DWORD GetTargetProcessIdFromWindow(char * WindowName)
{
HWND targetWnd;
targetWnd = FindWindow(NULL,(LPCWSTR)WindowName);
DWORD procID = GetWindowThreadProcessId(targetWnd, NULL);
return procID;
}
but targetWnd always returns 00000. Does anyone know how to properly convert from a string to LPCWSTR ?
Your compiler can't be expected to somehow convert an ANSI string into unicode simply because you cast it as such, not that there is any reason to in the first place. You have one of two options.
Code:
DWORD test = GetTargetProcessIdFromWindow(L"Untitled - Notepad");
DWORD GetTargetProcessIdFromWindow(LPCWSTR WindowName)
{
HWND targetWnd;
targetWnd = FindWindow(NULL, WindowName);
DWORD procID = GetWindowThreadProcessId(targetWnd, NULL);
return procID;
}
OR
Code:
DWORD test = GetTargetProcessIdFromWindow("Untitled - Notepad");
DWORD GetTargetProcessIdFromWindow(LPCSTR WindowName)
{
HWND targetWnd;
targetWnd = FindWindowA(NULL, WindowName);
DWORD procID = GetWindowThreadProcessId(targetWnd, NULL);
return procID;
}
There are two versions of each Windows API function. One for ANSI strings, and one for unicode. They have the format MessageBoxA() and MessageBoxW() respectively. MessageBox() is a pseudonym for MessageBoxW().
-
May 9th, 2010, 06:37 AM
#3
Re: trying to convert char* to LPCWSTR
If you are confused over LPCTSTR, LPWSTR etc. see this
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|