




全文預覽已結束
下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
一, 創(chuàng)建一個win32,應用程序(Win32 Application),包含了,創(chuàng)建SOCKET時出錯。引起出錯的語句:SOCKET myUDPSock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP),問題現象:編譯可以通過,連接時有如下錯誤,超找?guī)椭l(fā)現可能執(zhí)行函數時,沒有連接到庫,在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)二、出現預編譯文件找不到,問題原因可能是一個工作區(qū)包含了多個工程,第一個工程編譯編譯運行后,就會在工程設置里增加預編譯頭文件,新建的工程繼承了原來工程的設置,所以在運行時會找原來的文件而找不到。解決方法:更改工程設置,去掉這個預編譯頭文件如圖: 2010-8-14三、free和malloc的使用注意事項在一次編程中出現下面的斷言錯誤,經過反復試驗,發(fā)現是free的指針所指的內存不是malloc分配的,而是一個數組在定義時分配的。結合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分配的內存是從heap(堆)中獲得的,free函數也就只能free堆里的內存,因此,當調用函數去free一快棧里的內存是,就會有下面的錯誤。用來驗證此錯誤的程序: 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);*/四、堆內存和棧內存的小區(qū)別1 、棧區(qū)( stack ) 由編譯器自動分配釋放 ,存放函數的參數值,局部變量的值等。其操作方式類似于數據結構中的棧。棧內存分配運算內置于處理器的指令集中,效率很高,但是分配的內存容量有限.2 、堆區(qū)( heap ) 亦稱動態(tài)內存分配.程序在運行的時候用malloc或new申請任意大小的內存,程序員自己負責在適當的時候用free或delete釋放內存。動態(tài)內存 的生存期可以由我們決定,如果我們不釋放內存,程序將在最后才釋放掉動態(tài)內存.但是,良好的編程習慣是:如果某動態(tài)內存不再使用,需要將其釋放掉,否則, 我們認為發(fā)生了內存泄漏現象。注意它與數據結構中的堆是兩回事,分配方式倒是類似于鏈表.3、字面常量區(qū) char * pstr = “hello”; pstr0 = c; / 錯誤,不能修改五、函數編譯可以通過,但連接錯誤,一般原因可能是有了函數的聲明,但是沒有函數的定義(實現),會導致連接出錯。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,知道這個函數需要包含庫Iphlpapi.lib七、對話框中如何響應鍵盤消息VC對話框里如何響應鍵盤消息VC學習 2008-03-18 09:48:31 閱讀80 評論0 字號:大中小 訂閱 在VC中,如果需要在對話框中響應鍵盤消息,是不可能直接做到的,必須通過添加虛函數才能進行處理。具體過程如下: 1.在所需要響應鍵盤消息的對話框所對應的類名上單擊右鍵,選擇“添加虛函數(Add Virtual Function. )”; 2.在彈出來的對話框中選擇PreTranslateMessage并添加; 3.編輯PreTranslateMessage函數; BOOL CDrawVoltDlg:Pre
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國瀝青去除劑行業(yè)市場全景分析及前景機遇研判報告
- 2024年度浙江省二級注冊建筑師之法律法規(guī)經濟與施工高分通關題庫A4可打印版
- 股權培訓計劃方案
- 腫瘤患者飲食營養(yǎng)科學指南
- 幼兒園中層管理者培訓課程
- 幼兒心理健康發(fā)展指導
- 關于創(chuàng)新的培訓
- 華文老師面試題及答案
- 卓越青年領袖培訓班
- 前端監(jiān)聽面試題及答案
- 小學生匯報講課件
- 2025浙江嘉興市海寧市嘉睿人力招聘5人筆試參考題庫附帶答案詳解析版
- 2025年安徽蚌埠市龍子湖區(qū)東方人力資源有限公司招聘筆試參考題庫含答案解析
- 2025至2030中國云計算行業(yè)產業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 黨課課件含講稿:《關于加強黨的作風建設論述摘編》輔導報告
- GB/T 19023-2025質量管理體系成文信息指南
- 2025中考歷史高頻點速記大全
- 2025年特種設備作業(yè)人員氣瓶充裝P證考試題庫
- 《智能駕駛輔助系統(tǒng)ADAS》課件
- 2024年自然資源部所屬單位招聘筆試真題
- 多余物管理制度
評論
0/150
提交評論