简体   繁体   English

构建 DLL 时出现 C++ 错误:const wchar_t* 类型的参数与 LPWSTR 类型的参数不兼容

[英]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.我是 C++ 编程的完全新手。

I need to create a DLL using header and solution files that were provided in a tutorial.我需要使用教程中提供的头文件和解决方案文件创建一个 DLL。 I have followed basic steps from here but, I am getting following errors in the solution file:我已经按照这里的基本步骤进行操作,但是在解决方案文件中出现以下错误:

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

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

Errors:错误:

L111 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' C2664 'BOOL CreateProcessW(LPCWSTR、LPWSTR、LPSECURITY_ATTRIBUTES、LPSECURITY_ATTRIBUTES、BOOL、DWORD、LPVOID、LPCWSTR、LPSTARTUPINFLOW、LPPROCESS_INFORMATION)':无法将参数 2 从 'const wchar_t[105]' 转换为 'LPWSTR'

L112 L112

E0167 argument of type "const wchar_t*" is incompatible with parameter of type "LPWSTR". E0167 “const wchar_t*”类型的参数与“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.我知道上述代码行中的细节对你们中的许多人来说意义不大,但我希望有人至少可以理解 C++ 错误并在这里提供帮助。

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 . CreateProcess的 Unicode 版本(它是一个映射到CreateProcessW的宏)需要一个可写字符串作为lpCommandLine参数,并且字符串文字是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文档在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++ “const wchar_t”类型参数 * 与“wchar_t”类型参数不兼容 - C++ Argument of type “const wchar_t” * incompatible with parameter of type “wchar_t” 错误:类型“const wchar_t *”的参数与“WCHAR *”类型的参数不兼容 - Error: argument of type “const wchar_t *” is incompatible with parameter of type “WCHAR *” Visual Studio 2017; 当启用/ permissive时,“ const wchar_t *”类型的参数与“ PWSTR”类型的参数不兼容 - Visual Studio 2017; argument of type “const wchar_t *” is incompatible with parameter of type “PWSTR” when /permissive is enabled E0167 “CHAR *”类型的参数与“const wchar_t *”类型的参数不兼容 - E0167 argument of type "CHAR *" is incompatible with parameter of type "const wchar_t *" 错误:C2664 'void RecursiveDelete(LPWSTR,LPWSTR)':无法将参数 2 从 'const wchar_t [12]' 转换为 'LPWSTR' - error : C2664 'void RecursiveDelete(LPWSTR,LPWSTR)': cannot convert argument 2 from 'const wchar_t [12]' to 'LPWSTR' C ++ wifstream:不兼容的类型char const *,wchar_t const * - C++ wifstream: Incompatible type char const*, wchar_t const* 添加新用户会出现错误“无法将类型为“const wchar_t”的值分配给类型为“LPWSTR”的实体” - Adding new user gives error "a value of type "const wchar_t" cannot be assigned to entity of type "LPWSTR"" 如何将 const wchar_t 类型转换为 LPTSTR (C++) - How to transform const wchar_t type to LPTSTR (C++) “WCHAR *”类型的参数与 c++ 中“LPCSTR”类型的参数不兼容 - argument of type "WCHAR *" is incompatible with parameter of type "LPCSTR" in c++ C ++ Boost错误:初始化时无法将const值类型*(aka const wchar_t *)转换为const char * - C++ boost error: cannot convert const value type* (aka const wchar_t*) to const char* in initialization
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM