Sharing code between projects

Posted on 2006-03-31
Last Modified: 2010-04-24
What would be the best way of sharing code between two projects in 2003/2005. Would it be by adding the same files containing the code to both projects, making a DLL or some other way?

Im creating a TcpIP implementation and since both the server and the client must have a client I thaught it was a good idea.

It's for a course in programming and therefore I would like to implement it using interfaces and polymorphism, so the solution must be capable of that.

Any help appreciated!
Question by:bjqrn
    LVL 48

    Expert Comment

    The best way is writing Dll.
    One exception of this rule is code which can be placed in h-files: constants, templates, inline functions. Such files can be placed to some common directory and included to both projects.

    Source file which belongs to two projects is not a good idea because of two reasons:
    1) Synchronization problems between two projects.
    2) Visual Studio doesn't source files in other directories and you can loose some of IDE support like Intellicense, Class View etc.
    LVL 3

    Author Comment

    Is there a good tuorial on writing .NET dlls then? I need to be able to use classes as I would when writing .cpp and .h files.

    I would want it to work as System.dll, System.XML.dll and such.
    LVL 48

    Accepted Solution

    Make the following steps:
    1) Create C++/CLI Class Library project. Add required classes to it. Every managed public class from class library is available for .NET clients.
    2) Client project can be written in any .NET language. Add reference to class library to client project and use classes from library in the code.
    If library and client are in different solutions, you need to browse and add library Dll in Add References dialog. If they belong to the same solution, you can select library project in the Projects tab.
    LVL 3

    Author Comment

    thanks alot!

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now