How to compile c code in visual c ++ express 2010

I am trying to compile c code in VS C ++ express 2010, but I get the following error trace:

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 ========== 

When I try to compile with the cpp extension, I get this error:

 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 ========== 
+4
source share
3 answers

When creating a project, make sure you create it as a Win32 program, not a CLR application. This parameter can be changed in the project properties.

Propeties β†’ Common Language Runtime Support is the setting you are looking for. Set it equal.

+4
source

/ clr means using .Net runtime - not c runtime!

Just call the .c file and it will work, there is a flag to stop the use of any C ++ functions.

Go to properties -> c / C ++ -> advanced -> compile as and select 'c'

+5
source

You must remove /clr , this is not what you need.

To answer the underlying problem: you pass a char array to LPWSTR and LPCWSTR and LPCTSTR, which are arrays with two char bytes, so wchar_t* one form or another (if UNICODE, otherwise the latter is just just char* - like).

You will have to either cancel the UNICODE definition (not recommended) or convert the char[] and char* types to wchar_t

+1
source

All Articles