如何在visualc++;快车2010 我试图在VS C++ Express 2010中编译C代码,但是我得到以下错误跟踪: 1>------ Build started: Project: test4, Configuration: Release Win32 ------ 1>cl : Command line error D8045: cannot compile C file 'test4.c' with the /clr option ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 1>------ Build started: Project: test4, Configuration: Release Win32 ------ 1> test4.cpp 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(86): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(98): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(138): error C2664: 'OpenServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(196): error C2664: 'GetSystemDirectoryW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(203): error C2664: 'lstrcatW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(208): error C2664: 'CopyFile' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(236): error C2664: 'CreateServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>test4.cpp(27): error C3861: 'kbhit': identifier not found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

如何在visualc++;快车2010 我试图在VS C++ Express 2010中编译C代码,但是我得到以下错误跟踪: 1>------ Build started: Project: test4, Configuration: Release Win32 ------ 1>cl : Command line error D8045: cannot compile C file 'test4.c' with the /clr option ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 1>------ Build started: Project: test4, Configuration: Release Win32 ------ 1> test4.cpp 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(86): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(98): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(138): error C2664: 'OpenServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(196): error C2664: 'GetSystemDirectoryW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(203): error C2664: 'lstrcatW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(208): error C2664: 'CopyFile' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(236): error C2664: 'CreateServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>test4.cpp(27): error C3861: 'kbhit': identifier not found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========,c,C,当我尝试使用cpp扩展进行编译时,我得到以下错误跟踪: 1>------ Build started: Project: test4, Configuration: Release Win32 ------ 1>cl : Command line error D8045: cannot compile C file 'test4.c' with the /clr option ========== Build: 0 succeeded, 1 failed, 0 up-to-date,

当我尝试使用cpp扩展进行编译时,我得到以下错误跟踪:

1>------ Build started: Project: test4, Configuration: Release Win32 ------
1>cl : Command line error D8045: cannot compile C file 'test4.c' with the /clr option
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
1>------ Build started: Project: test4, Configuration: Release Win32 ------
1>  test4.cpp
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(86): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(98): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(138): error C2664: 'OpenServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(196): error C2664: 'GetSystemDirectoryW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(203): error C2664: 'lstrcatW' : cannot convert parameter 1 from 'CHAR [80]' to 'LPWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(208): error C2664: 'CopyFile' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(236): error C2664: 'CreateServiceW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>test4.cpp(27): error C3861: 'kbhit': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

/clr意味着使用.Net运行时,而不是c语言运行时

只需调用文件.c,它就可以工作了,有一个标志阻止你使用任何C++特性。


转到属性->c/c++->高级->编译为并选择“c”

创建项目时,请确保将其创建为Win32程序,而不是CLR应用程序。可以在“项目属性”下更改此设置

属性->公共语言运行时支持是您需要的设置。
将其设置为无。

首先,您应该删除
/clr
,这不是您想要的

回答问题的根本问题:您正在将
char
数组传递给LPWSTR和LPCWSTR以及LPCTSTR,它们都是双字节char数组,因此
wchar\u t*
具有某种形式或其他形式(如果定义了UNICODE,否则最后一个就是普通的
char*
-like)


您必须撤消UNICODE定义(不推荐)或转换
char[]<代码> > char *>代码> WCARYTT < /C>类型,我按照您的建议执行,我仍然在获取命令行错误D8045:不能用/CLR optOnt//CLR optuuon编译C文件'Test4.c ',这是MSFT奇怪的C++与C/N.NETNEX的混合,默认情况下Visual C++编译器用.c编译文件。扩展为C和.cp扩展为C++的文件。如果您使用这两个标准扩展名,则不需要更改此设置。@James-我认为compile-as-c-flag会对“/”注释之类的内容发出警告,即使使用.c文件(自从我使用它以来已经有几个版本了)。使用.cpp扩展名编译时出现的错误表明您混淆了
wchar\u t
char
。即使将此文件编译为C文件,也需要修复这些错误。