Thread: cannot open Debug/c.exe for writing

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    385

    cannot open Debug/c.exe for writing

    when I try to compile the following code it says "cannot open Debug/c.exe for writing"


    Code:
    /*------------------------------------------------------------
       HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
                     (c) Charles Petzold, 1998
      ------------------------------------------------------------*/
    
    #include <windows.h>
    
    #undef WS_OVERLAPPEDWINDOW 
    
    #define WS_OVERLAPPEDWINDOW (WS_SYSMENU )
    
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("HelloWin") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL ,IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
    
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("The Hello Program"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              CW_USEDEFAULT,              // initial x size
                              CW_USEDEFAULT,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
         
    	 
         ShowWindow (hwnd, iCmdShow ) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         HDC         hdc ;
         PAINTSTRUCT ps ;
         RECT        rect ;
         
         switch (message)
         {
         case WM_CREATE:
              PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
              return 0 ;
              
         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;
              
              GetClientRect (hwnd, &rect) ;
              
              DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
                      DT_SINGLELINE |DT_CENTER | DT_VCENTER ) ;
              
              EndPaint (hwnd, &ps) ;
              return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
    
    	 }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> "cannot open Debug/c.exe for writing"
    Either c.exe is currently running in that location, or you don't have permissions to write.

    >> #define WS_OVERLAPPEDWINDOW (WS_SYSMENU )
    Don't do that. Just use WS_SYSMENU

    >> while (GetMessage (&msg, NULL, 0, 0))
    GetMessage() does not return a boolean.

    >> PlaySound (TEXT ("hellowin.wav") ...
    First parameter to PlaySound is not a TCHAR string. ([edit] Oops, actually it is a TCHAR string.[/edit])

    >> TEXT ("Hello, Windows 98!")
    Windows 98: "Get off of my lawn!" <shakes cane>

    gg
    Last edited by Codeplug; 01-05-2012 at 01:04 PM. Reason: bad info

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    alright. Am new to windows programming, so just wanted to ask how come the window gets closed even if we remove the PostQuitMessage call from line no. 89.

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by Codeplug View Post
    >> while (GetMessage (&msg, NULL, 0, 0))
    GetMessage() does not return a boolean.
    That calling of it does. You can only get it to return -1 if you pass in a non-null, non-(HWND)-1 and non-(HWND)0xffff invalid HWND. The other case mentioned in the GetMessage docs (an invalid message pointer) returns 0 on NT4 and lower versions of NT, causes an exception in 2000+ versions and returns 1 regardless in DOS versions of Windows.

    PlaySound (TEXT ("hellowin.wav") ...
    First parameter to PlaySound is not a TCHAR string.
    It is unless you're writing code for Windows Mobile, which is what your 'correct' page refers to.

    Code:
    TEXT("This program requires Windows NT!")
    TEXT ("Hello, Windows 98!")
    Hilarious

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Commenting out line 89 doesn't affect the closing of the window. It does prevent the application from closing since the message loop never exits.

    gg

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by juice View Post
    alright. Am new to windows programming, so just wanted to ask how come the window gets closed even if we remove the PostQuitMessage call from line no. 89.
    Closing a window and exiting a program are two totally different things. (As Codeplug points out).

    Open task manager and look at the processes tab... it's very likely one (or more) copies of your program are still running, which is causing the error you're getting!


    Also... did I read correctly that you're using windows 98?
    If so .... RUN --do not walk, do not hesitate, RUN-- to your nearest computer store and get an OS that is younger than you are!

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Quote Originally Posted by CommonTater View Post
    did I read correctly that you're using windows 98?
    Haha.. no am not using windows 98. Am referring programming windows by chales petzold and I directly imported the code from the companion CD ROM, and since the book was written in (I suppose) 1998 thats why the antiquated code. I wonder if there could be anyone still using windows 98.

  8. #8
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Quote Originally Posted by Codeplug View Post
    Commenting out line 89 doesn't affect the closing of the window. It does prevent the application from closing since the message loop never exits.

    gg
    didn't understand what that means??

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> ... how come the window gets closed even if we remove the PostQuitMessage call from line no. 89.
    First thing I would do is look up that function call to see what may happen by removing it. MSDN is the main documentation for MS API's.
    PostQuitMessage function
    Quote Originally Posted by MSDN
    The PostQuitMessage function posts a WM_QUIT message to the thread's message queue and returns immediately;
    Next I would click on WM_QUIT to see what that message is all about.
    WM_QUIT message
    Quote Originally Posted by MSDN
    Indicates a request to terminate an application, and is generated when the application calls the PostQuitMessage function. This message causes the GetMessage function to return zero.
    So this is the primary mechanism that causes the message loop to stop looping. The window is still destroyed - whether you call PostQuitMessage or not.

    gg

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by juice View Post
    didn't understand what that means??
    As Codeplug points out it means that you can close a window without exiting the application.
    The window is not the application... it is something produced by the application.

    And yes, you can write windows GUI mode programs that don't have windows or use dialogs instead of windows.


    That's why your message loop should look like this...
    Code:
         while (GetMessage (&msg, NULL, 0, 0) > 0) 
             { TranslateMessage (&msg) ;
                DispatchMessage (&msg) ;  }      
          return msg.wParam ;
    Look up the msn documentation for GetMessage ... you will discover that it returns 0 for WM_QUIT and negative numbers for errors. Thus a simple while loop is inadequate to cause a program exit if an error occurs.

    What you should do before you get too far into this is download and install a copy of the Windows SDK... It's full documentation of the Windows API and all it's features. You're going to be positively lost without it. Almost every windows call needs to be looked up to ensure correct syntax... and there are about 30,000 of them so don't even bother trying to remember them,

    Windows SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-25-2010, 11:45 AM
  2. Good practice of writing debug print statements
    By hzmonte in forum C Programming
    Replies: 11
    Last Post: 11-09-2005, 11:55 PM
  3. Cannot open debug/filename.exe for writing
    By Shadow12345 in forum C++ Programming
    Replies: 2
    Last Post: 08-26-2002, 10:44 AM
  4. writing a file to an open socket...
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 06-30-2002, 08:43 PM
  5. Writing to the Debug window ~ VC++
    By Okiesmokie in forum C++ Programming
    Replies: 5
    Last Post: 05-10-2002, 08:50 AM