Discussion:
How to make this string?
(too old to reply)
i***@earthlink.net
2009-05-12 17:41:57 UTC
Permalink
Hi, ALL,
I need to make following string:

"str1\0str2\0str3\0"

Or even better

"str1\0"
"str2\0"
"str3\0\0"

What is the best way to achieve this?
I need to pass it to SQLConfigDataSource...

Thank you.
Uli Hertlein
2009-05-14 06:36:05 UTC
Permalink
Post by i***@earthlink.net
Hi, ALL,
"str1\0str2\0str3\0"
Or even better
"str1\0"
"str2\0"
"str3\0\0"
I'd use a vector<char> for that instead of a string. Technically it's not a C
string (because it contains multiple '\0' bytes, so strlen&friends won't work)
and C++ std::string can give surprising results.

Question of course is what your API call expects.
Cheers,
/uli
--
Uli Hertlein
Research and Development Phone: +49-(0)171-3188145
XDT Pty Ltd Web: www.xdt.com.au
i***@earthlink.net
2009-05-14 22:21:46 UTC
Permalink
Uli,

-----Original Message-----
Sent: May 14, 2009 2:36 AM
Subject: Re: How to make this string?
Post by i***@earthlink.net
Hi, ALL,
"str1\0str2\0str3\0"
Or even better
"str1\0"
"str2\0"
"str3\0\0"
I'd use a vector<char> for that instead of a string. Technically it's not a C
string (because it contains multiple '\0' bytes, so strlen&friends won't work)
and C++ std::string can give surprising results.
Question of course is what your API call expects.
The function I'm talking about expects the array of UTF-16 strings.
And the str[1,2,3] should be of the way "var=value", that should be pulled from the
registry.

The registry loop is already written, and I can generate the wxString object in the
form of "var=value".
Now what is the best way: convert this string to the UTF16, or add it to the vector
and convert the whole vector at once. I'm thinking number 2, but I don't know if I will
be able to perform the conversion on the vector<char>.
Cheers,
/uli
Thank you.
--
Uli Hertlein
Research and Development Phone: +49-(0)171-3188145
XDT Pty Ltd Web: www.xdt.com.au
Uli Hertlein
2009-05-15 07:19:51 UTC
Permalink
Post by i***@earthlink.net
Post by Uli Hertlein
Post by i***@earthlink.net
"str1\0str2\0str3\0"
Or even better
"str1\0"
"str2\0"
"str3\0\0"
I'd use a vector<char> for that instead of a string. Technically it's not a C
string (because it contains multiple '\0' bytes, so strlen&friends won't work)
and C++ std::string can give surprising results.
...
The function I'm talking about expects the array of UTF-16 strings.
...
Now what is the best way: convert this string to the UTF16, or add it to the vector
and convert the whole vector at once. I'm thinking number 2, but I don't know if I will
be able to perform the conversion on the vector<char>.
Well if it's actually an array of C strings (pointers I suppose) then you should
be fine. You can probably use pointers to the wxString data if they support UTF-16.

Cheers,
/uli
--
Uli Hertlein
Research and Development Phone: +49-(0)171-3188145
XDT Pty Ltd Web: www.xdt.com.au
Dave Silvia
2009-05-15 09:12:38 UTC
Permalink
Hi!

I think the complication to the whole thing is that Windows Registry doesn't use arrays, C, C++, or otherwise. It uses a 'stream' of characters, delimiting strings with nulls (0x00, '\0', however you want to refer to it). Once you parse through the 'stream', converting it into something less 1970's assembly, like string arrays, you're home free. You can 'store' it in any 'container' you choose.

jmtcw:

thx,
Dave S.
Post by Uli Hertlein
Post by i***@earthlink.net
Post by Uli Hertlein
Post by i***@earthlink.net
"str1\0str2\0str3\0"
Or even better
"str1\0"
"str2\0"
"str3\0\0"
I'd use a vector<char> for that instead of a string. Technically it's
not a C
Post by i***@earthlink.net
Post by Uli Hertlein
string (because it contains multiple '\0' bytes, so strlen&friends
won't work)
Post by i***@earthlink.net
Post by Uli Hertlein
and C++ std::string can give surprising results.
...
The function I'm
talking about expects the array of UTF-16 strings.
Post by i***@earthlink.net
...
Now what is the best way: convert this string to the UTF16, or add it to
the vector
Post by i***@earthlink.net
and convert the whole vector at once. I'm thinking number 2, but I don't
know if I will
Post by i***@earthlink.net
be able to perform the conversion on the vector<char>.
Well if it's actually an array of C strings (pointers I suppose) then you should
be fine. You can probably use pointers to the wxString data if they support UTF-16.
Cheers,
/uli
--
Uli Hertlein
Research and Development Phone: +49-(0)171-3188145
XDT Pty Ltd Web: www.xdt.com.au
_________________________________________
i***@earthlink.net
2009-05-15 15:36:19 UTC
Permalink
Hi, Uli,

-----Original Message-----
Sent: May 15, 2009 12:19 AM
Subject: Re: How to make this string?
Post by i***@earthlink.net
Post by Uli Hertlein
Post by i***@earthlink.net
"str1\0str2\0str3\0"
Or even better
"str1\0"
"str2\0"
"str3\0\0"
I'd use a vector<char> for that instead of a string. Technically it's not a C
string (because it contains multiple '\0' bytes, so strlen&friends won't work)
and C++ std::string can give surprising results.
...
The function I'm talking about expects the array of UTF-16 strings.
...
Now what is the best way: convert this string to the UTF16, or add it to the vector
and convert the whole vector at once. I'm thinking number 2, but I don't know if I will
be able to perform the conversion on the vector<char>.
Well if it's actually an array of C strings (pointers I suppose) then you should
be fine. You can probably use pointers to the wxString data if they support UTF-16.
Here is the function prototype:

BOOL SQLConfigDataSource( HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes);

Here is the sample from MSDN:

DSN=Personnel Data\0UID=Smith\0PWD=Sesame\0DATABASE=Personnel\0\0

As you can see lpszAttributes is of the type LPCSTR and is in the form of UTF-16.
Cheers,
/uli
Thank you.
--
Uli Hertlein
Research and Development Phone: +49-(0)171-3188145
XDT Pty Ltd Web: www.xdt.com.au
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
legalize+ (Richard)
2009-05-16 01:20:29 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by i***@earthlink.net
BOOL SQLConfigDataSource( HWND hwndParent, WORD fRequest, LPCSTR
lpszDriver, LPCSTR lpszAttributes);
DSN=Personnel Data\0UID=Smith\0PWD=Sesame\0DATABASE=Personnel\0\0
As you can see lpszAttributes is of the type LPCSTR and is in the form of UTF-16.
No. It is an array of TCHARs. A TCHAR can be either char or wchar_t
depending on how you compile the code. When its char, then
SQLConfigDataSource will be #define'd to be SQLConfigDataSourceA and
when its wchar_t, it will be SQLConfigDataSourceW. If you use the
wide character entry point explicitly, then lpdzAttributes will be
LPWSTR.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
legalize+ (Richard)
2009-05-16 01:31:39 UTC
Permalink
[Please do not mail me a copy of your followup]

Looking more closely at the includes, SQLConfigDataSource is #define'd
to be SQLConfigDataSourceW in a wide-character build and all the
string arguments for SQLConfigDataSourceW are LPCWSTR's. So its like
I said before, but they didn't document the function as taking
LPCTSTRs like they should have and the ANSI entry point doesn't end in
an 'A' like it normally would.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Chris Spencer
2009-05-15 16:45:08 UTC
Permalink
Dave,
I'm making a wxString object after reading the registry in the form of
wxString temp = "DSN=test";
Now since wxString consist of the '\0' temination symbol and simple
temp += "UID=dba";
will push to the end of the "temp", what should I do?
Also should I convert "temp" to be a UTF16 string, or the final product?
Thank you.
Assuming you have a vector of strings, you can do this:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
vector<string> entries{ "a=b", "c=d" };
string combined;
for (auto entry = entries.begin(); entry != entries.end(); ++entry) {
combined += *entry;
combined.push_back('\0');
}
cout.write(combined.c_str(), combined.length() + 1);
return 0;
}

This will print to stdout:
61 3d 62 00 63 3d 64 00 00
which is what you need.

You should be able to convert it to UTF-16 after it has been combined,
I haven't looked in much detail at the documentation so I'm not sure
how it wants it.

Hope this helps.

Chris.
i***@earthlink.net
2009-05-16 15:32:09 UTC
Permalink
Richard,

-----Original Message-----
Sent: May 15, 2009 6:31 PM
Subject: Re: How to make this string?
[Please do not mail me a copy of your followup]
Looking more closely at the includes, SQLConfigDataSource is #define'd
to be SQLConfigDataSourceW in a wide-character build and all the
string arguments for SQLConfigDataSourceW are LPCWSTR's. So its like
I said before, but they didn't document the function as taking
LPCTSTRs like they should have and the ANSI entry point doesn't end in
an 'A' like it normally would.
I understand all of this, but on Windows all ODBC functions expects to get
and return UTF16 strings....
Are you saying it's not true?

Thank you.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
legalize+ (Richard)
2009-05-16 18:58:42 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by i***@earthlink.net
I understand all of this, but on Windows all ODBC functions expects to get
and return UTF16 strings....
Are you saying it's not true?
The compiler datatype is not a wide character string if you don't
compile for wide characters.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
i***@earthlink.net
2009-05-16 22:29:05 UTC
Permalink
Richard,

-----Original Message-----
Sent: May 16, 2009 11:58 AM
Subject: Re: How to make this string?
[Please do not mail me a copy of your followup]
Post by i***@earthlink.net
I understand all of this, but on Windows all ODBC functions expects to get
and return UTF16 strings....
Are you saying it's not true?
The compiler datatype is not a wide character string if you don't
compile for wide characters.
I'm using wx TRUNK, which means I'm compiling everything in UNICODE..

Thank you.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Loading...