Making a Extracting/Compiling program in Visual C++ 2010 but have errors

392 Views Asked by At

I am building a .SM2 and .RM2 extractor/compiler for a game but I am having trouble with the code. I am not experienced in C++ at all and the code is source code given by the original creator. Even his original file that wasnt edited by me had errors but he still made the program. Can someone please help me with the errors?

Errors:

Error1: error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'const char [25]' to 'LPCWSTR'

Error2: error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'(X3)

Error4: error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [256]' to'LPCWSTR'

Error5: error C2440: 'initializing' : cannot convert from 'WCHAR [260]' to 'char*'

Here is my code that apparently have the errors:

CreateDirectory(".\\TESTFOLDER\\TESTFOLD2ER", NULL);   (This is for Error 1)

CreateDirectory(string, NULL);
break;                          (This is for Error2)


if ((hdl = FindFirstFile(asteriskpath, &data)) == INVALID_HANDLE_VALUE)
    return;       (For Error3)

char* filename = data.cFileName;
char current_dir[256];       (For Error4)

Please help, Thanks, Cameron Sawaya

1

There are 1 best solutions below

1
On BEST ANSWER

Method 1: set your project character setting to Use Multi-Byte Character Set:

Configure Properties > General > Project Defaults > Character Set > Use Multi-Byte Character Set


Method 2:

  • For Error 1/2/4:

    You should convert char[] to wchar_t[] first before passing to CreateDirectory() (For your Error 1, similar for other errors 2 and 4) as they are using different character encoding types. Try swprintf with the %hs flag.

    Example:

    wchar_t  ws[100];
    swprintf(ws, 100, L"%hs", ".\TESTFOLDER\TESTFOLD2ER");
    
  • For Error 5:

    You can use the wcstombs function to convert wchar_t[] to char[], reference here.