Actually, the function myFunction(PWCHAR pszKey, ULONG ulKeyLen) is exposed
by some custom 3rd party DLL. I have to pass these parameters to the DLL
where pszKey is a NON NULL terminated string and ulKeyLen is length of
pszKey in bytes. The pszKey parameter is usually a 4 charecters string like
"1234".
When I use MultiByteToWideChar(CP_ACP, 0, "1111", 4, pszKey, ulKeyLen), it
returns 0 but the pszKey is <undefined value>. When I call GetLastError, the
error number returned is ERROR_INVALID_PARAMETER.
Here is the code I use:
LPCSTR szKey = "1111";
int cbLen = sizeof(szKey); // == 4
PWCHAR pszKey;
ULONG ulKeyLen = sizeof(pszKey); // == 4;
int ret = MultiByteToWideChar(CP_ACP, 0, "1111", 4, pszKey, ulKeyLen);
//returns 0 but pszKey == <undefined value>
UINT err = GetLastError(); //returns ERROR_INVALID_PARAMETER (87)
//Call to myFunction() goes here...
Please help.
B Vidyadhar Joshi.
"Mihajlo Cvetanovic" <ma*@RnEeMtOsVeEt.co.yu> wrote in message
news:41**************@RnEeMtOsVeEt.co.yu...
B Vidyadhar Joshi wrote: I have a function which takes a NOT NULL terminated PWCHAR.
int myFunction (PWCHAR pszKey, ULONG ulKeyLen);
I have to pass a 4 charecter value to the "key" parameter. For example,
"1111". How do I do it?
Everything depends on what you want to do (it's not clear from your post).
My best guess is this:
int myFunction (PWCHAR pszKey, ULONG ulKeyLen)
{
if ( ulKeyLen >= 4 )
return MultiByteToWideChar(CP_ACP, 0, "1111", 4, pszKey, ulKeyLen);
else
return 4;
}