这是自由拼音的一个注册程序, c写的.<br><br>#include &lt;windows.h><br>#include &lt;tchar.h><br>#include &lt;stdio.h><br><br>#define CONVERSION_SET 0x6101<br>#define LAYOUTTEXT _T("自由拼音输入法")<br>#define LAYOUTFILE _T("kbdus.kbd")<br>#define LAYOUTFILENT _T("kbdus.dll")<br>#define IMEFILE _T("freepy.ime")<br><br>#define MAX_SIZE 200<br>#define MAX_SUBKEY 250<br><br>void main()<br>{<br> HKEY hKey,hChildKey;<br> DWORD dwIndex;<br> DWORD dwName,dwMaxName = 0;<br> TCHAR szNameArr[MAX_SUBKEY][MAX_SIZE],szName[MAX_SIZE];<br> DWORD dwLen;<br> TCHAR szLayoutText[MAX_SIZE];<br> DWORD dwData;<br> FILETIME ft;<br> LONG lRet;<br> TCHAR szRegName[MAX_SIZE];<br> DWORD dwDisposition;<br> DWORD dwConversionSet;<br> WORD wCount = 0;<br> int i;<br> OSVERSIONINFO osVerInfo;<br><br> dwIndex = 0;<br> dwLen = MAX_SIZE;<br> dwData = MAX_SIZE * sizeof(TCHAR);<br> dwConversionSet = CONVERSION_SET;<br><br> if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,<br> _T("Software"),<br> 0,<br> KEY_READ,<br> &hKey) != ERROR_SUCCESS ){<br> _ftprintf(stderr,_T("Software open error/n"));<br> exit(1);<br> }<br><br> if( RegCreateKeyEx( hKey,<br> _T("freepy"),<br> 0,<br> NULL,<br> REG_OPTION_NON_VOLATILE ,<br> KEY_ALL_ACCESS ,<br> NULL,<br> &hChildKey,<br> &dwDisposition ) != ERROR_SUCCESS) {<br> RegCloseKey(hKey);<br> _ftprintf(stderr,_T("freepy create error/n"));<br> exit(1);<br> }<br><br> RegSetValueEx(hChildKey,<br> _T("ConversionSet"),<br> 0,<br> REG_DWORD,<br> (LPBYTE)&dwConversionSet,<br> sizeof(DWORD));<br><br> RegCloseKey(hChildKey);<br> RegCloseKey(hKey);<br><br> if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,<br> _T("System//CurrentControlSet//Control//Keyboard Layouts"),<br> 0,<br> KEY_READ,<br> &hKey) != ERROR_SUCCESS ){<br> _ftprintf(stderr,_T("Keyboard Layouts open error/n"));<br> exit(1);<br> }<br><br> RegQueryInfoKey (hKey,NULL, NULL,NULL,<br> &dwIndex,<br> NULL,NULL,NULL, NULL,NULL,NULL, NULL);<br><br> while( (int)dwIndex >= 0 ) {<br> dwLen = MAX_SIZE;<br> if((lRet = RegEnumKeyEx(hKey,<br> dwIndex,<br> szName,<br> &dwLen,<br> NULL,<br> NULL,<br> NULL,<br> &ft)) == ERROR_SUCCESS || lRet == ERROR_MORE_DATA ) {<br> _tcscpy(szNameArr[wCount++],szName);<br> }<br> dwIndex--;<br> }<br><br> for(i=0;i<wCount;i++) {<br> if ( RegOpenKeyEx(hKey,<br> szNameArr
,<br> 0,<br> KEY_ALL_ACCESS ,<br> &hChildKey) == ERROR_SUCCESS ){<br> if( RegQueryValueEx( hChildKey,<br> _T("layout text"),<br> NULL,<br> NULL,<br> (LPBYTE)szLayoutText,<br> &dwData) == ERROR_SUCCESS ){<br> if(!_tcsicmp(szLayoutText,LAYOUTTEXT)) {<br> goto my_next;<br> }<br> _stscanf(szNameArr,_T("%lx"),&dwName);<br> if( dwMaxName &lt; dwName ) dwMaxName = dwName;<br> }<br> RegCloseKey(hChildKey);<br> }<br> }<br><br> _stprintf(szRegName,"%lx",dwMaxName + 0x10000);<br> CharUpper(szRegName);<br><br> if( RegCreateKeyEx( hKey,<br> szRegName,<br> 0,<br> NULL,<br> REG_OPTION_NON_VOLATILE ,<br> KEY_ALL_ACCESS ,<br> NULL,<br> &hChildKey,<br> &dwDisposition ) != ERROR_SUCCESS) {<br> RegCloseKey(hKey);<br> _ftprintf(stderr,_T("%s create error/n"),szRegName);<br> exit(1);<br> }<br><br>my_next:<br> RegSetValueEx(hChildKey,<br> _T("IME file"),<br> 0,<br> REG_SZ,<br> (LPBYTE)IMEFILE,<br> _tcslen(IMEFILE)*sizeof(TCHAR));<br><br> osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br> if(GetVersionEx(&osVerInfo)) {<br> RegSetValueEx(hChildKey,<br> _T("layout file"),<br> 0,<br> REG_SZ,<br> (osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ?<br> ((LPBYTE)LAYOUTFILENT)(LPBYTE)LAYOUTFILE),<br> _tcslen(LAYOUTFILENT)*sizeof(TCHAR));<br> }<br> else {<br> _ftprintf(stdout,_T("get version error/n"));<br> RegSetValueEx(hChildKey,<br> _T("layout file"),<br> 0,<br> REG_SZ,<br> (LPBYTE)LAYOUTFILE,<br> _tcslen(LAYOUTFILE)*sizeof(TCHAR));<br> }<br><br> RegSetValueEx(hChildKey,<br> _T("layout text"),<br> 0,<br> REG_SZ,<br> (LPBYTE)LAYOUTTEXT,<br> _tcslen(LAYOUTTEXT)*sizeof(TCHAR));<br><br> RegCloseKey(hChildKey);<br> RegCloseKey(hKey);<br><br> _ftprintf(stdout,_T("ok/n"));<br> return;<br>}<br>