Solved

Type Conversions

Posted on 2003-10-22
5
249 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
Comment Utility
handle = THandle
dword = DWord
lpvoid = pointer
lpdword = Pointer

 
0
 
LVL 11

Expert Comment

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

Author Comment

by:JuleZzZ
Comment Utility
ok got it workin... changed pointer to cardinal.. :E

np
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 500 total points
Comment Utility
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
Comment Utility
nice one. explained just about everything i needed to know


Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

11 Experts available now in Live!

Get 1:1 Help Now