Thread: Pointer to memory

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    Pointer to memory

    I found the code below as a DOS program and I need it to include in my MFC Windows program but I got an error of "Memory could not be read", Is there another way to handle this in Windows?

    This is the code:

    unsigned int GetLPT1Addr()
    {
    unsigned int far *ptraddr;
    unsigned int address;
    ptraddr=(unsigned int far*)0x00000408;
    address=*ptraddr;
    return address;
    }

    Thanks in advance,
    Alextrons
    If they can, why can't I...

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    32 bit windows and 16 bit DOS handle things very differently. You cannot expect to port old DOS code like this to a 32 bit environment.

    If you want to "talk" to a port, look at the CreateFile() API function with particular regard to the "communications resources" sections.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Thanks Adrian for the idea, but how about _inp() and _outp() functions? Can we use this to get the address of LPT1? And you mean that there is no "ptraddr=(unsigned int far*)0x00000408; " kind of code in VC++? Can you make an equivalent code for me for that one line?


    Sorry for being insistent, I hope you don't mind.
    If they can, why can't I...

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    but how about _inp() and _outp() functions?
    You can't use those in a win32 app either. As Adrian has stated you can use CreateFile(), along with these.
    zen

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Originally posted by Alextrons
    Thanks Adrian for the idea, but how about _inp() and _outp() functions? Can we use this to get the address of LPT1? And you mean that there is no "ptraddr=(unsigned int far*)0x00000408; " kind of code in VC++? Can you make an equivalent code for me for that one line?


    Sorry for being insistent, I hope you don't mind.
    It has nothing to do with VC++. Windows won't let you access memory like that. Memory management prohibits you from accessing memory not allocated to your program.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    So can teach how to do it in Windows?
    If they can, why can't I...

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    So can you please teach me how to do it in Windows.
    If they can, why can't I...

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    OffTopic

    to Alextrons: If you make a typo, you have an EDIT button in the lower right corner of your post. No need to post a new one
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Ah...Ok thanks...
    If they can, why can't I...

  10. #10
    Sayeh
    Guest
    Yeppers, that is exactly why you use the new API (It's called: WinAPI)--- It has a toolbox full of routines to do everything and more that you could do in dos.

    You don't go direct to devices under the API, you call a manager and uses it's routines to access that device.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. Replies: 5
    Last Post: 03-23-2009, 03:44 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM