How to include c project into vc++ project.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to include c project into vc++ project.

  1. #1
    Join Date
    Mar 2010
    Posts
    74

    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

  2. #2
    Join Date
    Oct 2009
    Posts
    577

    Smile 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.

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

    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.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center