我写了一个服务程序,想在服务程序在服务管理器中运行的时候可以自己弹出来一个CMD窗体,在上面显示日志信息。但是我怎么用
AllocConsole函数不对呀。用这个函数返回是TRUE,但是就是不弹出CMD窗体。这到底是为什么???注:我是想在Release下弹出窗口,Debug下是自带的,而且我在Debug下自己弹出窗口实现了.
AllocConsole函数不对呀。用这个函数返回是TRUE,但是就是不弹出CMD窗体。这到底是为什么???注:我是想在Release下弹出窗口,Debug下是自带的,而且我在Debug下自己弹出窗口实现了.
scHOutPut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(scHOutPut,"hello\n",6,NULL,NULL);
AllocConsole();
scHOutPut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(scHOutPut,"hello\n",6,NULL,NULL);
A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, and then it can call AllocConsole to create a new console. If the calling process creates a child process, the child inherits the new console. 第一句话就让你死心了。
但是,如果你是Debug运行的话,确实有一个Cmd窗体弹出来,这是调试环境自己弹出来的。我用FreeConsole可以将这个窗体杀掉,再自己创建一个。
可是,如果在Release条件下运行,那么不会自己弹出来一个CMD窗体,另外我试过使用FreeConsole和不用FreeConsole都不会再弹出来一个CMD窗体。
我是在想,当这个程序在服务程序管理器中被激活后,也可以弹出来一个CMD窗体,想调试的时候可以直接实时的显示日志信息