471,093 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

Non NULL terminated PWCHAR

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?

TIA.

Regards,

B Vidyadhar Joshi
Nov 17 '05 #1
5 2224
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;
}

Nov 17 '05 #2
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;
}

Nov 17 '05 #3
OK - A small mistak while posting. The code goes as follows:

LPCSTR szKey = "1111";
int cbLen = sizeof(szKey); // == 4
LPWSTR pszKey;
int ulKeyLen = sizeof(pszKey); // == 4;

int ret = MultiByteToWideChar(CP_ACP, 0, "1111", cbLen, pszKey, ulKeyLen);
//returns 0 but pszKey == <undefined value>
UINT err = GetLastError(); //returns ERROR_INVALID_PARAMETER (87)

//Call to myFunction() goes here...

TIA.

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;
}

Nov 17 '05 #4
myFunction(L"1111", 4);
L for 'wide' string literal.
The fact that you must pass the key length suggests that null-terminated
or not is irrelevant. no?

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?

TIA.

Regards,

B Vidyadhar Joshi


Nov 17 '05 #5
This doesn't work either :-(

This time myFunction returns ERROR_CONTROL_ID_NOT_FOUND.

"doug mansell" <do**********@hotmail.com> wrote in message
news:ee**************@tk2msftngp13.phx.gbl...
myFunction(L"1111", 4);
L for 'wide' string literal.
The fact that you must pass the key length suggests that null-terminated
or not is irrelevant. no?

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?

TIA.

Regards,

B Vidyadhar Joshi


Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by David Mathog | last post: by
15 posts views Thread by ehabaziz2001 | last post: by
3 posts views Thread by B Vidyadhar Joshi | last post: by
2 posts views Thread by Steve Barnett | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.