In this article, I will summarize the results of my investigation with respect to including a dynamic link library (DLL) into a Microsoft Visual C++ 6.0 project, and using services which are offered by the loaded DLL.
The purpose of this article is to explain in short, but explicitly, what you need to do in order to be able to use services included in a DLL (by services, I refer to any function, a class or a parameter exported into DLL). Three weeks of “DLL hell” I went through can be avoided by doing the steps described below.
Case 1: A DLL you are supplied with is provided by another application and has been generated with the help of OLE (COMM).
Example: I needed to access an external interface of Rose-RT, which has been provided by the developers of Rose-RT as RrtRes.dll in order to control Rose-RT from external application.
Steps to perform:
- Create in Microsoft Visual C++ 6.0 an MFC application (.dll or .exe);
- Go to the menu View, ClassWizard.
- Select an option Add Class…, from a type library.
- Browse to the location of your *.dll.
- A window, which displays the content of your *.dll, will appear. Select all classes you want to include in your project (Ctrl+A – select all content, or Ctrl + mouse click – for selecting a specific set of classes).
- Push the button Open. Header file *.h and *.cpp implementation file will be generated.
- Close the ClassWizard.
Now, all services you selected for use in you project are available!
Case 2: A DLL you are supplied with has been generated as a MFC-shared DLL and it is to be used in a single-threaded code
Example: Suppose you are supplied with LoadMe.dll, services of which should be accessed, but which cannot be exported as mentioned in case 1.
typedef void (*EntryPointfuncPtr)(int argc, const char * argv );
LoadMe = LoadLibrary("..\\enter a Path To Your Dll here\\LoadMe.dll");
if (LoadMe != 0)
printf("LoadMe library loaded!\n");
printf("LoadMe library failed to load!\n");
LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddress(LoadMe,"entryPoint");
Now, you can access any of the services of LoadMe.dll. Good luck!
Case 3: A DLL you are supplied with has been generated as a MFC-shared DLL and it is to be used in a multithreaded code
AfxLoadLibrary() instead of
LoadLibrary() mentioned in case 2.
When you are done, don't forget to free the memory and unload the library:
I have BSc and MSc in Automatics and Computer Control Systems. After graduation I followed a post-master program Software Technology. Until the end of august 2004 I was involved in 9-month graduation project at the Embedded Systems Institute (Netherlands), where I was busy with coupling of Matlab/Simulink and Rational Rose RealTime. From September I switched to a new domain, so now I work on the development of patterns for process-aware information systems. My hobbies are painting, chess and dynamic sport.