473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 2347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: David Mathog | last post by:
Every so often one of my fgets() based programs encounters an input file containing embedded nulls. fgets is happy to read these but the embedded nulls subsequently cause problems elsewhere in...
15
by: ehabaziz2001 | last post by:
Hi, Till now I do not understand how the null character automatically added to the end of the string and it is not an element of the string array . All books said the null character (\0) added...
3
by: B Vidyadhar Joshi | last post by:
I have a function (a 3rd party DLL) which takes PWCHAR as one of the arguments. The value that is supposed to be passed to this argument is got from a Windows::Forms TextBox control which is in...
2
by: Steve Barnett | last post by:
I need to call a Win32 function that returns a set of string values. Each value is terminated by a null and the last value is terminated by two nulls. How do I code for this in C#? The call is:...
12
by: semut | last post by:
Given that the string is of null terminated type. What could be the possible causes (by experience) the string to have no null terminated and cause buffer overflow later. I know it is quite broad,...
7
by: semut | last post by:
Given that the string is of null-terminated type. What could be the possible causes (by experience) the string to have no null character (\0) and cause buffer overflow later. I know it is quite...
14
by: mast2as | last post by:
Hi everyone, I am trying to implement some specs which specify that an array of parameter is passed to a function as a pointer to an array terminated by a NULL chatacter. That seemed fairly easy...
1
by: ycinar | last post by:
How can I convert a string (or a wstring) to a PWCHAR? PWCHAR temp; wstring wstr; // Basically I want to do // temp = wstr // but casting didnt work // temp = PWCHAR (wstr) // error...
5
by: ssylee | last post by:
If I'm being supplied with a char* that is not null-terminated, is it impossible to transform it into a null terminated char* with only abstract information about the char* information?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.