摘要:
调用exe 有诸如 ShellExecute(Ex) , System 之类的函数,本文以ShellExecuteEx为例子,调用exe,并等待其结束。 charActiveCmd[200]={0};sprintf(ActiveCmd,"%s%s",argv[1],argv[2]);printf("%s\n",ActiveCmd); /** 转换char * ---> TCHAR **/ intactcnt=MultiByteToWideChar(CP_ACP,NULL,ActiveCmd,-1,NULL,0);TCHAR*pbuffer=newT 阅读全文
摘要:
voidUTIL_CountFileSize(constchar*dir,long&fsize){#ifndefWIN32DIR*dp;structdirent*entry;structstatstatbuf;if((dp=opendir(dir))==NULL){fprintf(stderr,"cannotopendirctory:%s\n",dir);return;}chdir(dir);//注意这里改变了工作路径while((entry=readdir(dp))!=NULL){lstat(entry->d_name,&statbuf);if(S_ 阅读全文
摘要:
#ifdefUNICODEtypedefwchar_tTCHAR;#elsetypedefunsignedcharTCHAR;#endiftypedefunsignedcharCHAR;typedefunsignedwchar_tWCHAR; 因此,TCHAR 在 UNICODE 下为 sizeof(TCHAR) = 2 字节 ,否则 sizeof(TCHAR)= 1 字节 (8位). /***char*-->TCHAR***/charszFind[MAX_PATH];intactcnt=MultiByteToWideChar(CP_ACP,NULL,szFind,-1,NULL,0); 阅读全文
摘要:
<Unix Network Programming>有介绍三种方法:1 定义特定的分隔符隔开消息。每次读到时候,读到分隔符位置。分隔符采用消息中不会出现的字符,如 <CRLF> 2 定义特定的结构体,定义 消息类型、消息长度、消息内容 做为一结构体传输。如下:typedefstruct{MessageTypeMt;//Enum类型longmessage_size;//消息长度charmessage[MAX_LEN];//消息的真正内容}MessageIPC;3 每次传输,建立一次连接,通讯完毕关闭连接。书中举例: http 1.0 阅读全文
摘要:
if(mkfifo(SERVER_FIFO_NAME,0666)==-1){fprintf(stderr,"Sorry,createserverfifofailure!\n");exit(EXIT_FAILURE);}server_fifo_fd=open(SERVER_FIFO_NAME,O_RDONLY);if(server_fifo_fd==-1){fprintf(stderr,"Sorry,serverfifoopenfailur... 阅读全文
摘要:
typedefenmu{OT_UNKNOW=-1,OT_ADD=0}OTType;typedefstruct{pid_tpid;OTTypeOT;}MessageClient;typedefstruct{MessageClientMC;charResourceID[ID_SIZE];//ID_SIZE=49intresult;}ResultInfo;sizeof(ResultInfo) = 64 =8 +49+4+3(padding)MC 放于前面1-8个字节,ResourceID排在9-57个字节 , result 排在58-61, 62-64 是padding... 阅读全文
摘要:
被问及以下问题:#include<iostream>usingnamespacestd;voidfunc(int*&a,intb){for(inti=0;i<b;i++)a[i]+=i;}intmain(){inttest[10]={1,2,3,4,5,6,7,8,9,7};func(test,4);cout<<"Afterassignment,testis"<<endl;...}error: invalid initialization of non-const reference of type ‘int*&’ 阅读全文
摘要:
int i=3;int *a = &i;//这里a是一个指针,它指向变量iint &b = i;//这里b是一个引用,它是变量i的引用。 可以理解为 b is now " in the name of" i 。i 有一绰号 bint * &c = a;//这里c是一个引用,它是指针a的引用int & *d;//这里d是一个指针,它指向引用。看编译的错误就知道(a pointer to ‘int&’),.但引用不是实体,所以这是错误的,报错:error: cannot declare pointer to ‘int&’int * 阅读全文
摘要:
表 1. 线程函数列表对象操作Linux Pthread APIWindows SDK 库对应 API线程创建pthread_createCreateThread退出pthread_exitThreadExit等待pthread_joinWaitForSingleObject互斥锁创建pthread_mutex_initCreateMutex销毁pthread_mutex_destroyCloseHandle加锁pthread_mutex_lockWaitForSingleObject解锁pthread_mutex_unlockReleaseMutex条件创建pthread_cond_init 阅读全文
摘要:
I wanted to download a file from Internet while I find the wget may stuck when the network is not good enough ."wget" command accepts -T / --timeout , however, it doesn't work right as I tried . So I create a thread to handle this job , using pthread_cond_timedwait . the following prog 阅读全文