简体   繁体   中英

Use C library in C++

I have C library with a header file. Now i want to make a wrapper in C++ in order to use it in .NET. When i include the library, the compiler reports an syntax errors regarding the variable types (DWORD, LPCSTR, etc...). In short, probably it thinks that the library is in C++ instead of C.

I tried

extern "C"{

  #include "c_lib.h"

}

but with no success. I am using Visual Studio 2010, so maybe so changes to the project settings should be done.

Any help will be appreciated.

Regards.

You need to include <windows.h> , but I think you're doing it wrong. You don't need to create a C++ wrapper to use the library from .NET. You can DllImport all the C functions you need to call, directly in C#.

Using the DllImport Attribute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM