-
July 17th, 2008, 07:53 PM
#1
converting from LPWSTR to char *
Hi, I am trying to convert an LPWSTR, specifically from an OPENFILENAME struct, to a char *.
so I have my code it looks like
OPENFILENAME ofn;
...
char *fname = (char *)ofn.lpstrFile; //this is what I tried and it didnt work
so pretty much I was wondering if there was some simple way of taking the file path from my OPENFILENAME struct and putting it in a useful char *.
-
July 17th, 2008, 07:58 PM
#2
Re: converting from LPWSTR to char *
You must have a UNICODE build if ofn.lpstrFile is LPWSTR. There is rarely a need for mixing char* and wchar_t* in the same build so can you explain why you need char*?
-
July 17th, 2008, 08:04 PM
#3
Re: converting from LPWSTR to char *
well, I am using the file path that I got from ofn.lpstrFile to open a file using fopen. The first parameter of fopen is a char *. I am used to working with C, so I am not sure if this is the best way of doing this in c++.
-
July 18th, 2008, 12:59 AM
#4
Re: converting from LPWSTR to char *
For wide char's with LPWSTR ..use _wfopen_s(..)
-
July 18th, 2008, 04:39 AM
#5
Re: converting from LPWSTR to char *
Virtually every c-runtime function, API function, etc. has a wide character equivalent. You should be using _wfopen() instead of fopen(). When developing your code you will quite often run into this problem. Assuming that you have help installed press F1 on fopen() (or any other function that takes a string parameter) and you will find the wide character equivalent.
-
July 18th, 2008, 06:09 PM
#6
Re: converting from LPWSTR to char *
Thanks for the info, I am using the _wfopen_s instead of fopen.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|