锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
To set all the bytes in a block of memory to a particular value, use memset(). The function prototype is
void * memset(void *dest, int c, size_t count);
The argument dest points to the block of memory. c is the value to set, and count is the number of bytes, starting at dest, to be set. Note that while c is a type int, it is treated as a type char. In other words, only the low-order byte is used, and you can specify values of c only in the range 0 through 255.
Use memset() to initialize a block of memory to a specified value. Because this function can use only a type char as the initialization value, it is not useful for working with blocks of data types other than type char, except when you want to initialize to 0. In other words, it wouldn't be efficient to use memset() to initialize an array of type int to the value 99, but you could initialize all array elements to the value 0. memset() will be demonstrated in program below.
memcpy() copies bytes of data between memory blocks, sometimes called buffers. This function doesn't care about the type of data being copied--it simply makes an exact byte-for-byte copy. The function prototype is
void *memcpy(void *dest, void *src, size_t count);
The arguments dest and src point to the destination and source memory blocks, respectively. count specifies the number of bytes to be copied. The return value is dest. If the two blocks of memory overlap, the function might not operate properly--some of the data in src might be overwritten before being copied. Use the memmove() function, discussed next, to handle overlapping memory blocks. memcpy() will be demonstrated in program below.
memmove() is very much like memcpy(), copying a specified number of bytes from one memory block to another. It's more flexible, however, because it can handle overlapping memory blocks properly. Because memmove() can do everything memcpy() can do with the added flexibility of dealing with overlapping blocks, you rarely, if ever, should have a reason to use memcpy(). The prototype is
void *memmove(void *dest, void *src, size_t count);
dest and src point to the destination and source memory blocks, and count specifies the number of bytes to be copied. The return value is dest. If the blocks overlap, this function ensures that the source data in the overlapped region is copied before being overwritten. Sample program below demonstrates memset(), memcpy(), and memmove().
1: /* Demonstrating memset(), memcpy(), and memmove(). */ 2: 3: #include <stdio.h> 4: #include <string.h> 4: 5: char message1[60] = "Four score and seven years ago ..."; 6: char message2[60] = "abcdefghijklmnopqrstuvwxyz"; 7: char temp[60]; 8: 9: main() 10: { 11: printf("\nmessage1[] before memset():\t%s", message1); 12: memset(message1 + 5, `@', 10); 13: printf("\nmessage1[] after memset():\t%s", message1); 14: 15: strcpy(temp, message2); 16: printf("\n\nOriginal message: %s", temp); 17: memcpy(temp + 4, temp + 16, 10); 18: printf("\nAfter memcpy() without overlap:\t%s", temp); 19: strcpy(temp, message2); 20: memcpy(temp + 6, temp + 4, 10); 21: printf("\nAfter memcpy() with overlap:\t%s", temp); 22: 23: strcpy(temp, message2); 24: printf("\n\nOriginal message: %s", temp); 25: memmove(temp + 4, temp + 16, 10); 26: printf("\nAfter memmove() without overlap:\t%s", temp); 27: strcpy(temp, message2); 28: memmove(temp + 6, temp + 4, 10); 29: printf("\nAfter memmove() with overlap:\t%s\n", temp); 30: 31: } message1[] before memset(): Four score and seven years ago ... message1[] after memset(): Four @@@@@@@@@@seven years ago ... Original message: abcdefghijklmnopqrstuvwxyz After memcpy() without overlap: abcdqrstuvwxyzopqrstuvwxyz After memcpy() with overlap: abcdefefefefefefqrstuvwxyz Original message: abcdefghijklmnopqrstuvwxyz After memmove() without overlap: abcdqrstuvwxyzopqrstuvwxyz After memmove() with overlap: abcdefefghijklmnqrstuvwxyz
ANALYSIS: The operation of memset() is straightforward. Note how the pointer notation message1 + 5 is used to specify that memset() is to start setting characters at the sixth character in message1[] (remember, arrays are zero-based). As a result, the 6th through 15th characters in message1[] have been changed to @.
When source and destination do not overlap, memcpy() works fine. The 10 characters of temp[] starting at position 17 (the letters q through z) have been copied to positions 5 though 14, where the letters e though n were originally located. If, however, the source and destination overlap, things are different. When the function tries to copy 10 characters starting at position 4 to position 6, an overlap of 8 positions occurs. You might expect the letters e through n to be copied over the letters g through p. Instead, the letters e and f are repeated five times.
If there's no overlap, memmove() works just like memcpy(). With overlap, however, memmove() copies the original source characters to the destination.
2.pow(2,10) 瑕佹敼鎴?nbsp; pow((double)2,10)鎴杙ow(2.0,10)
璇存槑錛?.0涓敤鍒癿ath.h pow()鍑芥暩鏅傦紝鏈夐欏嬪師鍨?double pow(int _X,int _Y) 浣嗗鏋滅敤VC++ 2005鐨勮┍錛宲ow()鐨勭涓鍊嬪弮鏁稿氨涓嶈兘鍐嶄嬌鐢╥nt鍨嬫厠錛屽彧鑳戒嬌鐢╢loat銆乨ouble銆乴ong double錛孷C++ 2005鍦ㄧ法璀檪鏈冨仛type checking錛岀劧寰屽氨閬庝笉浜嗭紝鎶rror C2668
3.Itoa鏂規硶鍚嶈鏀規垚 _Itoa_s
4.error C2440錛?#8220;static_cast” 鏃犳硶浠?#8220;void (__thiscall CChatManagerDlg::* )(WPARAM,LPARAM)”杞崲涓?#8220;LRESULT (__thiscall CWnd::* )錛屽嚭閿欏鍦∣N_MESSAGE(WM_SETPLAY,OnSetPlay)
瑙g瓟錛氬皢void CVideoBaseView::OnSetPlay(WPARAM wp,LPARAM lp) 鏀規垚LRESULT CVideoBaseView::OnSetPlay(WPARAM wp,LPARAM lp){
LRESULT result = Default();
//浣犲師鏉ョ殑浠g爜
return result;}
5.鎵句笉鍒癕FC80D.DLL
瑙e喅錛?#8220;宸ョ▼灞炴?#8221;->“link”->“manifesto file”->“$(IntDir)\$(TargetFileName).intermediate.manifest” 鍊?nbsp; 鏀規垚 $(IntDir)\$(TargetFileName).manifest
鏂囩珷鍑哄錛氶璇虹綉(www.firnow.com):http://dev.firnow.com/course/3_program/vc/vc_js/200879/132413.html
view plaincopy to clipboardprint?
LRESULT CPreventShutdownDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_QUERYENDSESSION == message)
{
AfxMessageBox(_T("鍛靛懙錛屼笉璁稿叧鏈猴紒"));
return FALSE; // 鏍規嵁MSDN錛學M_QUERYENDSESSION 榪斿洖FALSE鍒欏彇娑堝叧鏈?nbsp;
}
return CDialog::WindowProc(message, wParam, lParam);
}
LRESULT CPreventShutdownDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_QUERYENDSESSION == message)
{
AfxMessageBox(_T("鍛靛懙錛屼笉璁稿叧鏈猴紒"));
return FALSE; // 鏍規嵁MSDN錛學M_QUERYENDSESSION 榪斿洖FALSE鍒欏彇娑堝叧鏈?br> }
return CDialog::WindowProc(message, wParam, lParam);
}
鏄粈涔堝師鍥犲湪鏌愪簺鏈哄櫒涓婃棤娉曢樆姝㈠叧鏈哄憿錛?/p>
鍥炲繂鍏蟲満鏃剁粡甯擱亣鍒扮殑鍦烘櫙錛?/p>
1. 濡傛灉鏌愪釜榪涚▼澶卞幓鍝嶅簲錛屽叧鏈虹殑鏃跺欎細鎻愮ず"...娌℃湁鍝嶅簲錛屾槸鍚︾粨鏉?
2. 浣跨敤璁頒簨鏈慨鏀逛簡鏂囨。錛屽湪娌℃湁淇濆瓨鐨勬儏鍐典笅榪涜鍏蟲満錛屾櫘閫氭儏鍐典細鎻愮ず鏄惁榪涜淇濆瓨銆?/p>
1榪欑鎯呭喌涓嶅ソ妯℃嫙錛屼絾鏄?鏄緢濂芥ā鎷熺殑銆備簬鏄湪涓嶈兘闃繪鍏蟲満鐨勬満鍣ㄤ笂榪欐牱榪涜嫻嬭瘯錛屽彂鐜拌櫧鐒朵篃寮瑰嚭浜嗘槸鍚︿繚瀛樼殑瀵硅瘽妗嗭紝浣嗘槸榪樻槸椹笂灝卞叧鏈轟簡銆?/p>
鏋滅劧錛屽拰紼嬪簭鏃犲叧錛屽簲璇ユ槸鏈哄櫒璁劇疆鐨勯棶棰樸備簬鏄兂鍒頒簡涓涓緢嫻佽鐨勮瘝錛?蹇熷叧鏈?
鍒扮綉涓奼oogle浜嗕竴涓嬶紝鍙戠幇蹇熷叧鏈烘槸閫氳繃濡備笅鐨勬柟寮忓疄鐜扮殑錛?/p>
HKEY-CURRENT-USER\Control Panel\Desktop\AutoEndTasks 鍊間負1琛ㄧず蹇熷叧鏈?/p>
鏅氭儏鍐靛間負0鎴栬繖涓敭鍊間笉瀛樺湪
鍒頒笉鑳介樆姝㈠揩閫熷叧鏈虹殑鏈哄櫒涓婁竴鐪嬶紝鏋滅劧榪欎釜閿間負1.
鏀逛負0鍚庡啀榪愯紼嬪簭錛屽氨閮借兘闃繪鍏蟲満浜嗐?/p>
銆愮粨璁恒戦樆姝㈠叧鏈洪渶瑕佷袱姝ユ墠鑳藉畬緹庣殑瀹炵幇錛岃屼笉浠呬粎鏄疢SDN涓弿榪扮殑2)
1) 鍦ㄧ▼搴忎腑鍏堝垹闄よ繖涓敭鍊?HKEY-CURRENT-USER\Control Panel\Desktop\AutoEndTasks)
2) 澶勭悊 WM_QUERYENDSESSION 鏃惰繑鍥濬ALSE
鏈枃鏉ヨ嚜CSDN鍗氬錛岃漿杞借鏍囨槑鍑哄錛?a >http://blog.csdn.net/skyxie/archive/2009/06/09/4255767.aspx
閭e浣曡幏鍙栬繖涓獥鍙g殑鍙ユ焺鍛紵寰堣嚜鐒舵垜浠彲浠ユ兂鍒拌繖涔堜竴涓嚱鏁幫紝鍑芥暟褰㈠紡濡備笅錛?/p>
HWND FindWindowEx(
HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow
);
hwndParent錛氭寚鍚戜竴涓緟鎼滅儲紿楀彛鐨勭埗紿椼?/p>
hwndChildAfter錛氬瓙紿楀彛鐨勫彞鏌勩?/p>
lpszClass錛氱獥鍙g殑綾誨悕銆?/p>
lpszWindow錛氱獥鍙g殑鏍囬鍚嶃?/p>
渚嬪錛屾湰紺轟緥宸ョ▼瑕佹壘鍒頒竴涓璇濇閲岀殑緙栬緫妗嗭紝騫跺榪欎釜緙栬緫妗嗚繘琛屾敞鍏ャ傛煡鎵捐繃紼嬪涓嬶細
HWND hWndChild = NULL;
while(1)
{
// 鏌ユ壘瀵硅瘽妗嗙獥鍙o紝涓旇繖涓璇濇紿楀彛鐨勬爣棰樺悕涓?#8220;TestDlg”
HWND hDlg = FindWindowEx(0, NULL, "#32770", "TestDlg");
if(hDlg == NULL)
{
printf("娌℃湁鎵懼埌璇ュ璇濇紿楀彛!\n");
exit(1);
}
else
{
// 鏌ユ壘榪欎釜瀵硅瘽妗嗙獥鍙d腑鐨別dit鎺т歡
hWndChild = FindWindowEx(hDlg, NULL, "Edit",NULL);
if(hWndChild != NULL)
{
break; // 鎵懼埌榪欎釜緙栬緫妗嗭紝鐜板湪瑕佸榪欎釜緙栬緫妗嗚繘琛屾敞鍏?
}
}
}
// 鏍規嵁鏌ユ壘鍑虹殑紿楀彛錛屾煡璇㈣繘紼?
DWORD dwQQGameId;
HANDLE hProcessQQGame;
if(!GetWindowThreadProcessId(hWndChild,&dwQQGameId))
{
printf("Error in GetWindowThreadProcessId():%d\n",GetLastError());
exit(1);
}
鎵懼埌榪欎釜榪涚▼鍚庯紝鐒跺悗灝辮瀵硅繖涓繘紼嬭繘琛屾敞鍏ャ備絾鏄紝浣犲埆蹇樿浜嗭紝褰撲綘鍦ㄥ叾浠栬繘紼嬩腑鑾峰彇鍙﹀榪涚▼鐨勭獥鍙e彞鏌勶紝浣犳槸娌℃湁鍔炴硶鎿嶄綔榪欎釜鍙ユ焺鐨勩備負浠涔堝憿錛熸瘡涓繘紼嬮兘琚祴浜堝畠鑷繁鐨勮櫄鎷熷湴鍧絀洪棿銆傚浜? 2浣嶈繘紼嬫潵璇達紝榪欎釜鍦板潃絀洪棿鏄? G B錛屽洜
涓? 2浣嶆寚閽堝彲浠ユ嫢鏈変粠0 x 0 0 0 0 0 0 0 0鑷? x F F F F F F F F涔嬮棿鐨勪換浣曚竴涓箋傝繖浣垮緱涓涓寚閽堣兘澶熸嫢鏈? 294 967 296涓間腑鐨勪竴涓鹼紝瀹冭鐩栦簡涓涓繘紼嬬殑4 G B铏氭嫙絀洪棿鐨勮寖鍥淬傚浜? 4浣嶈繘紼嬫潵璇達紝榪欎釜鍦板潃絀洪棿鏄? 6 E B錛? 01 8瀛楄妭錛夛紝鍥犱負6 4浣嶆寚閽堝彲浠ユ嫢鏈変粠0 x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0鑷? x F F F F F F F F F F F F F F F F涔嬮棿鐨勪換浣曞箋傝繖浣垮緱涓涓寚閽堝彲浠ユ嫢鏈?8 446 744 073 709 551 616涓間腑鐨勪竴涓鹼紝瀹冭鐩栦簡涓涓繘紼嬬殑1 6 E B铏氭嫙絀洪棿鐨勮寖鍥淬傝繖鏄浉褰撳ぇ鐨勪竴涓寖鍥淬傜敱浜庢瘡涓繘紼嬪彲浠ユ帴鏀跺畠鑷繁鐨勭鏈夌殑鍦板潃絀洪棿錛屽洜姝ゅ綋榪涚▼涓殑涓涓嚎紼嬫鍦ㄨ繍琛屾椂錛岃綰跨▼鍙互璁塊棶鍙睘浜庡畠鐨勮繘紼嬬殑鍐呭瓨銆傚睘浜庢墍鏈夊叾浠栬繘紼嬬殑鍐呭瓨鍒欓殣钘忕潃錛屽茍涓斾笉鑳借姝e湪榪愯鐨勭嚎紼嬭闂傛敞鎰忓湪Windows 2000涓紝灞炰簬鎿嶄綔緋葷粺鏈韓鐨勫唴瀛樹篃鏄殣钘忕殑錛屾鍦ㄨ繍琛岀殑綰跨▼鏃犳硶璁塊棶銆傝繖鎰忓懗鐫綰跨▼甯稿父涓嶈兘璁塊棶鎿嶄綔緋葷粺鐨勬暟鎹俉indows 98涓紝灞炰簬鎿嶄綔緋葷粺鐨勫唴瀛樻槸涓嶉殣钘忕殑錛屾鍦ㄨ繍琛岀殑綰跨▼鍙互璁塊棶銆傚洜姝わ紝姝e湪榪愯鐨勭嚎紼嬪父甯稿彲浠ヨ闂搷浣滅郴緇熺殑鏁版嵁錛屼篃鍙互鐮村潖鎿嶄綔緋葷粺錛堜粠鑰屾湁鍙兘瀵艱嚧鎿嶄綔緋葷粺宕╂簝錛夈傚湪Windows 98涓紝涓涓繘紼嬬殑綰跨▼涓嶅彲鑳借闂睘浜庡彟涓涓繘紼嬬殑鍐呭瓨銆傚墠闈㈣榪囷紝姣忎釜榪涚▼鏈夊畠鑷繁鐨勭鏈夊湴鍧絀洪棿銆傝繘紼婣鍙兘鏈変竴涓瓨鏀懼湪瀹冪殑鍦板潃絀洪棿涓殑鏁版嵁緇撴瀯錛屽湴鍧鏄? x 1 2 3 4 5 6 7 8錛岃岃繘紼婤鍒欐湁涓涓畬鍏ㄤ笉鍚岀殑鏁版嵁緇撴瀯瀛樻斁鍦ㄥ畠鐨勫湴鍧絀洪棿涓紝鍦板潃鏄? x 1 2 3 4 5 6 7 8銆傚綋榪涚▼A涓繍琛岀殑綰跨▼璁塊棶鍦板潃涓? x 1 2 3 4 5 6 7 8鐨勫唴瀛樻椂錛岃繖浜涚嚎紼嬭闂殑鏄繘紼婣鐨勬暟鎹粨鏋勩傚綋榪涚▼B涓繍琛岀殑綰跨▼璁塊棶鍦板潃涓? x 1 2 3 4 5 6 7 8鐨勫唴瀛樻椂錛岃繖浜涚嚎紼嬭闂殑鏄繘紼婤鐨勬暟鎹粨鏋勩傝繘紼婣涓繍琛岀殑綰跨▼涓嶈兘璁塊棶榪涚▼B鐨勫湴鍧絀洪棿涓殑鏁版嵁緇撴瀯錛屽弽涔嬩害鐒躲?/p>
榪欐牱鐪嬫潵錛岃嫢鎯沖榪欎釜紿楀彛鍙ユ焺榪涜鎿嶄綔錛屽緱鎯蟲柟璁炬硶浣挎垜浠兘澶熻繘鍏ュ埌鍘熷涓昏繘紼嬩腑錛岀劧鍚庢墽琛屾垜浠殑鎿嶄綔銆傝繖涓氨濂借薄涓涓瘎鐢熻櫕鎯寵鐮村潖浜轟綋鐨勬満鑳斤紝蹇呴』寰楄繘鍏ユ垜浠殑浣撳唴錛屽瘎鐢熷湪鎴戜滑鐨勭粍緇囦笂鎵嶈兘澶熶駭鐢熶綔鐢ㄣ傜幇鍦ㄥ叧閿槸濡備綍瀵勭敓鍒板涓諱腑鍛紵
閫氬父錛屼換浣曡繘紼嬮兘鍙互閫氳繃LoadLibrary鍔ㄦ佸湴鍔犺澆DLL錛屼絾鏄垜浠浣曞己鍒朵竴涓閮ㄨ繘紼嬭皟鐢ㄨ鍑芥暟鍛紵絳旀鏄疌reateRemoteThread銆?br>璁╂垜浠厛鏉ョ湅鐪婰oadLibrary鍜孎reeLibrary鐨勫嚱鏁板0鏄庯細
HINSTANCE LoadLibrary(
LPCTSTR lpLibFileName // address of filename of library module
);
BOOL FreeLibrary(
HMODULE hLibModule // handle to loaded library module
);
鍐嶅拰CreateRemoteThread鐨勭嚎紼嬭繃紼嬶紙thread procedure錛塗hreadProc姣旇緝涓涓嬶細
DWORD WINAPI ThreadProc(
LPVOID lpParameter // thread data
);
浣犱細鍙戠幇鎵鏈夌殑鍑芥暟閮芥湁鍚屾牱鐨勮皟鐢ㄧ害瀹氾紙calling convention錛夈侀兘鎺ュ彈涓涓?2浣嶇殑鍙傛暟騫朵笖榪斿洖鍊肩被鍨嬬殑澶у皬涔熶竴鏍楓備篃灝辨槸璇達紝鎴戜滑鍙互鎶奓oadLibrary/FreeLibrary鐨勬寚閽堜綔涓哄弬鏁頒紶閫掔粰CrateRemoteThread銆?/p>
鐒惰岋紝榪樻湁涓や釜闂錛堝弬鑰冧笅闈㈠CreateRemoteThread鐨勮鏄庯級
1錛?浼犻掔粰ThreadProc鐨刲pStartAddress 鍙傛暟蹇呴』涓鴻繙紼嬭繘紼嬩腑鐨勭嚎紼嬭繃紼嬬殑璧峰鍦板潃銆?br> 2錛?濡傛灉鎶奣hreadProc鐨刲pParameter鍙傛暟褰撳仛涓涓櫘閫氱殑32浣嶆暣鏁幫紙FreeLibrary鎶婂畠褰撳仛HMODULE錛夐偅涔堟病鏈夊浣曢棶棰橈紝浣嗘槸濡傛灉鎶婂畠褰撳仛涓涓寚閽堬紙LoadLibrary鎶婂畠褰撳仛涓涓猚har*錛夛紝瀹冨氨蹇呴』鎸囧悜榪滅▼榪涚▼涓殑鍐呭瓨鏁版嵁銆?/p>
絎竴涓棶棰樺叾瀹炲凡緇忚繋鍒冭岃В浜嗭紝鍥犱負LoadLibrary鍜孎reeLibrary閮芥槸瀛樺湪浜巏ernel32.dll涓殑鍑芥暟錛岃宬ernel32鍙互淇濊瘉浠諱綍“姝e父”榪涚▼涓兘瀛樺湪錛屼笖鍏跺姞杞藉湴鍧閮芥槸涓鏍風殑銆傦紙鍙傜湅闄勫綍A錛変簬鏄疞oadLibrary/FreeLibrary鍦ㄤ換浣曡繘紼嬩腑鐨勫湴鍧閮芥槸涓鏍風殑錛岃繖灝變繚璇佷簡浼犻掔粰榪滅▼榪涚▼鐨勬寚閽堟槸涓湁鏁堢殑鎸囬拡銆?/p>
絎簩涓棶棰樹篃寰堢畝鍗曪細鎶奃LL鐨勬枃浠跺悕錛圠odLibrary鐨勫弬鏁幫級鐢╓riteProcessMemory澶嶅埗鍒拌繙紼嬭繘紼嬨?/p>
鎵浠ワ紝浣跨敤CreateRemoteThread鍜孡oadLibrary鎶鏈殑姝ラ濡備笅錛?br> 1錛?寰楀埌榪滅▼榪涚▼鐨凥ANDLE錛堜嬌鐢∣penProcess錛夈?br> 2錛?鍦ㄨ繙紼嬭繘紼嬩腑涓篋LL鏂囦歡鍚嶅垎閰嶅唴瀛橈紙VirtualAllocEx錛夈?br> 3錛?鎶奃LL鐨勬枃浠跺悕錛堝叏璺緞錛夊啓鍒板垎閰嶇殑鍐呭瓨涓紙WriteProcessMemory錛?br> 4錛?浣跨敤CreateRemoteThread鍜孡oadLibrary鎶婁綘鐨凞LL鏄犲皠榪戣繙紼嬭繘紼嬨?br> 5錛?絳夊緟榪滅▼綰跨▼緇撴潫錛圵aitForSingleObject錛夛紝鍗崇瓑寰匧oadLibrary榪斿洖銆備篃灝辨槸璇村綋鎴戜滑鐨凞llMain錛堟槸浠LL_PROCESS_ATTACH涓哄弬鏁拌皟鐢ㄧ殑錛夎繑鍥炴椂榪滅▼綰跨▼涔熷氨绔嬪嵆緇撴潫浜嗐?br> 6錛?鍙栧洖榪滅▼綰跨▼鐨勭粨鏉熺爜錛圙etExitCodeThtread錛夛紝鍗矻oadLibrary鐨勮繑鍥炲尖曗曟垜浠珼LL鍔犺澆鍚庣殑鍩哄湴鍧錛圚MODULE錛夈?br> 7錛?閲婃斁絎?姝ュ垎閰嶇殑鍐呭瓨錛圴irtualFreeEx錛夈?br> 8錛?鐢–reateRemoteThread鍜孎reeLibrary鎶奃LL浠庤繙紼嬭繘紼嬩腑鍗歌澆銆傝皟鐢ㄦ椂浼犻掔6姝ュ彇寰楃殑HMODULE緇橣reeLibrary錛堥氳繃CreateRemoteThread鐨刲pParameter鍙傛暟錛夈?br> 9錛?絳夊緟綰跨▼鐨勭粨鏉燂紙WaitSingleObject錛夈?/p>
涓昏浠g爜濡備笅錛?/p>
#include<stdio.h>
#include<conio.h>
#include<windows.h>
void main()
{
HWND hWndChild = NULL;
while(1)
{
// 鏌ユ壘瀵硅瘽妗嗙獥鍙o紝涓旇繖涓璇濇紿楀彛鐨勬爣棰樺悕涓?#8220;TestDlg”
HWND hDlg = FindWindowEx(0, NULL, "#32770", "TestDlg");
if(hDlg == NULL)
{
printf("娌℃湁鎵懼埌璇ュ璇濇紿楀彛!\n");
exit(1);
}
else
{
// 鏌ユ壘榪欎釜瀵硅瘽妗嗙獥鍙d腑鐨別dit鎺т歡
hWndChild = FindWindowEx(hDlg, NULL, "Edit",NULL);
if(hWndChild != NULL)
{
break; // 鎵懼埌榪欎釜緙栬緫妗嗭紝鐜板湪瑕佸榪欎釜緙栬緫妗嗚繘琛屾敞鍏?
}
}
}
// 鏍規嵁鏌ユ壘鍑虹殑紿楀彛錛屾煡璇㈣繘紼?
DWORD dwQQGameId;
HANDLE hProcessQQGame;
if(!GetWindowThreadProcessId(hWndChild,&dwQQGameId))
{
printf("Error in GetWindowThreadProcessId():%d\n",GetLastError());
exit(1);
}
HINSTANCE hDll = NULL;
typedef void(*LP_SET_HEDIT_FUN)(HWND);
LP_SET_HEDIT_FUN m_SethEdit = NULL;
char DllPath[MAX_PATH] = "D:\\榪涚▼娉ㄥ叆嫻嬭瘯宸ョ▼\\Bin\\automessagedll.dll";
hDll = LoadLibrary(DllPath);
if(hDll)
{
m_SethEdit = (LP_SET_HEDIT_FUN)GetProcAddress(hDll,"SethEdit");
}
if(m_SethEdit)
{
m_SethEdit(hWndChild);
}
else
{
printf("Can not load SethEdit in the dll(%d).\n",GetLastError());
}
if( (hProcessQQGame = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwQQGameId)) == NULL)
{
printf("Error in OpenProcess():%d\n",GetLastError());
getch();
exit(1);
}
int cb = (1+lstrlen(DllPath))* sizeof(char);
char* RemoteLibFile = (char*)VirtualAllocEx(hProcessQQGame,NULL,cb,MEM_COMMIT,PAGE_READWRITE);
if(RemoteLibFile == NULL)
{
printf("Error in VirtualAllocEx():%d\n",GetLastError());
getch();
exit(1);
}
if( (WriteProcessMemory(hProcessQQGame,RemoteLibFile,(LPVOID)DllPath,cb,NULL)) == 0)
{
printf("Error in WriteProcessMemory():%d\n",GetLastError());
getch();
exit(1);
}
PTHREAD_START_ROUTINE pfnStartAddr;
pfnStartAddr = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"),"LoadLibraryA");
HANDLE hThread = CreateRemoteThread(hProcessQQGame,NULL,0,pfnStartAddr,RemoteLibFile,0,NULL);
if(hThread == NULL)
{
printf("Error in CreateRemoteThread():%d",GetLastError());
getch();
exit(1);
}
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
VirtualFreeEx(hProcessQQGame,RemoteLibFile,0,MEM_RELEASE);
CloseHandle(hProcessQQGame);
}
鏈枃鏉ヨ嚜CSDN鍗氬錛岃漿杞借鏍囨槑鍑哄錛?a >http://blog.csdn.net/kissyfish/archive/2008/12/07/3462055.aspx
//---------------------------------------------------------------------------
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#define MAXBLOCKSIZE 1024
#pragma comment( lib, "wininet.lib" ) ;
void download(const char *Url,const char *save_as)/*灝哢rl鎸囧悜鐨勫湴鍧鐨勬枃浠朵笅杞藉埌save_as鎸囧悜鐨勬湰鍦版枃浠?/
{
byte Temp[MAXBLOCKSIZE];
ULONG Number = 1;
FILE *stream;
HINTERNET hSession = InternetOpen(_T("RookIE/1.0"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hSession != NULL)
{
HINTERNET handle2 = InternetOpenUrl(hSession,_T(Url), NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
if (handle2 != NULL)
{
if( (stream = fopen( save_as, "wb" )) != NULL )
{
while (Number > 0)
{
InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);
fwrite(Temp, sizeof (char), Number , stream);
}
fclose( stream );
}
InternetCloseHandle(handle2);
handle2 = NULL;
}
InternetCloseHandle(hSession);
hSession = NULL;
}
}
int main(int argc, char* argv[]){
download("*璋冪敤紺轟緥錛屼笅杞界櫨搴︾殑棣栭〉鍒癱:\index.html鏂囦歡*/
return 0;
}
VOID CALLBACK Timer2Proc(
HWND hWnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
)
{
return;
}
鏂規硶浜岋細
// DLL涓殑綰跨▼鍑芥暟鍙互璞¤繖鏍蜂嬌鐢═imer
UINT ThreadProc(LPVOID)
{
SetTimer(NULL, 1, 5000, NULL);
MSG msg;
// PeekMessage 寮哄埗緋葷粺涓鴻綰跨▼寤虹珛娑堟伅鏍?br> PeekMessage(&msg, NULL, NULL, NULL, FALSE);
while (GetMessage(&msg, NULL, NULL, NULL))
{
switch (msg.message)
{
case WM_TIMER:
{
// 榪欓噷姣?縐掗挓鎵ц涓嬈?br> }
break;
}
//TranslateMessage(&msg);
//DispatchMessage(&msg);
}
KillTimer(NULL, 1);
return 0;
}
鏂規硶涓夛細
鍒涘緩涓涓嚎紼? 鍙嶅璇葷郴緇熸椂闂翠笉灝卞彲浠ヤ簡? 濡傛灉瀹氭椂瑕佹眰涓嶄弗,鐢⊿leep灝卞彲浠ヤ簡
UINT TimerThread(LPVOID pama)
{
UINT oldTickCount, newTickCount;
oldTickCount = GetTickCount();
while(TRUE)
{
while(TRUE)
{
newTickCount = GetTickCount();
if(newTickCount - oldTickCount >= 100)
{
oldTickCount = newTickCount;
break;
}
}
TimeProc();
}
return 0;
}
澶х害姣?00ms 璋冪敤涓嬈imeProc();
User Rating: 1019 | Rate This User | ![]() ![]() |
Report this Post to a Moderator | Link |
![]() |
![]() ![]() |
|||
![]() |
||||
The difference between Win32 and MFC are pretty straightforward: The Windows API (Win32) uses a C interface to access windows functionality. It requires that you write all of your own code to manage windows and message handling. It is quite straightforward but you will need a good reference, like MSDN, and some good tutorials or samples to get started. In contrast, MFC, which stands for Microsoft Foundation Classes, are a collection of C++ classes which encapsulate the Win32 API. MFC has some wizards which make the initial creation of a program quick and easy, but I have to admit the learning curve of MFC can sometimes be frustrating as Microsoft seems to have done everything in a way that can at times seem counter-intuitive. Whenever I write an application I write it in MFC but I have been writing applications in MFC for a long time. If all you want is a message loop and a window handle for a game, use Win32. If you want to write a larger application like an editor, maybe MFC is the right tool. Ideally, I would suggest skipping both Win32 and MFC and writing tools in .NET. I do not have any personal experience in it but people I work with sure can get a lot done using it. It may well be worth investigation. Best of luck, - S |
||||
|
![]() |
![]() ![]() |
|||
![]() |
||||
Quote: I am planning to write an interactive 3D environment does that mean using WIN32 application is a better tool for it? also is it possible to use openGL for oject creation and DirectXinput for the interactive control? please give me some suggestion millions of thanks |
||||
|
![]() |
![]() ![]() |
|||
![]() |
||||
Quote: For a game Win32 is usually better. I think I have also heard that MFC doesn't work well in fullscreen. Quote: You can render with opengl and use directinput for input. ____________________________________________________________ Programmers Resource Central |
||||
|
![]() |
![]() ![]() |
|||
![]() |
||||
what about mouse movement like shooting games? how can i do that, please give me some direction |
||||
|
![]() |
![]() ![]() |
|||
![]() |
||||
You can use directinput for mouse movement. Or you can use GetCursorPos(POINT *p); ____________________________________________________________ Programmers Resource Central |
||||
|
![]() |
![]() ![]() |
|||
![]() |
||||
How do i use that? can you give me some example and much clearer direction millions of thanks |
||||
|
![]() |
![]() ![]() |
![]() |
|
msdn Though if you want a camera class look here and here. |
#include <stdio.h>
main()
{
int a,b; /* 瀹氫箟a,b涓や釜鏁村艦鍙橀噺鐢ㄤ簬杈撳叆涓や釜鏁存暟 */
int *point_1,*point_2,*temp_point; /* 瀹氫箟涓変釜鎸囬拡鍙橀噺 */
scanf("%d,%d",&a,&b); /* 鏍煎紡鍖栬緭鍏,b鐨勫?*/
point_1=&a; /* 鎶婃寚閽堝彉閲弍oint_1鐨勫兼寚鍚戝彉閲廰鐨勫湴鍧 */
point_2=&b; /* 鎶婃寚閽堝彉閲弍oint_2鐨勫兼寚鍚戝彉閲廱鐨勫湴鍧 */
if (a<b)
{
temp_point=point_1; /* 榪欓噷鐨則emp_point鏄敤浜庝復鏃跺瓨鍌╬oint_1鐨勫間篃灝辨槸鍙橀噺a鐨勫湴鍧鐨?*/
point_1=point_2; /* 鎶妏oint_2鐨勫艱祴浜坧oint_1 */
point_2=temp_point;
/* 鐢變簬point_1鐨勫煎凡緇忔敼鍙樻棤娉曟壘鍒?鍒╃敤鍓嶉潰涓存椂瀛樺偍鐨勪篃灝辨槸temp_point鎵懼洖鍘焢oint_1鐨勫艱祴浜坧oint_2,鎵撳埌鎶妏oint_1鍜宲oint_2鍊煎鎹㈢殑鐩殑*/
}
printf("%d,%d",*point_1,*point_2); /* 鍒╃敤*point_1鍜?point_2涔熷氨鏄垎杈ㄦ寚鍚慴鍜宎鐨勬柟娉曟妸鍊兼樉紺鴻嚜鐖卞睆騫曚笂 */
}
/* 姝ら闇瑕佹敞鎰忓拰浜嗚В鏄殑姝ゆ硶騫舵病鏈夋敼鍙樺彉閲廰,b鐨勫煎彧鏄埄鐢ㄦ寚閽堝彉閲忓垎鍒瓨鍌╝鍜宐鐨勫湴鍧,鐒跺悗鍐嶆妸閭d袱涓寚閽堝彉閲忕殑鍊煎鎹竴涓嬪叾瀹炲氨鏄瓨鍌ㄥ湪
鎸囬拡鍙橀噺閲岄潰a涓巄鐨勫湴鍧瀵規崲,鍦ㄥ埄鐢?point_1鍜?point_2鐨勬柟寮忔妸璋冩崲鍚庣殑鍊兼樉紺哄嚭鏉ヨ繖閲岀殑*point_1瀹為檯灝辨槸a,姝や腑綆楁硶騫墮潪鐪熺殑鏀瑰彉a,b鐨勫?鑰屾槸
鍒╃敤鎸囬拡榪涜鍦板潃浜ゆ崲杈懼埌澶у皬鎺掑簭鐨勭洰鐨?
*/
#include <stdio.h>
main()
{
int a,b; /* 瀹氫箟a,b涓や釜鏁村艦鍙橀噺鐢ㄤ簬杈撳叆涓や釜鏁存暟 */
int *point_1,*point_2; /* 瀹氫箟涓変釜鎸囬拡鍙橀噺 */
scanf("%d,%d",&a,&b); /* 鏍煎紡鍖栬緭鍏,b鐨勫?*/
point_1 = &a; /* 鎶婃寚閽堝彉閲弍oint_1鐨勫兼寚鍚戝彉閲廰鐨勫湴鍧 */
point_2 = &b; /* 鎶婃寚閽堝彉閲弍oint_2鐨勫兼寚鍚戝彉閲廱鐨勫湴鍧 */
compositor(point_1,point_2); /* 璋冪敤鑷畾涔夌殑鎺掑簭娑墊暟,鎶奱,b鐨勫湴鍧浼犻掔粰point_1鍜宲oint_2 */
printf("%d,%d",a,b); /* 鎵撳嵃鍑篴,b鐨勫?*/
}
static compositor(p1,p2)
int *p1,*p2; /* 瀹氫箟褰㈠紡鍙傛暟p1,p2涓烘寚閽堝彉閲?*/
{
int temp; /* 寤虹珛涓存椂瀛樺偍鍙橀噺 */
if (*p1<*p2) /* 濡傛灉*p1<p2,娉ㄦ剰榪欓噷鐨?p1鍜?p2鍏跺疄灝辨槸a鍜宐 */
{
temp = *p1; /* 鍒╃敤鍙橀噺temp鐢ㄤ簬涓存椂瀛樺偍*p1鍜屽氨鏄痑鐨勫?*/
*p1 = *p2; /* 灝?p1鐨勫間篃灝辨槸a鐨勫兼崲鎴?p2鐨勫間篃灝辨槸b鐨勫?絳変環浜巃=b */
*p2 = temp; /* 灝?p2鐨勫間篃灝辨槸temp鐨勫肩瓑浠蜂簬b=temp */
}
}
/* 娉ㄦ剰:姝ら涓庝笂棰樹笉鍚岀殑鏄?鐩存帴鏀瑰彉浜哸浜巄鐨勫艱揪鍒扮湡瀹炴敼鍙樼殑鐩殑 */