Solved

How call win32 func using pointer?

Posted on 2002-05-23
1
289 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
[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
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

728 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