[program-l] Re: Calling functions at addresses

  • From: "Will Pearson" <will-pearson@xxxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Mon, 5 Sep 2005 14:53:19 +0100

Hi,

To add to what Mark has given, you need to use function pointers, which is implied by MSDN, but not that obvious if you are not familiar with function pointers. A function pointer is just like a normal pointer, but the type is specified by the return type and parameter types of the function. So, void (*)() equates to the type of a function pointer where the function returns void and takes no parameters. To declare a function pointer, not just declare the type of a function pointer, you have to give it a name. You place the variable name immediately following the *. So void (*fp)() will declare a function pointer named fp, where the type of the function is one that returns void and takes no parameters. To call the function, you simply dereference the function pointer, passing in any arguments that are necessary.

As you will need a few different function types, one for each set of return types and parameter types, you'll likely need to use a switch statement. The switch will work by determining the type of the function, and then calling GetProcAddress, assigning the address to a pointer of the appropriate type, then dereferencing the pointer to call the function.

You can find plenty about function pointers on the web, in C/C++ tutorials, and my favourite site for this sort of information is the C++ reference guide on www.informit.com

Will
----- Original Message ----- From: "Mark Long" <Mark.Long@xxxxxxxxxxxxx>
To: <program-l@xxxxxxxxxxxxx>
Sent: Monday, September 05, 2005 1:58 PM
Subject: [program-l] Re: Calling functions at addresses



MSDN is your friend

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc
/base/getprocaddress.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc
/base/using_run_time_dynamic_linking.asp


-----Original Message----- From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of SEAN FARROW Sent: 05 September 2005 12:55 To: program-l@xxxxxxxxxxxxx Subject: [program-l] Re: Calling functions at addresses

Hi: mark:
The functions I will be calling will have the following attributes:
1. They will all be withing the dll I am writing.
2. They wioll all either return void, bool or int.
Can you shed any more light on the issue?
Regards
Sean.

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq



** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: