




全文預(yù)覽已結(jié)束
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
一, 創(chuàng)建一個win32,應(yīng)用程序(Win32 Application),包含了,創(chuàng)建SOCKET時出錯。引起出錯的語句:SOCKET myUDPSock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP),問題現(xiàn)象:編譯可以通過,連接時有如下錯誤,超找?guī)椭l(fā)現(xiàn)可能執(zhí)行函數(shù)時,沒有連接到庫,在Projects-settingslink中加入ws2_32.lib鏈接,問題解決。(2010-8-8)-Configuration: WINMAIN3 - Win32 Debug-Linking.WINMAIN3.obj : error LNK2001: unresolved external symbol _imp_socket12Debug/WINMAIN3.exe : fatal error LNK1120: 1 unresolved externalsError executing link.exe.WINMAIN3.exe - 2 error(s), 0 warning(s)二、出現(xiàn)預(yù)編譯文件找不到,問題原因可能是一個工作區(qū)包含了多個工程,第一個工程編譯編譯運行后,就會在工程設(shè)置里增加預(yù)編譯頭文件,新建的工程繼承了原來工程的設(shè)置,所以在運行時會找原來的文件而找不到。解決方法:更改工程設(shè)置,去掉這個預(yù)編譯頭文件如圖: 2010-8-14三、free和malloc的使用注意事項在一次編程中出現(xiàn)下面的斷言錯誤,經(jīng)過反復(fù)試驗,發(fā)現(xiàn)是free的指針所指的內(nèi)存不是malloc分配的,而是一個數(shù)組在定義時分配的。結(jié)合msdn對free和malloc的解釋:The free function deallocates a memory block (memblock) that was previously allocated by a call to calloc, malloc, or realloc. The number of freed bytes is equivalent to the number of bytes requested when the block was allocated (or reallocated, in the case of realloc). If memblock is NULL, the pointer is ignored and free immediately returns. Attempting to free an invalid pointer (a pointer to a memory block that was not allocated by calloc, malloc, or realloc) may affect subsequent allocation requests and cause errors.After a memory block has been freed, _heapmin minimizes the amount of free memory on the heap by coalescing the unused regions and releasing them back to the operating system. Freed memory that is not released to the operating system is restored to the free pool and is available for allocation again.可以看出malloc分配的內(nèi)存是從heap(堆)中獲得的,free函數(shù)也就只能free堆里的內(nèi)存,因此,當調(diào)用函數(shù)去free一快棧里的內(nèi)存是,就會有下面的錯誤。用來驗證此錯誤的程序: 2010-8-15#include #include #include typedef struct testchar *pch;test_t;int test_init(test_t * p_test);int test_set(test_t *p_test, char* ch);/int test_set_chrs(test_t *p_test, const char* ch);int test_free(test_t *p_test);int main()test_t *ptr_test;char chrs = tests;/printf(length of chrs %dn,strlen(chrs);char *ptr_string;int length;length = strlen(chrs);ptr_string = (char*)malloc(length+1)*sizeof(char);strcpy(ptr_string,chrs);*(ptr_string+length) = 0;test_init(&ptr_test);/test_set(ptr_test,ptr_string);test_set(ptr_test,chrs); /run this command,then run free may cause a errorprintf(%sn,(ptr_test-pch);test_free(ptr_test);/test_set(&ptr_test,chrs);return 1;int test_init(test_t *p_test)(*p_test) = (test_t*)malloc(sizeof(test_t);(*p_test)-pch = NULL;return 1;int test_set(test_t * p_test,char *ch)p_test-pch = ch;return 1;int test_free(test_t *p_test)free(p_test-pch); /Notice: free function must free memory allocated by malloc()free(p_test);return 1;/*int test_set_chrs(test_t *p_test, const char* ch)if (p_test=NULL)return -1;p_test-pch = (char*)malloc(strlen(ch)*sizeof(char);strcpy(p_test-pch,ch);*/四、堆內(nèi)存和棧內(nèi)存的小區(qū)別1 、棧區(qū)( stack ) 由編譯器自動分配釋放 ,存放函數(shù)的參數(shù)值,局部變量的值等。其操作方式類似于數(shù)據(jù)結(jié)構(gòu)中的棧。棧內(nèi)存分配運算內(nèi)置于處理器的指令集中,效率很高,但是分配的內(nèi)存容量有限.2 、堆區(qū)( heap ) 亦稱動態(tài)內(nèi)存分配.程序在運行的時候用malloc或new申請任意大小的內(nèi)存,程序員自己負責在適當?shù)臅r候用free或delete釋放內(nèi)存。動態(tài)內(nèi)存 的生存期可以由我們決定,如果我們不釋放內(nèi)存,程序?qū)⒃谧詈蟛裴尫诺魟討B(tài)內(nèi)存.但是,良好的編程習慣是:如果某動態(tài)內(nèi)存不再使用,需要將其釋放掉,否則, 我們認為發(fā)生了內(nèi)存泄漏現(xiàn)象。注意它與數(shù)據(jù)結(jié)構(gòu)中的堆是兩回事,分配方式倒是類似于鏈表.3、字面常量區(qū) char * pstr = “hello”; pstr0 = c; / 錯誤,不能修改五、函數(shù)編譯可以通過,但連接錯誤,一般原因可能是有了函數(shù)的聲明,但是沒有函數(shù)的定義(實現(xiàn)),會導致連接出錯。unresolved external symbol int _cdecl application_cb_snd_message(struct osip_transaction *,struct osip_message *,char *,int,int) (?application_cb_snd_messageYAHPAUosip_transactionPAUosip_messagePADHHZ) 六、連接出錯unresolved external symbol _GetIfEntryLinking.eXutils.obj : error LNK2001: unresolved external symbol _GetIfEntry4eXutils.obj : error LNK2001: unresolved external symbol _GetIpAddrTable12Debug/exosip.dll : fatal error LNK1120: 2 unresolved externalsError executing link.exe.通過查找msdn,知道這個函數(shù)需要包含庫Iphlpapi.lib七、對話框中如何響應(yīng)鍵盤消息VC對話框里如何響應(yīng)鍵盤消息VC學習 2008-03-18 09:48:31 閱讀80 評論0 字號:大中小 訂閱 在VC中,如果需要在對話框中響應(yīng)鍵盤消息,是不可能直接做到的,必須通過添加虛函數(shù)才能進行處理。具體過程如下: 1.在所需要響應(yīng)鍵盤消息的對話框所對應(yīng)的類名上單擊右鍵,選擇“添加虛函數(shù)(Add Virtual Function. )”; 2.在彈出來的對話框中選擇PreTranslateMessage并添加; 3.編輯PreTranslateMessage函數(shù); BOOL CDrawVoltDlg:Pre
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 新能源風力發(fā)電標準必要專利許可與風力發(fā)電場運維合作協(xié)議
- 管理部部長工作概述
- 護理進修述職
- 醫(yī)院培訓課件:《康復(fù)醫(yī)學》
- 鋼架大棚安裝協(xié)議書
- 食堂轉(zhuǎn)讓轉(zhuǎn)租協(xié)議書
- 車商汽車合同協(xié)議書
- 餐廳股東解散協(xié)議書
- 酒后駕駛賠償協(xié)議書
- 車輛設(shè)備移交協(xié)議書
- 網(wǎng)絡(luò)安全服務(wù)方案
- 【MOOC】現(xiàn)代郵政英語(English for Modern Postal Service)-南京郵電大學 中國大學慕課MOOC答案
- 巨量千川營銷師(初級)認證考試復(fù)習題庫(含答案)
- 1學會尊重-《每個人都應(yīng)得到尊重》(說課稿)2023-2024學年統(tǒng)編版道德與法治四年級下冊
- 教室租賃合同范本教程
- 商用廚房設(shè)備搬遷實施方案
- 執(zhí)業(yè)藥師資格考試試題及答案
- 《供應(yīng)鏈管理》課件 第7章 供應(yīng)鏈運輸管理
- 書法測評基礎(chǔ)理論知識單選題100道及答案解析
- 2023內(nèi)蒙古呼和浩特金谷農(nóng)商銀行招聘70人筆試參考題庫附帶解題思路及答案詳解
- 2024至2030年中國墓地陵園行業(yè)市場全景監(jiān)測及投資前景展望報告
評論
0/150
提交評論