Solved

How call win32 func using pointer?

Posted on 2002-05-23
1
287 Views
Last Modified: 2013-12-03
I want to store the address of a win32 function (for example GetLocalTime) in a pointer var and then
use the pointer var to call GetLocalTime. While assigning the offset of GetLocalTime to pointer var,
I would like to add in an additional value like a random number, say 37, which I'll subtract back off
before calling. My C/C++ is pretty weak but in ASM it looks like:

RNDNUM    = 37
mov       [ptrGLT],offset GetLocalTime + RNDNUM
sub       [ptrGLT],RNDNUM
call      [ptrGLT],offset SystemTime
0
Comment
Question by:mortonsw
1 Comment
 
LVL 1

Accepted Solution

by:
RolandAZ earned 100 total points
ID: 7031548

MortonSW,


create a new type for the function pointer:
typedef void ( __stdcall *LPFUNCGETLOCALTIME) (LPSYSTEMTIME);

////
SYSTEMTIME systemTime;
LPFUNCGETLOCALTIME fPtrGETLOCALTIME;
DWORD RNDNUM = 37;
     
fPtrGETLOCALTIME = &GetLocalTime;  //get address
//your math
fPtrGETLOCALTIME = (LPFUNCGETLOCALTIME)((DWORD)
                         fPtrGETLOCALTIME + RNDNUM);
fPtrGETLOCALTIME = (LPFUNCGETLOCALTIME)((DWORD)
                        fPtrGETLOCALTIME - RNDNUM);
//---
fPtrGETLOCALTIME(&systemTime); //the function call


Works on Win2k ...
Copy and paste to try it in your program..

Have fun...
Roland
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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

838 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