Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Type Conversions

Posted on 2003-10-22
5
Medium Priority
?
257 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

824 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