Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. System call under NT w/o CMD win

System call under NT w/o CMD win

Scheduled Pinned Locked Moved IT & Infrastructure
linuxquestion
5 Posts 3 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, I have an application which runs under NT4/Win2K which needs to be called routinely (it's a console application, which also runs under cron on Unix). To solve this, I have written a small service, which basically sleeps and runs the application using the system() call. This works well, except for the fact that a CMD window ('dos shell') annoyingly pop's up every time the application is run. Is there anyone who knows how I can get rid of this? I don't know much about Windows programming, but I thought maybe there was some way I could turn the application into a windows application, and then simply not create any windows. Or, if there is another call, similar to system(), that will allow me to run other executables without getting a window. All assistance appreciated! Sincerely, Sverre Hjelm, eJournal AS

    L 1 Reply Last reply
    0
    • L Lost User

      Hi, I have an application which runs under NT4/Win2K which needs to be called routinely (it's a console application, which also runs under cron on Unix). To solve this, I have written a small service, which basically sleeps and runs the application using the system() call. This works well, except for the fact that a CMD window ('dos shell') annoyingly pop's up every time the application is run. Is there anyone who knows how I can get rid of this? I don't know much about Windows programming, but I thought maybe there was some way I could turn the application into a windows application, and then simply not create any windows. Or, if there is another call, similar to system(), that will allow me to run other executables without getting a window. All assistance appreciated! Sincerely, Sverre Hjelm, eJournal AS

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      hmmm, why don't you make the application itself a service. Other choice would be as you have suggested, Changing the application into a Window app and call it using ShellExecute(); with SW_HIDE flag Regards Alfadhly

      H 1 Reply Last reply
      0
      • L Lost User

        hmmm, why don't you make the application itself a service. Other choice would be as you have suggested, Changing the application into a Window app and call it using ShellExecute(); with SW_HIDE flag Regards Alfadhly

        H Offline
        H Offline
        hjelms ejournal no
        wrote on last edited by
        #3

        Hi, Thanks for your reply! First of all; the reason I don't want to have the program itself as a service is simply that I fear memory leaks and other events that may a) Make the service eat all memory. b) Core, burn and die. Consequently, the second idea seems much more interesting. Sorry for being a newbie (unix is my preferable domain), but what are the minimum requirements for a Window app? Just a winmain() procedure, or is there something more to it (given that I do not want to handle any messages, draw anything, etc). All the program is going to do is quickly fetch some emails and store them in a database. I.e. a straightforward background job. Sincerely, Sverre Hjelm

        L G 2 Replies Last reply
        0
        • H hjelms ejournal no

          Hi, Thanks for your reply! First of all; the reason I don't want to have the program itself as a service is simply that I fear memory leaks and other events that may a) Make the service eat all memory. b) Core, burn and die. Consequently, the second idea seems much more interesting. Sorry for being a newbie (unix is my preferable domain), but what are the minimum requirements for a Window app? Just a winmain() procedure, or is there something more to it (given that I do not want to handle any messages, draw anything, etc). All the program is going to do is quickly fetch some emails and store them in a database. I.e. a straightforward background job. Sincerely, Sverre Hjelm

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well, I am not an expert in windows enough to be able to explain all of the message pumb . But here is a simple prgram that should give you a head start on how the windows message dispatch work This sample is a very simple sample , (as you can see) However, it should be able to open the code project site using your favorites browser. To build it simply create a new empty win32 Application and add a cpp file with the code below. compile and run I hope it will help Regards Alfadhly [CODE] // the windows header #include <windows.h> //include ShellExecuteA #include "shellapi.h" //link in the library #pragma comment(lib,"shell32.lib") WNDCLASS clsWnd; // declare a generic window class HWND hwndHandle; // handle to the window to be created MSG msgWindow; // just a message handler // prototype of the function that will handle the window messages long _stdcall WndProc (HWND,UINT,WPARAM,LPARAM); // the program entry point winMain int _stdcall WinMain(HINSTANCE instance,HINSTANCE j,char *k,int l) { clsWnd.lpszClassName = "THE_WINDOW_CLASS"; clsWnd.hInstance = instance; clsWnd.lpfnWndProc = WndProc; // register our new window class RegisterClass(&clsWnd); // now creat a window hwndHandle = CreateWindow ( // see MSDN "THE_WINDOW_CLASS", "Title", 0,0,0,0,0,0,0,instance,0 ); ShowWindow(hwndHandle,3); while ( GetMessage(&msgWindow,0,0,0) ) DispatchMessage(&msgWindow); return 1; } long _stdcall WndProc (HWND w,UINT x,WPARAM y,LPARAM z) { if ( x == WM_CREATE) { // as soon as the window is created // do some stuff // shell execute can alos be used to open URL // yoo hooooo // so let open my favorite web site ShellExecute(NULL, "open", "http://www.codeproject.com/", "", NULL, SW_SHOWNORMAL ); // lets tell the program we have changed our mind PostQuitMessage(0); } // oh well just in case if ( x == WM_DESTROY) PostQuitMessage(0); return DefWindowProc(w,x,y,z); } [/CODE]

          1 Reply Last reply
          0
          • H hjelms ejournal no

            Hi, Thanks for your reply! First of all; the reason I don't want to have the program itself as a service is simply that I fear memory leaks and other events that may a) Make the service eat all memory. b) Core, burn and die. Consequently, the second idea seems much more interesting. Sorry for being a newbie (unix is my preferable domain), but what are the minimum requirements for a Window app? Just a winmain() procedure, or is there something more to it (given that I do not want to handle any messages, draw anything, etc). All the program is going to do is quickly fetch some emails and store them in a database. I.e. a straightforward background job. Sincerely, Sverre Hjelm

            G Offline
            G Offline
            GBO
            wrote on last edited by
            #5

            Hi, I suggest you create a Win32 windowless application. You do not need to change anything in your existing Console Application (except getting rid of the console App). Here comes a bulk of code. Try to understand it. This mechanism will create a message loop for your application so it can respond to WM_CLOSE and WM_QUIT and WM_QUERYENDSESSION (Windows Exit or Log off) messages. It creates a Console in Debug Mode so you can print some debug messages to this console but there is no window in release. It is not hidden, it is never created hence you do not use the resources. In debug mode ctrl-C and ctrl-break can be caught. (sounds familiar to a Unix-dude doesn't it?) WaitUntillKeyPressed is a function that will enable you to see the debug output in the console when the App has done its work. (can be handy) Win32 Apps do not have a "int main(argc, argv)" form entry function but a "WinMain" entry function. #include #include DWORD dwMainThread = 0; // pseudo code for the worker thread object // give it Start() and Stop() functions // WorkerThreadObject* p_YourThreadObject = NULL; static __int32 ConsoleHandler(DWORD fdwCtrlType) { switch(fdwCtrlType) { case CTRL_C_EVENT: case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_BREAK_EVENT: { UINT Msg = WM_QUIT; // message to post WPARAM wParam = NULL; // first message parameter LPARAM lParam = NULL;// second message parameter BOOL Answer = PostThreadMessage( dwMainThread, // thread identifier Msg, // message to post wParam, // first message parameter lParam // second message parameter ); _ASSERT(Answer == TRUE); return TRUE; } default: { return FALSE; } } } static void WaitUntillKeyPressed(void) { HANDLE hConsoleInput = GetStdHandle( STD_INPUT_HANDLE ); INPUT_RECORD Buffer; DWORD NumberOfEventsRead = 0; while ( ReadConsoleInput( hConsoleInput, // handle of a console input buffer &Buffer, // address of the buffer for read data 1, // number of records to read &NumberOfEventsRead // address of number of records read ) ) { if (Buffer.EventType == KEY_EVENT && Buffer.Event.KeyEvent.bKeyDown == TRUE) { break; } } } int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #ifdef _DEBUG BOOL Answer = AllocConsole(); _ASSERT(Answer == TRUE); if (! SetConsoleCtrlH

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups