• 11
• 9
• 10
• 9
• 10

# compile error

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there, I copy some part of source code to my project. I use Visual Studio.Net 2003. Source code and errors : ----------------------------------------------------------------------------- MessageBox( NULL, L"Failed to init XACT because media not found.", L"XACT Tutorial", MB_OK ); error C2664: 'Messageert BoxA' : cannot convert parameter 2 from 'const unsigned short [45]' to 'LPCSTR' ----------------------------------------------------------------------------- hFile = CreateFile( str, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); error C2664: 'CreateFileA' : cannot convert parameter 1 from 'WCHAR [260]' to 'LPCSTR' Is there anybody can help me ?

##### Share on other sites
try taking the L's of the front of the strings, so they are LPSTR's not WCHAR thingys. that should work.

MessageBox( NULL, "Failed to init XACT because media not found.", "XACT Tutorial", MB_OK );

##### Share on other sites
You are mixing Unicode strings with ASCII strings. Unicode are two bytes per character, ASCII is one byte per character. The 'L' prefix makes a string Unicode. Instead, use the TEXT() macro. This macro's behaviour is dependant on the project's Unicode settings. Define _UNICODE to enable Unicode strings, don't define it and get the ASCII versions. The Windows API, not knowing if your application is Unicode or not differentiates between Unicode parameters and ASCII parameters by adding an 'A' or 'W' to API calls that accept strings and the version called is dependant on the project settings (the _UNICODE define). So MessageBox maps to MessageBoxA in ASCII and takes a char * type, but maps to MessageBoxW in Unicode and takes a unsigned short * type. You're getting the two mixed up.

Skizz

##### Share on other sites
the L in front of L"Failed to init XACT because media not found." tells the compiler to treat the attached string as a wide char string. This is used for UNICODE as opposed to the standard ASCII support. With ASCII you can only store the english alphabet, but with UNICODE you can use any language (because it's 2 bytes so you have 2^16 possibilites as opposed to ASCIIs 2^8

So the function MessageBox, does not take wide characters, and removing the L before your input string will fix the compile error.

On the other hand, if you need to use wide characters then define UNICODE befor eyou include windows so that windows knows to use the wide char verison of it's functions:

#define UNICODE#include <windows.h>