Thread: Weird access to an exe compiled with windows.h

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    85

    Weird access to an exe compiled with windows.h

    I discovered a really odd happening. I'm using devc++ 4.9.9.2.

    I have a piece of code with an infinite loop (stopped by ctrl+c), that compiles ok. I can make a change, and recompile it, works ok. If I add windows.h whenver I stop the program, modify it and try to recompile it, access to that file is denied. I can't delete it, or run it after this point.

    It's really really annoying since I have to click a few extra times to rename the output file before each compile.

    Any ideas why this is happening?

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Off hand without seeing the code, I would guess, your program is not ending... this is common mistake in beginners windows program. If you don't create a handler to handle WM_DESTROY, more specifically, by calling PostQuitMessage when your app needs to end, it will continue to run even though the window has closed.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    Do you guys around here know every possible thing? ^^
    Anyway, thanks a ton. Solved.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Unless you're building an actual Windows-Windows program, it should be compiled as a console program imo.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    I need access to at least the millisecond clock resolution.
    I have found no other way to get this than through the wonderful (random guy in crowd screaming: and efficient!) windows kernel.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    This is like being surprised you get food from a restaurant from the kitchen. Where the heck else do you expect this to come from?

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    85
    A secret function they included that runs in half CPU timeshare with the kernel. No, really ^^ Ah well. I guess if I'll really put my head to it, there is a way to read it directly from the bios, make a .com in assembler to spit it out, run that com from my program, and tada.

    To be honest, I thought I might get it elsewhere, but I guess that all functions are there since that's the purpose of the OS, hardware abstraction. If it's not in the os, I can't get it. Doh.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Except of course that firing up the 8086 emulation environment, loading the .com into it, executing it, finding out that it tries to do something not directly allowed, emulating the operation, collecting the output and returning it to your program takes faaaaaaaaaaaaaaaar longer than calling into the kernel a hundred times - certainly longer than a millisecond.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I think this is a clear case of someone not understanding how this stuff works. This isn't like an NES or SNES where you talk directly to the hardware, and for all intents and purposes, you are the O/S. You're not allowed to do that on Windows unless you're a driver, and even then, you have conditions that you must stick with (ie. conforming to specifications).

    Nowadays, your program talks to the O/S and requests resources, be it extra memory, file access, or whatever else. If the O/S doesn't like you, it says no, and that's that. That's how modern operating systems work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Store a file into an exe after compiled?
    By megablue in forum C Programming
    Replies: 4
    Last Post: 05-19-2009, 10:27 PM
  2. Weird access violation error with stack
    By ryeguy in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 02:53 AM
  3. Are comments compiled into and exe file?
    By Chris2222 in forum C Programming
    Replies: 5
    Last Post: 10-01-2007, 01:49 PM
  4. reading file weird access violation
    By p3p in forum C++ Programming
    Replies: 6
    Last Post: 09-03-2005, 08:06 AM
  5. Operator overloading in template classes
    By moejams in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2003, 05:16 PM