Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-19
3
Medium Priority
?
358 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 375 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

773 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