Results 1 to 5 of 5

Thread: "Cant read memory" error

  1. #1

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    "Cant read memory" error

    This code works but retuns an error saying:
    The instruction at "0x6f746172" referenced memory at "0x6f746172". The memory could not be "read".
    (this error seems to occur at the very end of the code).

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
    	char s_username;
    	unsigned long i_length;
    	GetUserName (&s_username, &i_length);
    	printf(&s_username);
    	return 0;
    }
    Why is that?
    Cbomb
    Techie

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    It does not give me any error in vc++ but when I run it, it gives me some weird characters as the username
    Baaaaaaaaah

  3. #3

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    hmm

    grrr....very weird...

    I get: "Administrator" *error occurs here* "Press any key to exit"
    Cbomb
    Techie

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: "Cant read memory" error

    You need to use a buffer:
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main() {
        char pcUserName[100];
        unsigned long lLength = 100;
        GetUserName(pcUserName, &lLength);
        printf("%s\n", pcUsername);
        return 0;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    ohhhhhhhh

    Thank you VERY much
    Cbomb
    Techie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width