string source;

	 char *src = (char*)(source.c_str());
	 LPCWSTR lpszsrc = (LPCWSTR)src;

       Handle h=  CreateFile(lpszsrc,.........);

       if(h==INVALID_HANDLE)
       printf("Error occured")
       return 0;

The above code segment always shows invalid file handle.I know the reason is my LPCWSTR conversion is not correct.How to make it correct.?

Recommended Answers

All 2 Replies

There's no need to call the unicode mapping by calling CreateFile and having to go through the conversion.

Instead call CreateFileA( ) for the ANSI version.
Also use
INVALID_HANDLE_VALUE for the return value check!

You can also gointo the project settings and turn off UNICODE and set to Single Byte or Multi-Byte.

I solved theabove problem

string source;
CString src( soure.c_str()) ;


thanking u
Krish+

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.