Solved

Type Conversions

Posted on 2003-10-22
5
253 Views
Last Modified: 2010-04-05
Ok Im Rather New To Delphi So I Ask Of Your Help.

Im Trying To Log Functions Parameters To File By Hooking It, But i aint too sure how to format pointers and hex data into a string.


Heres the function  def...
 
HANDLE hProcess,  // handle to process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // pointer to buffer to write data to
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten  // actual number of bytes written

handle = cardinal?
dword = cardinal?
lpvoid = pointer?
lpdword = pdword?

 
i tried..

FmtStr(TheParams,'%d, %.x, %.x, %d, %d', [hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten]);

but still crashes :/




Thanks.
0
Comment
Question by:JuleZzZ
[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
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9604193
handle = THandle
dword = DWord
lpvoid = pointer
lpdword = Pointer

 
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 9604242
Almost correct.
LPDWORD = PDWORD
Most of these pointer types are declared in Windows.pas
0
 

Author Comment

by:JuleZzZ
ID: 9604266
ok got it workin... changed pointer to cardinal.. :E

np
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 500 total points
ID: 9604583
That is not a good idea. Stay with pointer types where pointer types are expected.
Better typecast in your FmtStr

FmtStr(TheParams,'%d, %.x, %.x, %d, %d', [DWORD(hProcess), DWORD(lpBaseAddress), DWORD(lpBuffer), nSize, lpNumberOfBytesWritten]);

Aha. I see another bug. Most probably the source of your crash.
lpNumberOfBytesWritten is in C a pointer to a variable where the write call stores the number of bytes written.
The correct conversion for the write function is therefore
"var NumberOfBytesWritten: Cardinal"
You can stay with your conversion, but then you have to call it like this:

var
  NumberOfBytesWritten: DWORD;
begin
  write( ... , @NumberOfBytesWritten);
0
 

Author Comment

by:JuleZzZ
ID: 9611454
nice one. explained just about everything i needed to know


Thanks.
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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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