Solved

How call win32 func using pointer?

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

16 Experts available now in Live!

Get 1:1 Help Now