Solved

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

Posted on 2003-11-19
3
311 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

772 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

9 Experts available now in Live!

Get 1:1 Help Now