BRat
BRat

Reputation: 83

C++ error when building DLL: argument of type const wchar_t* is incompatible with parameter of type LPWSTR

I am a complete novice to C++ programming.

I need to create a DLL using header and solution files that were provided in a tutorial. I have followed basic steps from here but, I am getting following errors in the solution file:

L111 !CreateProcess(L".\\phreeqc\\phreeqc.exe",

L112 TEXT(".\\phreeqc\\phreeqc.exe .\\phreeqc\\phreeqc_input.txt .\\phreeqc\\phreeqc_input.out .\\phreeqc\\wateq4f_plus.dat")

Errors:

L111

C2664 'BOOL CreateProcessW(LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFLOW,LPPROCESS_INFORMATION)': cannot convert argument 2 from 'const wchar_t[105]' to 'LPWSTR'

L112

E0167 argument of type "const wchar_t*" is incompatible with parameter of type "LPWSTR".

I understand that the specifics in the above lines of code will not mean much to many of you but I am hoping that someone can at least understand the C++ error and help out here.

Upvotes: 1

Views: 1745

Answers (1)

catnip
catnip

Reputation: 25388

The Unicode version of CreateProcess (which is a macro that maps to CreateProcessW) requires a writable string for the lpCommandLine parameter, and string literals are const. You therefore cannot pass a string literal directly for this parameter.

Instead, you can change your code like so:

WCHAR lpCommandLine [] = L"...";
BOOL ok = CreateProcess (L"your_application_name_here", lpCommandLine, ...);

Documentation here

Upvotes: 3

Related Questions