I'm trying to use up to 3 dll's in an vc6 application. On the end-user's system, not all the dll's will necessarily be installed. I'm using LoadLibrary so the program can proceed as long as at least one .dll is loaded.
My problem is that the project(s) seems setup such that I get a runtime error message if all three .dll's aren't available. Also, the _ASSERTE statement below for GetProcAddress is failing.
Here is a "stub" of the vc6 main.cpp
#include "FirstDll.h"
#include "SecondDll.h"
#include "ThirdDll.h"
void main(void)
{
const char* pBuf;
HINSTANCE hLibrary = ::LoadLibrary("FirstDll.dll");
if (hLibrary == NULL) {
printf("Unable to load FirstDll\n");
}
else {
pBuf = FirstGetBuf(1);
printf([%s]\n", pBuf);
::FreeLibrary(hLibrary);
}
hLibrary = ::LoadLibrary("SecondDll.dll");
if (hLibrary == NULL) {
printf("Unable to load SecondDll\n");
}
else {
pBuf = SecondGetBuf(1);
printf([%s]\n", pBuf);
::FreeLibrary(hLibrary);
}
hLibrary = ::LoadLibrary("ThirdDll.dll");
if (hLibrary == NULL) {
printf("Unable to load ThirdDll\n");
}
else {
pBuf = ThirdGetBuf(1);
printf([%s]\n", pBuf);
::FreeLibrary(hLibrary);
}
/*
typedef const char* const (CALLBACK* GET_PROC)(USHORT);
GET_PROC pGetBuf;
pGetBuf = (GET_PROC)GetProcAddress(hLibrary, "ThirdGetBuf");
_ASSERTE(pGetBuf != NULL);
pBuf = pGetBuf((USHORT)1);
*/
}
Note that the commented out statements don't work ... the _ASSERTE is raised because GetProcAddress isn't resolving the function FirstGetBuf.
Here is a stub of FirstDll.h as generated by the Vc6 wizard for Win32 Dynamic Link Library:
#ifdef FIRSTINDLL_EXPORTS
#define FIRSTINDLL_API __declspec(dllexport)
#else
#define FIRSTINDLL_API __declspec(dllimport)
#endif
// Exported function.
FIRSTINDLL_API const char* const FirstGetBuf(USHORT Num);
If SecondDll.dll isn't installed at run-time, I get the message:
"This application has failed to start because SecondDll.dll was not found. Re-installing the application may fix this problem."
What am I doing wrong? Do I have the main.dsp project and/or *Dll.dsp projects incorrectly setup to insist that the *Dll.dll files exists? Do I need to have .def files? Does having the statement:
pBuf = FirstGetBuf(1);
cause the linker to insist on having FirstDll.dll be present? How to I get the GetProcAddress call to work?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.