Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-19
3
Medium Priority
?
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

688 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