Solved

How to capture invalid function when loading a dll in win32?

Posted on 2003-11-19
3
320 Views
Last Modified: 2007-12-19
I am trying to develop an application that uses 3rd party dll that might comes in several different version. I am trying to find out how could i check for the validity of a particular function in the dll during the runtime of my application.

For the moment whenever i tries to run a function from my application with the dll (which doesnt contain tt function), i will be prompted tt the function is invalid in the dll and then the application is terminated automatically. How could i stop it from auto termination and do something else in my code?

0
Comment
Question by:KCChan
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9784484
>>I am trying to find out how could i check for the validity of a particular
>> function in the dll during the runtime of my application

http://www.microsoft.com/msj/archive/s202b.aspx ("Jeffrey Richter's Qs&As, Sep. '96") pretty much describes how to do that and comes with sample code :o)

BTW, it is the Q asked by Jeremy Y.Y. Lai.
0
 

Accepted Solution

by:
jayesh_j_patel earned 125 total points
ID: 9787126
Do not link that function and dll/library statically with your application. Instead load it dynamically:

HINSTANCE hInst = LoadLibrary("ABC.DLL");
if (hInst)
{
   FARPROC hProc = GetProcAddress(hInst, "YourFunctionName");
  if (hProc)
  {
     hProc(p1, p2); // call 'YourFunctionName' with parameter p1 and p2
  }
  else AfxMessageBox("Cound not find function");
}
else AfxMessageBox("Could not load library");


Hope will help,
Jayesh
0
 

Author Comment

by:KCChan
ID: 9808189
the solution from jayesh_j_patel is closer to what I need. However, I do appreciate the information provided by jkr.

One more thing that i wish to clarify as I dont quite familiar with dymanically linking libraries.

Lets say now i were to include a cryptographic library that is provided by CSP, in the dll format. Microsoft sdk has provided me with a file wincrypt.h that i have to include in my application, which declare all the functions needed by the application. My concern here is that if a funcX() is declared in the wincrypt.h, but then my wincrypt.dll doesnt provide such a function(due to different version of the dll), what will happen under such situation? Is it possible to capture such and error or exception and prompt user with my own error message?

 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now