Using VC++ 4.0 - pointers HELP!!! 
Author Message
 Using VC++ 4.0 - pointers HELP!!!

Hello, I need some VERY quick and useful help. All of you Visual C++ 4.0
users I need some answers. I am having difficulty when I assign a pointer
to a specific memory address (see example). The program compiles fine, but
gives an Access Violation (C0000005) error when I run it. I compiled the
code on MS C 5.1 and ran it on my Win95 machine and it ran fine. What
gives?? If I get an Access error with one executable, should I not get the
same from another (even if the machine instructions are a LITTLE different
- it is still accessing the same part of memory )? Please help, any would
be appreciated - an example program is below. All it is supposed to do is

#include <stdio.h>

main()
{

    char *flags = (char *)0x00000417;   /* memory location of keyboard
                                        indicator flags in Windows95 */

    *flags |= 64;                               /* turn CAPS LOCK on */

    return( 0 );

Quote:
}



Fri, 24 Dec 1999 03:00:00 GMT  
 Using VC++ 4.0 - pointers HELP!!!

: Hello, I need some VERY quick and useful help. All of you Visual C++ 4.0
: users I need some answers. I am having difficulty when I assign a pointer
: to a specific memory address (see example). The program compiles fine, but
: gives an Access Violation (C0000005) error when I run it. I compiled the
: code on MS C 5.1 and ran it on my Win95 machine and it ran fine. What
: gives??

You've moved the code from a platform with *NO* memory protection
whatsoever to one that has a considerable amount of protection.
You're going from DOS to Win32.

Scott



Fri, 24 Dec 1999 03:00:00 GMT  
 Using VC++ 4.0 - pointers HELP!!!

Quote:

> Hello, I need some VERY quick and useful help. All of you Visual C++ 4.0
> users I need some answers. I am having difficulty when I assign a pointer
> to a specific memory address (see example). The program compiles fine, but
> gives an Access Violation (C0000005) error when I run it. I compiled the
> code on MS C 5.1 and ran it on my Win95 machine and it ran fine. What
> gives?? If I get an Access error with one executable, should I not get the
> same from another (even if the machine instructions are a LITTLE different
> - it is still accessing the same part of memory )? Please help, any would
> be appreciated - an example program is below. All it is supposed to do is

> #include <stdio.h>

> main()
> {

>     char *flags = (char *)0x00000417;   /* memory location of keyboard
>                                         indicator flags in Windows95 */

>     *flags |= 64;                               /* turn CAPS LOCK on */

>     return( 0 );

> }

Hallo Justin,
  every pointer you use which points to a location which does not belong
to your program causes access violations. Also it is not a good practice
to use the memory adress to encounter the indicator flags in win95. In
fact, there are some Win32/MFC routines which do exactly the thing you
want.

  Holger

--



Sat, 25 Dec 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Non VC++ 4.0 using DAO and ODBC under VC++ 4.0

2. Need help with printing using the Enhanced MetaFiles, VC++ 4.0, MFC

3. Beginner: Problems Using OLE Forms using VC++ 4.0

4. Printer setup using vc++ 4.0

5. nt 4.0 compatable with vc++ 4.0?

6. Help:overloading delete operator in vc++ 4.0

7. Help:overloading delete operator in vc++ 4.0

8. Get contents of this pointer in debugger of VC++ 4.0 Professional

9. SHFileOperation function using VC++ 4.0

10. Is P-code used in VC++ 4.0?

11. using VC++ 4.0

12. uart+serial port on NT 4.0 using VC++5.0

 

 
Powered by phpBB® Forum Software