Topic : MFC .DLL TUTORIAL PART 2
Author : Andrew Fenster
Page : << Previous 2  
Go to page :


a comment to my previous article.

When you are creating a class which you intend to export, you add two public, static functions, CreateMe( ) and DestroyMe( ):


class __declspec(dllexport) CMyClass
{
    CMyClass( );
    ~CMyClass( );
    
     public:
     static CMyClass* CreateMe( );
     static void DestroyMe(CMyClass *ptr);
}
CreateMe( ) and DestroyMe( ) are implemented as follows:


CMyClass* CMyClass::CreateMe( )
{
     return new CMyClass;
}

void CMyClass::DestroyMe(CMyClass *ptr)
{
     delete ptr;
}

You export CMyClass as you would any other class. In the client application, you must be sure to use the CreateMe( ) and DestroyMe( ) functions. When you want to create a CMyClass object, you don't declare it in the usual fashion, i.e.:


CMyClass x;
Instead, you do this:


CMyClass *ptr = CMyClass::CreateMe( );
When you are done, you must remember to delete the object:


CMyClass::DeleteMe(ptr);
Using this technique, you can modify the size of CMyClass without having to recompile the client application.

Conclusion

This article is not a complete review of every issue concerning .DLLs, nor does it cover every possible solution. Good discussions of these issues can be found in Inside COM by Dale Rogerson and Essential COM by Don Box. For a more detailed understanding of the issue, that's where I would go. This article should at least serve to make you aware of the biggest issues and possible fixes and get you started on your way.


Page : << Previous 2