# How to Create a DLL from existing class

This topic is 2080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a win 32 C++ application that has been developed using Visual studio 2010. The application has several classes and compiles to an executable. What I would like to know is how I can compile the classes  as DLLs as I want to ship the application as an exe that calls dlls. When I was using Visual studio 6.0 I could do this but it was a bit tedious. Is there a better way to do this in Visual studio 2010  or how can this be accomplished in visual studio 2010.

##### Share on other sites

You need to create a new DLL project, and import your class files there.

Then in the class header do something like this

#ifdef DLL_PROJECT // Indicated we are building the dll
#define DLLEXPORT __declspec(dllexport)
#else // Building the executable
#define DLLEXPORT __declspec(dllimport)
#endif

class DLLEXPORT MyClass
{
// class defs go here
};


When you compile the DLL, your class and all its functions will be exported.

When you compile the EXE, use the same header and your class will be imported.

• 18
• 29
• 11
• 21
• 16