包含了《winsock2h》,创建socket时出错引起出错的语

上传人:F****n 文档编号:103049828 上传时间:2019-10-05 格式:DOC 页数:5 大小:132KB
返回 下载 相关 举报
包含了《winsock2h》,创建socket时出错引起出错的语_第1页
第1页 / 共5页
包含了《winsock2h》,创建socket时出错引起出错的语_第2页
第2页 / 共5页
包含了《winsock2h》,创建socket时出错引起出错的语_第3页
第3页 / 共5页
包含了《winsock2h》,创建socket时出错引起出错的语_第4页
第4页 / 共5页
包含了《winsock2h》,创建socket时出错引起出错的语_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《包含了《winsock2h》,创建socket时出错引起出错的语》由会员分享,可在线阅读,更多相关《包含了《winsock2h》,创建socket时出错引起出错的语(5页珍藏版)》请在金锄头文库上搜索。

1、一, 创建一个win32,应用程序(Win32 Application),包含了,创建SOCKET时出错。引起出错的语句:SOCKET myUDPSock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP),问题现象:编译可以通过,连接时有如下错误,超找帮助发现可能执行函数时,没有连接到库,在Projects-settingslink中加入ws2_32.lib链接,问题解决。(2010-8-8)-Configuration: WINMAIN3 - Win32 Debug-Linking.WINMAIN3.obj : error LNK2001: unresolve

2、d external symbol _imp_socket12Debug/WINMAIN3.exe : fatal error LNK1120: 1 unresolved externalsError executing link.exe.WINMAIN3.exe - 2 error(s), 0 warning(s)二、出现预编译文件找不到,问题原因可能是一个工作区包含了多个工程,第一个工程编译编译运行后,就会在工程设置里增加预编译头文件,新建的工程继承了原来工程的设置,所以在运行时会找原来的文件而找不到。解决方法:更改工程设置,去掉这个预编译头文件如图: 2010-8-14三、free和ma

3、lloc的使用注意事项在一次编程中出现下面的断言错误,经过反复试验,发现是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 whe

4、n 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 requ

5、ests 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 availabl

6、e 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 ch

7、ar* 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_s

8、et(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

9、 * 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

10、);strcpy(p_test-pch,ch);*/四、堆内存和栈内存的小区别1 、栈区( stack ) 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。栈内存分配运算内置于处理器的指令集中,效率很高,但是分配的内存容量有限.2 、堆区( heap ) 亦称动态内存分配.程序在运行的时候用malloc或new申请任意大小的内存,程序员自己负责在适当的时候用free或delete释放内存。动态内存 的生存期可以由我们决定,如果我们不释放内存,程序将在最后才释放掉动态内存.但是,良好的编程习惯是:如果某动态内存不再使用,需要将其释放掉,否则, 我们认为发

11、生了内存泄漏现象。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表.3、字面常量区 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_messageY

12、AHPAUosip_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 externalsE

13、rror executing link.exe.通过查找msdn,知道这个函数需要包含库Iphlpapi.lib七、对话框中如何响应键盘消息VC对话框里如何响应键盘消息VC学习 2008-03-18 09:48:31 阅读80 评论0 字号:大中小 订阅 在VC中,如果需要在对话框中响应键盘消息,是不可能直接做到的,必须通过添加虚函数才能进行处理。具体过程如下: 1.在所需要响应键盘消息的对话框所对应的类名上单击右键,选择“添加虚函数(Add Virtual Function. )”; 2.在弹出来的对话框中选择PreTranslateMessage并添加; 3.编辑PreTranslateM

14、essage函数; BOOL CDrawVoltDlg:PreTranslateMessage(MSG* pMsg) / TODO: Add your specialized code here and/or call the base class if(pMsg-message=WM_KEYDOWN)&(pMsg-wParam=VK_DOWN) /响应按下键盘上的向上键 处理函数代码 return CDialog:PreTranslateMessage(pMsg); 企业一般可在支付平台上备案多个用于税费电子支付的账号,法人卡用户可通过点击“修改可操作账号”,将这些银行账号的操作权限给予指定的操作员卡用户,并设定最大可操作金额。several group number, then with b a,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号