From: Tim Roberts on
"Jack" <jl(a)knight.com> wrote:
>
>Hi vc gurus,
>
>bool LoadMesh(std::wstring szPath)
>{
>//...
> ::GetModuleFileNameW(NULL, (LPWCH) szPath.c_str(), szPath.size());

Unless you have stored something in it previously, szPath.size() will be
zero.

Can you see that you are fighting the construct here? Seriously, when
you're working with the Win32 API, you're much better off using CString
than using std::string.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: Jack on
Thank you for all the advices

Jack


From: Leigh Johnston on
Why the std::string hate? Using std::string/std::wstring with Win32 API is
fine, I have no problems with it.

/Leigh

"Tim Roberts" <timr(a)probo.com> wrote in message
news:mnqgi590ocurhgppv1ijqoh50cjhe3nvgf(a)4ax.com...
> "Jack" <jl(a)knight.com> wrote:
>>
>>Hi vc gurus,
>>
>>bool LoadMesh(std::wstring szPath)
>>{
>>//...
>> ::GetModuleFileNameW(NULL, (LPWCH) szPath.c_str(), szPath.size());
>
> Unless you have stored something in it previously, szPath.size() will be
> zero.
>
> Can you see that you are fighting the construct here? Seriously, when
> you're working with the Win32 API, you're much better off using CString
> than using std::string.
> --
> Tim Roberts, timr(a)probo.com
> Providenza & Boekelheide, Inc.

From: Alex Blekhman on
"Leigh Johnston" wrote:
> Why the std::string hate? Using std::string/std::wstring with
> Win32 API is fine, I have no problems with it.

This is not about hate or love. Some standard classes are fine
with Win32 API, but some aren't. std::string is significantly less
convenient than CString. Think about the following operations:

1. Load a string from resources.
2. Pass a pointer to internal character buffer to Windows API
function.
3. Trim a string from right and/or left.
4. Tokenize a string.
5. Convert a string between ANSI and Unicode encodings.

All the above mentioned tasks are quite easy with CString and hard
with std::string.

Alex

From: Leigh Johnston on

> 1. Load a string from resources.

Fair enough, the only time I use CString

> 2. Pass a pointer to internal character buffer to Windows API function.

Trivial to do with std::string.. resize(...) and &s[0]

> 3. Trim a string from right and/or left.

Trivial to do with find/substr

> 4. Tokenize a string.

Writing a tokenizer is trivial, there is also boost

> 5. Convert a string between ANSI and Unicode encodings.

Fair enough although it is fairly trivial to implement your own (I did for
UTF-8) or use something like ICU.

>
> All the above mentioned tasks are quite easy with CString and hard with
> std::string.

Wrong.
>
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: Visual Studio 2008 on Windows 7
Next: std::vector error