分类: C/C++
2008-08-01 16:56:53
unsigned char buffer[255]={0}; unsigned long length; unsigned long type; HKEY hKey; RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\dm",&hKey); RegQueryValueEx(hKey,"Num",NULL,&type,buffer,&length); RegCloseKey(hKey); int Count; Count = atoi((const char*)buffer); if(Count == 0) { RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\dm",&hKey); RegSetValueEx(hKey,"Num",0,REG_SZ,(const unsigned char *)"5",strlen("5")); RegCloseKey(hKey); MessageBox(NULL,"最后用5次!","Hello",MB_OK); } else if(Count == 1) { MessageBox(NULL,"请注册!","Hello",MB_OK); return true; } else { char buf[255]={0}; Count -= 1; itoa(Count,buf,10); CString str; str.Format ("最后用%d次!",Count); MessageBox(NULL,str,"Hello",MB_OK); RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\dm",&hKey); RegSetValueEx(hKey,"Num",0,REG_SZ,(const unsigned char*)buf,strlen(buf)); RegCloseKey(hKey); }这时它就具有了使用次数的限制。其中程序中的5是准备让用户使用的次数,它可被你任意修改。大家可以看出来,程序其实就是在读写注册表,利用这种思路也可以作成读写文件,甚至是加密狗。总之没什么高深的,祝各位编程快乐!(Win2k vc6.0下通过) 下载本文示例代码