?
Solved

Dynamic Link of DLL func in CBuilder 3

Posted on 1998-04-21
4
Medium Priority
?
272 Views
Last Modified: 2006-11-17
I want to Dynamically Load a DLL in C++ Builder   Ex:
 HINSTANCE hndl;
 FARPROC Func;
 hndl = LoadLibrary("c:\\wwwroot\\cgi-bin\\control.dll");
 Func = (FARPROC) GetProcAddress(hndl,"Passed");
 if(Func(Name.c_str(),Password.c_str())){ FreeLibrary(hndl); return 1;}//Passed
 else {FreeLibrary(hndl); return 0;}

I'm getting an error message saying "Too Many Arguments" to the DLL function even though the number of arguments is correct
Regards Matlock.
0
Comment
Question by:Matlock
[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
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 240 total points
ID: 1162642
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1162643
The problem is that you've declared the function pointer as a pointer to function that takes no parameters.  Then you try to use it with two string parameters.  In c++ the function pointers must be used with the same number and type of parameters that they are declared with.  Since I asume that this is a win32 program, I'll drop the FAR stuff.  If I'm wrong we can put it back.  You want something like this.

typedef bool (*ProcPtrTyp)(char *,char *);
ProcPtrTyp Func;
Func = (ProcPtrTyp) GetProcAddress(hndl,"Passed");
if(Func(Name.c_str(),Password.c_str()))
{
   FreeLibrary(hndl);
   return 1;
}//Passed
else
{
   FreeLibrary(hndl);
   return 0;
}

0
 
LVL 22

Expert Comment

by:nietod
ID: 1162644
I've created a typedefinition for a pointer to a function of the format you've needed.  This isn't necessary, but it makes things much easier to read.  Then I declared Func to have the appropriate type.  Note I didn't know what type the function returned so I declared it as bool.  It might be int.

An improvement that would generate smaller code would be to store the result of the function call in a local variable.  Then call free library.  Then determine your return value from the saved result of the function call.  This will give you only one return point from the function (returns are actually a little costly) and one free library call.  Makes the code easier to maintain too.
0
 

Author Comment

by:Matlock
ID: 1162645
Thanks nietod,
your added comments made it clear where I was going wrong
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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.

719 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