How to include c project into vc++ project.
Hi all,
I have a DOS application that was written in C. Since it's DOS, I'm creating a GUI for the application in VC++ but would like to use all the original functions from the .C and .H files. Can I include these in my VC++ project or do I need to modify them? There are 13 projects to include in my VC++ GUI project.
thanks ,
rohit
Re: How to include c project into vc++ project.
Yes, you can include the headers and c sources to your VC++ project. In all C++ sources and headers you should add extern "C" clause to prevent from C++ name mangling.
Code:
extern "C"
{
#include "oldc_header"
}
Alternatively, you put that clause into the old headers like
Code:
// old header
#ifndef OLD_HEADER_H
#ifdef __cplusplus
extern "C"
{
#endif
// put here the olc contents of the header
#ifdef __cplusplus
}
#endif
#endif // OLD_HEADER_H
That way the extern "C" only applies if the header was included from C++ source and the old C sources would compile as well including the header.
Re: How to include c project into vc++ project.
An addendum to that.
You also have to make sure you compile the C source with a C-compiler instead of a C++ compiler. I think the default setting for Visual Studio does that but if you run into some linker issues that might be worth to check.