Solved

Type Conversions

Posted on 2003-10-22
5
250 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
  • 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

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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