Menu

Permission Denied?

Anubis208
2007-08-12
2012-09-26
  • Anubis208

    Anubis208 - 2007-08-12

    I am compiling a project with the folowing files and sources on Windows XP.

    resource.h

    define IDR_MYMENU 101

    define IDR_MYICON 102

    define IDD_ABOUT 103

    define ID_FILE_EXIT 9001

    define ID_STUFF_GO 9002

    define ID_HELP_ABOUT 9003

    --

    resource.rc

    if !defined (_WINDOWS)

    define _WINDOWS

    endif

    ifndef IDC_STATIC

    define IDC_STATIC (-1)

    endif

    include "windows.h"

    include "resource.h"

    IDR_MYMENU MENU
    BEGIN
    POPUP "&File"
    BEGIN
    MENUITEM "E&xit", ID_FILE_EXIT
    END
    POPUP "&Stuff"
    BEGIN
    MENUITEM "&Go", ID_STUFF_GO
    MENUITEM "G&o somewhere else", 0, GRAYED
    END
    POPUP "&Help"
    BEGIN
    MENUITEM "&About", ID_HELP_ABOUT
    END
    END

    IDI_MYICON ICON "Smile.ico"

    IDD_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My about box....."
    FONT 8, "MS Sans Serif"
    BEGIN
    DEFPUSHBUTTON "OK", IDOK, 174, 18, 50, 14
    PUSHBUTTON "Cancel", IDCANCEL, 174, 35, 50, 14
    GROUPBOX "About this program....", IDC_STATIC, 7, 7, 225, 52
    CTEXT "An example program showing how to display Dialog Boxes/r/n/r/nby theForger",
    IDC_STATIC, 16, 18, 144, 33
    END
    --


    Main.cpp

    include <windows.h>

    include "resource.h"

    define ID_FILE_EXIT 9001

    define ID_STUFF_GO 9002

    HICON hIcon;
    HICON hIconSm;
    / Declare Windows procedure /
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    / Make the class name into a global variable /
    char szClassName[ ] = "WindowsApp";

    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    switch(Message)
    {
    case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hwnd, IDOK);
                break;
                case IDCANCEL:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
    

    }

    int WINAPI WinMain (HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszArgument,
    int nFunsterStil)

    {
    HWND hwnd; / This is the handle for our window /
    MSG messages; / Here messages to the application are saved /
    WNDCLASSEX wincl; / Data structure for the windowclass /

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);
    
    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MYICON));
    wincl.hIconSm = LoadIcon (NULL, MAKEINTRESOURCE(IDR_MYICON));
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    
    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&amp;wincl))
        return 0;
    
    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           &quot;Windows App&quot;,       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
    
    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&amp;messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&amp;messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&amp;messages);
    }
    
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
    

    }

    / This function is called by the Windows function DispatchMessage() /

    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message) / handle the messages /
    {
    case WM_CREATE:
    {
    HICON hIcon, hIconSm;
    hIcon = (HICON)LoadImage(NULL, "Smile.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
    if(hIcon)
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
    else
    MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);

            hIconSm = (HICON)LoadImage(NULL, &quot;Smile.ico&quot;, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
            if(hIconSm)
                       SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
            else
                MessageBox(hwnd, &quot;Could not load small icon!&quot;, &quot;Error&quot;, MB_OK | MB_ICONERROR);
          }
       break;
    
        case WM_COMMAND:
             switch(LOWORD(wParam))
             {
                    case ID_FILE_EXIT:
                         PostMessage(hwnd, WM_CLOSE,0,0);
                         break;      
                    case ID_STUFF_GO:
                         MessageBox(NULL,&quot;Woooooooooooh, you clicked go!&quot;,&quot;Go&quot;,MB_ICONEXCLAMATION|MB_OK);
                         break;  
                    case ID_HELP_ABOUT:
                    int ret = DialogBox(GetModuleHandle(NULL), 
                        MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                    if(ret == IDOK){
                           MessageBox(hwnd, &quot;Dialog exited with IDOK.&quot;, &quot;Notice&quot;,
                    MB_OK | MB_ICONINFORMATION);
                    }
                    else if(ret == IDCANCEL){
                         MessageBox(hwnd, &quot;Dialog exited with IDCANCEL.&quot;, &quot;Notice&quot;,
                         MB_OK | MB_ICONINFORMATION);
                    }
                    else if(ret == -1){
                         MessageBox(hwnd, &quot;Dialog failed!&quot;, &quot;Error&quot;,
                         MB_OK | MB_ICONINFORMATION);
                    }
                    break; 
             }
             break;
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    
    return 0;
    

    }


    Here's the compile log.

    Compile Log

    Compiler: Default compiler
    Building Makefile: "C:\mycppstuff\menu3\Makefile.win"
    Executing make clean
    rm -f main.o Project1_private.res Project1.exe

    rm: Project1.exe: Permission denied

    make.exe: *** [clean] Error 1

    Execution terminated

    My program doesn't show up when I try to run it from Dev-Cpp or from browsing for it and double-clicking on it. The compile buttons on the compiler are ghosted out when I run it, but nothing happens. I have tried a rebuild All and it doesn't work. Could somebody please help me?

     
    • Wayne Keen

      Wayne Keen - 2007-08-12

      This error suggest something:

      "rm: Project1.exe: Permission denied"

      it is telling you that the attempt to "rm" which is the command to remove failed,
      because the permission to do the removal operation was not granted by the OS.

      This can arise from several things. It comes up with a lot of new folks because they
      started a program that had that name, and never really shut it down. The OS will not let
      a file that is being executed be deleted. The brute force way to kill a task like this
      is a restart, with a less brute force means being to look through the task manager and
      kill it from there.

      It could also be a permision issue with the folder that the file is in.

      A variety of things, subtle things can lead to a given error condition, so you begin
      to see how hard it it to remote debug someone's problem when you are not there with
      them. I say this because a lot of new folks are under the impression that we can
      look at an error message, and come up with an instant diagnosis - if only it were that
      easy. :(

      Wayne

       
    • Anubis208

      Anubis208 - 2007-08-12

      Ok thanks for the help that you could give. It turns out six instances of my application were being run as processes so they were a little harder to track down. I ended those and now it works. Thanks again.

       
      • Wayne Keen

        Wayne Keen - 2007-08-12

        Great!

        Like I said, there is always the brute force means of a restart.

        As I am sure Clifford would volunteer, if there is a simple-minded and stupid
        solution to a problem, Wayne will suggest it. Big :)

        Wayne

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.