控制台程序Ctrl +C 退出
[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool AllocConsole();
[DllImport("kernel32.dll",SetLastError=true)]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool FreeConsole();
// Delegate type to be used as the Handler Routine for SCCH
delegate bool ConsoleCtrlDelegate(CtrlTypes CtrlType);
// Enumerated type for the control messages sent to the handler routine
enum CtrlTypes: uint
{
CTRL_C_EVENT=0,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT=5,
CTRL_SHUTDOWN_EVENT
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
private static bool ctrlHandler(CtrlTypes CtrlType)
{
if ((CtrlType == CtrlTypes.CTRL_C_EVENT) || (CtrlType == CtrlTypes.CTRL_BREAK_EVENT))
{
FreeConsole();
return true;
}
if (CtrlType == CtrlTypes.CTRL_CLOSE_EVENT)
return true;
return false;
}
相关文档:
在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条。
(1)先来介绍它的第一条也是最重要的一条:隐藏。
当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性。为理解这句话,我举例来说明。我们要同时编译两个源文件,一个是a.c,另一个是main.c。
下面是a.c的内容
ch ......
网马加密中,目前有个function(p,a,c,k,e,d)的,非常讨厌,我也是深恶痛绝,记得我刚开始碰到它的时候,拼命地读函数,那个叫痛苦啊,磕磕绊绊地勉强搞了出来。今天,突然看见了function(p,a,c,k,e,d)的解密代码,高兴都来不及
<script>
a=62;
function encode() {
var code = document.getElementById('code' ......
我们都知道gcc的-S开关可以用来生成汇编代码,
但有时候,单有汇编文件是不够的,我们希望的是将C语言程序的源代码和汇编语言文本交错在一起查看,
这是LISTING功能,在gcc中并没有专门的FAQ说明,
区区在网上查了很多资料才知道怎么实现,所以特此记下。
gcc -c -g -Wa,-adlhn ee.c > ee.anno.s
由此生成的e ......
static char *file2memory(FILE *file, long *size)
{
char buffer[1024];
char *string=NULL;
char *newstring=NULL;
long len=0;
long stringlen=0;
if(file) {
while((len = fread(buffer, 1, sizeof(buffer), f ......
突然发现自己连一元二次方程怎么算的都不知道了。想了半天,拿起笔来才顺手些了给x2+2x+1=0.悔恨啊。
#include "iostream"
#include "cmath"
using namespace std;
int main(){
double a,b,c;
double delta,x1,x2;
int sign,stop;
cout<<"输入3个系数a(a!=0),b,c"<<endl;
cin>>a>>b& ......