Application running as a process in Win2k?????

This is a discussion on Application running as a process in Win2k????? within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, I have a very unusual problem. I'v been writing programmes using WinAPI under windows98 at home and I'v ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    18

    Question Application running as a process in Win2k?????

    Hi all,
    I have a very unusual problem. I'v been writing programmes using WinAPI under windows98 at home and I'v had no problems.
    However, when I try to run my programmes on a win2k machine they run as a process, not as an application.
    Any ideas as to why this is happening.
    Thanks,
    Donal

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    All programs run as processes.......what do you mean?

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Oh...hang on....do you mean the dialog on CTR-ALT-DEL?


    If so its cuz WinNT based OSes allow you properly enumerate threads....it shows windows as well as non-windowed processes

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    Hi Fordy.
    I think i understand what you are saying but I am not using Threads. The programms run fine in the MSC++ environment. Its when I run them without the compiler then they run as processes and I can't interact with them! Could it have something to do with the way I setup the window class?
    Thanks,
    Donal

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by J_Bravo
    Hi Fordy.
    I think i understand what you are saying but I am not using Threads. The programms run fine in the MSC++ environment. Its when I run them without the compiler then they run as processes and I can't interact with them! Could it have something to do with the way I setup the window class?
    Thanks,
    Donal
    I have trouble understanding exactly what's wrong.....can you post a code sample please

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Did you make them as WIN32 app or WIN32 console app?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Unregistered
    Guest
    Here is my Main.cpp template that I have used.


    ************************************************** **
    #include<windows.h>
    #include<stdio.h>
    #include"resource.h"

    static HINSTANCE g_hInst = NULL;


    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);


    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
    {
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wndclass;

    wndclass.cbSize = sizeof (wndclass);
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = g_hInst;
    wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);

    wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

    wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    wndclass.lpszClassName = "Window Class 1";
    wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);

    RegisterClassEx (&wndclass);

    hwnd = CreateWindow ("Window Class 1",
    "My First Window",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    g_hInst,
    NULL);



    ShowWindow (hwnd, iCmdShow);
    UpdateWindow (hwnd);

    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    }

    return msg.wParam ;
    }



    BOOL CALLBACK DialogProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    switch(Message)
    {
    case WM_COMMAND:
    {
    switch(LOWORD(wParam))
    {
    case IDOK:
    EndDialog(hwnd, IDOK);
    return(TRUE);
    break;
    case IDCANCEL:
    if(MessageBox(hwnd, "An example of a message box returning a message"," ", MB_OKCANCEL)==IDOK)
    MessageBox(hwnd, "You Pressed OK", " ", MB_OK);
    else
    MessageBox(hwnd, "You Pressed Cancel", " ", MB_OK);
    return TRUE;
    break;
    }
    }
    break;

    case WM_DESTROY:
    EndDialog(hwnd, WM_DESTROY);
    return TRUE;
    break;
    }
    return FALSE;
    }




    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (iMsg)
    {
    case WM_COMMAND:
    {
    switch(LOWORD(wParam))
    {
    case ID_FILE_START:
    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DialogProc);
    break;
    case ID_FILE_EXIT:
    DestroyWindow(hwnd);
    break;
    case ID_HELP_ABOUT:
    MessageBox(hwnd, "This is a Template for a win32 application", "About", MB_OK);
    break;
    case ID_FILE_HIDE:
    ShowWindow(hwnd, SW_HIDE);
    ShowWindow(hwnd, SW_RESTORE);
    break;
    case ID_FILE_HIDEMOUSE:
    ShowCursor(FALSE);
    break;
    case ID_FILE_UNHIDEMOUSE:
    ShowCursor(TRUE);
    break;
    }
    }
    break;

    case WM_CREATE:
    break;

    case WM_SIZE:
    break;
    case WM_PAINT:
    break;
    PostQuitMessage(0); // This function actually puts a message on the message queue. SendMessage() sends a direct message, which is acted upon immediately. just for your information.
    break;
    }

    return DefWindowProc (hwnd, iMsg, wParam, lParam);


    }




    ************************************************** **

    Now, when I compile and run this using VC++ under win2k it works fine. However, when I execute the exe without VC++ under win2k, the programme doesn't appear. It seams as though the program hasn't run at all. If I then run Windows Task Manager and check Processes, I can see my exe there.

    Hope this explains it better.
    Thanks
    Donal

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Please use code tags!!!!

    The only reason I am posting is because I saw an error straight away. Because you did not use tags I was not going to bother sifting thru your code. 13 extra key strokes is not much to ask.

    You seem to be using g_Inst without setting it = hInstance. (or I have missed it) Add before init of the winclass.

    PostQuitMessage(0); //this is being sent as a default closing the app almost immediately.

    Should be in WM_QUIT and/or WM_DESTROY ,WM_CLOSE case. It is not a case on its own.

    There are more including sending a destroy on receiving a destroy.
    Last edited by novacain; 05-07-2002 at 04:33 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    Thanks for the help novacain, that worked fine.
    And in future I'll use code tags.
    Cheers,
    Donal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to check if own created process is still running
    By s-men in forum Windows Programming
    Replies: 3
    Last Post: 01-24-2009, 11:39 AM
  2. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 12:08 PM
  3. running application from command prompt
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2007, 05:24 AM
  4. Round Robin Scheduling using c.
    By eclipt in forum C Programming
    Replies: 8
    Last Post: 12-28-2005, 04:58 PM
  5. Process still active when application exits
    By xds4lx in forum Windows Programming
    Replies: 13
    Last Post: 08-15-2002, 03:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21