Solved

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

Posted on 2003-11-19
3
326 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why "." vs "->" 23 120
Need 'Configuration File' Management Library for C++ Project 1 493
is twain_32.dll cmpatible with windows 10 ? 10 155
Issues with C++ Class 19 92
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

805 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