Solved

Dynamic Link of DLL func in CBuilder 3

Posted on 1998-04-21
4
270 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 60 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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