Click here to Skip to main content
15,922,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: Static Extension Methods? Pin
Skippums26-Feb-08 4:51
Skippums26-Feb-08 4:51 
QuestionWhat does it mean Pin
netJP12L25-Feb-08 7:53
netJP12L25-Feb-08 7:53 
AnswerRe: What does it mean Pin
led mike25-Feb-08 8:11
led mike25-Feb-08 8:11 
GeneralParsing a custom date string to a DateTime Object Pin
Sunset Towers25-Feb-08 6:48
Sunset Towers25-Feb-08 6:48 
GeneralRe: Parsing a custom date string to a DateTime Object Pin
Gareth H25-Feb-08 7:33
Gareth H25-Feb-08 7:33 
GeneralRe: Parsing a custom date string to a DateTime Object Pin
Sunset Towers25-Feb-08 7:52
Sunset Towers25-Feb-08 7:52 
GeneralRe: Parsing a custom date string to a DateTime Object Pin
led mike25-Feb-08 8:10
led mike25-Feb-08 8:10 
GeneralSystem error codes, FormatMessage, and memory reading. [modified] Pin
Jitse25-Feb-08 5:55
Jitse25-Feb-08 5:55 
Hi ho Smile | :)

I've noticed something weird. When I try to read an unexisting address location (using ReadProcessMemory of kernel32 libraries), it gives an exception. This is totally normal. Then I'm able to retrieve the error code with GetLastError(). This code can be formatted, which returns a nice string message in my native language.

But now I've noticed something that's not quite normal. When I run the application normally, and the expected exception happens, the FormatMessage returns something like:

"A Read/WriteProcessMemory-operation is only partly executed."

Riiiiiight... WTF | :WTF: Now the weirdest thing is, if I put a debugging breakpoint just before I retrieve the error code with GetLastError(), and then do a step-by-step running (you know, the F11/F10 thing), it returns something totally different:

"Tried to point to an unexisting token."

Which is the message I want, because that's exactly what I did wrong. But still he doesn't return it if I don't put a breakpoint just before the GetLastError() function. It's as if the system needs a little time to store the error code, and my program is too fast requesting it. I tried a System.Threading.Thread.Sleep(100); or so, but that didn't work.

Here's my code, if that helps:

<br />
if (!ReadProcessMemory(handle, new IntPtr(address), buffer, length, out bytesReadPtr))<br />
{<br />
    StringBuilder str = new StringBuilder();<br />
    str.Capacity = 1000;<br />
    FormatMessage(<br />
        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,<br />
        IntPtr.Zero,<br />
        GetLastError(),<br />
        0,<br />
        str,<br />
        1000,<br />
        IntPtr.Zero);<br />
    throw new Exception("Unable to read process memory.\n" + str.ToString());<br />
}<br />


Anyone knows what's going on? Smile | :)

Thanks in advance.

(Btw. Can't I use decent tabs in code on this forum? Confused | :confused: )

modified on Sunday, March 2, 2008 12:03 PM

GeneralClear textbox problem Pin
Rick van Woudenberg25-Feb-08 5:30
Rick van Woudenberg25-Feb-08 5:30 
GeneralRe: Clear textbox problem --&gt; And this works Pin
Rick van Woudenberg25-Feb-08 5:33
Rick van Woudenberg25-Feb-08 5:33 
GeneralRe: Clear textbox problem --&gt; And this works Pin
Gareth H25-Feb-08 6:46
Gareth H25-Feb-08 6:46 
GeneralRe: Clear textbox problem Pin
engsrini25-Feb-08 11:47
engsrini25-Feb-08 11:47 
QuestionProcess memory, significant addresses Pin
Jitse25-Feb-08 4:33
Jitse25-Feb-08 4:33 
GeneralRe: Process memory, significant addresses Pin
Luc Pattyn25-Feb-08 4:48
sitebuilderLuc Pattyn25-Feb-08 4:48 
GeneralRe: Process memory, significant addresses Pin
Jitse25-Feb-08 5:02
Jitse25-Feb-08 5:02 
GeneralRe: Process memory, significant addresses Pin
Luc Pattyn25-Feb-08 5:28
sitebuilderLuc Pattyn25-Feb-08 5:28 
GeneralRe: Process memory, significant addresses Pin
Jitse25-Feb-08 5:43
Jitse25-Feb-08 5:43 
GeneralC# Windows Service shutting down Pin
Saamir25-Feb-08 4:04
Saamir25-Feb-08 4:04 
GeneralRead Outlook express - 6 contacts using c# 2005 Pin
Member 4463561 @##$#%$#%*(*&^(&)(_++[25-Feb-08 4:02
Member 4463561 @##$#%$#%*(*&^(&)(_++[25-Feb-08 4:02 
GeneralRe: Read Outlook express - 6 contacts using c# 2005 Pin
Judah Gabriel Himango25-Feb-08 5:54
sponsorJudah Gabriel Himango25-Feb-08 5:54 
GeneralRun time error Pin
Mc_Topaz25-Feb-08 3:57
Mc_Topaz25-Feb-08 3:57 
GeneralRe: Run time error Pin
Judah Gabriel Himango25-Feb-08 5:48
sponsorJudah Gabriel Himango25-Feb-08 5:48 
GeneralRe: Run time error [modified] Pin
Mc_Topaz25-Feb-08 20:23
Mc_Topaz25-Feb-08 20:23 
GeneralRe: Run time error Pin
Judah Gabriel Himango26-Feb-08 6:33
sponsorJudah Gabriel Himango26-Feb-08 6:33 
GeneralRe: Run time error Pin
Gareth H25-Feb-08 6:54
Gareth H25-Feb-08 6:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.