Advertisement

05.26.2006 at 08:08AM PDT, ID: 21865192
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

HowTo: LoadLibrary and GetProcAddress?

Asked by newton-allan in Windows MFC Programming

Tags:

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?

Start Free Trial
 
Keywords: HowTo: LoadLibrary and GetProcAdd…
 
Loading Advertisement...
 
[+][-]05.26.2006 at 08:21AM PDT, ID: 16769796

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 08:28AM PDT, ID: 16769870

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 09:03AM PDT, ID: 16770138

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 09:52AM PDT, ID: 16770493

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Windows MFC Programming
Tags: getprocaddress
Sign Up Now!
Solution Provided By: jkr
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.26.2006 at 10:01AM PDT, ID: 16770561

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 12:52PM PDT, ID: 16771931

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 01:19PM PDT, ID: 16772153

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 01:37PM PDT, ID: 16772267

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 01:43PM PDT, ID: 16772315

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 01:52PM PDT, ID: 16772394

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 03:06PM PDT, ID: 16772806

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 03:18PM PDT, ID: 16772856

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 05:53PM PDT, ID: 16773636

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2006 at 11:47PM PDT, ID: 16774399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.27.2006 at 04:38AM PDT, ID: 16775126

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.27.2006 at 04:43AM PDT, ID: 16775137

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081119-EE-VQP-49