Thread: C->Cdll->C#dll under VS2008

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    77

    C->Cdll->C#dll under VS2008

    Hello experts !
    I try to implement the following calling chain (for history reasons, thus is a given):
    C (.c file, main) -> calling C(.c file dll) -> calling C#(cs. file dll). All that’s under VS2008. Of course, between the C dll and the C# dll I have implemented a COM model, works fine; between the C main and the C dll is basic (I use a .def file for the C dll). The compiler is C++ for the C projects.
    Now, with the C-C dll working ok, I try to insert #import <the C# tlb library> into the C dll to start building the COM to the C#. The build of the C dll says error 2773, i.e. I need to use the C++ compiler (which is the case, and referenced into the project’s properties). As soon as I change the C dll source file type to .cpp the build goes through, but not anymore the one of the C main (error LNK 2019, doesn’t find the C dll function). All starts from the 2773 error which is not in accordance with the project’s settings. Any hints?
    Thanks!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    To call from C functions compiled with C++ you need in the function prototypes add
    extern "C"

    you could wrap the contents of the h file that contains the dll-interface used by the main
    inside the following code
    Code:
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    /* here go all the function prototypes that should be called from the pure C */
    
    
    #ifdef __cplusplus
    }
    #endif
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    77
    Thanks Vart! I put it into the .h file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Configuring VS2008 C++ to C
    By Akkernight in forum C Programming
    Replies: 8
    Last Post: 02-28-2009, 04:17 AM
  2. MASM In VS2008
    By valaris in forum Tech Board
    Replies: 1
    Last Post: 01-13-2009, 09:11 PM
  3. Need VS2008 Verification
    By rags_to_riches in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2008, 04:51 AM
  4. Does VS2008 have anything like Pythons IDLE?
    By atomsmasher442 in forum C# Programming
    Replies: 1
    Last Post: 07-26-2008, 04:37 AM
  5. nmake won't work in vs2008
    By inhahe in forum Windows Programming
    Replies: 2
    Last Post: 05-16-2008, 03:58 AM