Solved

How call win32 func using pointer?

Posted on 2002-05-23
1
285 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now