Thread: Converting ASCII character, to the code that represents it.....?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    Question Converting ASCII character, to the code that represents it.....?

    hi, here is my code
    Code:
    #include <windows.h>
    #include <stdio.h>
    #define ADDR 0x100AEC4
    
    int main()
    {
    HWND gHwnd;
    DWORD pid;
    HANDLE hProcess;
    
    char result;
    gHwnd = FindWindow(NULL,"********");
    if(!gHwnd)
    {MessageBox(0,"******* could not be detected.","Error",0); return 0;}
    
    GetWindowThreadProcessId(gHwnd,&pid);
    
    hProcess = OpenProcess(PROCESS_ALL_ACCESS,true,pid);
    if(!hProcess)
    {MessageBox(0,"Couldnt get a process handle to SD","Error",0); return 0;}  
    
    ReadProcessMemory(hProcess,(void *)ADDR,(void*)&result,4,NULL);
    //working on getting msgbox to show actual number, not ascii character of the supposed code
    MessageBox(0,(&result),"Warning",MB_OK | MB_ICONWARNING);
    return 0;   
         
    }
    The code works, in that it grabs the value (255) from a memory address, but the messagebox displays it as ÿ, the 255th ascii character i believe.

    How can i get it to just display the number?

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this.
    Code:
    #include <sstream>
    #include <windows.h>
    //#include <stdio.h>
    #define ADDR 0x100AEC4
    
    int main()
    {
    HWND gHwnd;
    DWORD pid;
    HANDLE hProcess;
    
    char result;
    gHwnd = FindWindow(NULL,"********");
    if(!gHwnd)
    {MessageBox(0,"******* could not be detected.","Error",0); return 0;}
    
    GetWindowThreadProcessId(gHwnd,&pid);
    
    hProcess = OpenProcess(PROCESS_ALL_ACCESS,true,pid);
    if(!hProcess)
    {MessageBox(0,"Couldnt get a process handle to SD","Error",0); return 0;}  
    
    ReadProcessMemory(hProcess,(void *)ADDR,(void*)&result,4,NULL);
    //working on getting msgbox to show actual number, not ascii character of the supposed code
    
       std::ostringstream out;
       out << (unsigned int)(unsigned char) result;
       std::string message = out.str();
    
       MessageBox(0,message.c_str(),"Warning",MB_OK | MB_ICONWARNING);
    
    return 0;   
         
    }

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    2
    oh wow thanks a lot ! works perfect
    With a slight modification, it was just what i needed ~~
    Last edited by Zelocke; 01-25-2006 at 11:06 AM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    There's an FAQ entry on the subject: http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Just use chars instead of ints.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. converting c code to c++, the foreach statement
    By hwttdz in forum C++ Programming
    Replies: 2
    Last Post: 07-12-2006, 11:03 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. wchar_t type
    By gustavosserra in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2003, 04:49 PM
  5. ASCII code for a NULL character
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 12-09-2001, 05:40 AM