上一页 1 2 3 4 5 6 7 8 ··· 20 下一页
摘要: bool GetLocalIP(char* ip) { //1.初始化wsa WSADATA wsaData; int ret=WSAStartup(MAKEWORD(2,2),&wsaData); if (ret!=0) { return false; } //2.获取主机名 char hostname[256]; ret=gethostname(hostname,sizeof(hostname)); if (ret==SOCKET_ERROR) { return false; } //3.获取主机ip HOSTENT* host=gethostbyname(hostname); i 阅读全文
posted @ 2011-05-29 09:08 OYJJ 阅读(452) 评论(0) 推荐(0) 编辑
摘要: static class Util { /// <summary> /// 16位字节序调整 /// </summary> /// <param name="v"></param> /// <returns></returns> public static UInt16 swap16(UInt16 v) { return (UInt16)(((v & 0x00ff) << 8) | ((v & 0xff00) >> 8)); } /// <summary&g 阅读全文
posted @ 2011-05-28 23:36 OYJJ 阅读(553) 评论(0) 推荐(0) 编辑
摘要: string->byte[]Encoding.Default.GetBytesbyte[]->stringEncoding.Default.GetString例如:Byte[] bytes = { 0x31, 0x32 };string str = Encoding.Default.GetString(bytes);bytes = Encoding.Default.GetBytes(str);编码可选择,Encoding.UTF8Encoding.ASCII 等等,根据实际情况选取。 阅读全文
posted @ 2011-05-28 23:25 OYJJ 阅读(184) 评论(0) 推荐(0) 编辑
摘要: HttpWebRequest 使用示例: public partial class Form1 : Form { private HttpWebRequest request; private HttpWebResponse response; public Form1() { InitializeComponent(); } private void btnGo_Click(object sender, EventArgs e) { try { request = (HttpWebRequest)HttpWebRequest.Create(txtUrl.Text); response = ( 阅读全文
posted @ 2011-05-28 22:51 OYJJ 阅读(537) 评论(0) 推荐(0) 编辑
摘要: 控件和m_ip关联CIPAddressCtrl m_ip.SetAddress(127,0,0,1);//初始化 可写在OnInitDialogCString ip; m_ip.GetWindowText(ip);//获取IP字符串这个值可以直接作为inet_addr(ip)的输入SOCKADDR_IN serverAddr;serverAddr.sin_family=AF_INET;serverAddr.sin_addr.s_addr=inet_addr(ip);//ipserverAddr.sin_port=htons(port);//portiRet=::connect(s,(socka 阅读全文
posted @ 2011-05-27 22:50 OYJJ 阅读(648) 评论(0) 推荐(0) 编辑
摘要: 1.头文件中使用前导声明替代交叉引用,由于前导声明只是一个符号声明,不能知道实际对象的大小,引用的对象只能是指针类型。2.源文件中包含自己的头文件。a.hclass B;class A{public: A(); B* b;}; b.hclass A;class B{public: B(); A* a;}; a.cpp#include "A.h"A::A(){} b.cpp#include "B.h"B::B(){} 阅读全文
posted @ 2011-05-18 20:31 OYJJ 阅读(522) 评论(0) 推荐(0) 编辑
摘要: #define DbgPrint(...) printf(__VA_ARGS__)#define DbgEnter() {DbgPrint("+%s/n",__FUNCSIG__);DbgPrint("+pointer_=0x%x,refcount_=0x%x,*refcount_=0x%x/n",pointer_,refcount_,refcount_==0?0:*refcount_);}#define DbgLeave() {DbgPrint("+pointer_=0x%x,refcount_=0x%x,*refcount_=0x%x/n& 阅读全文
posted @ 2011-05-11 22:26 OYJJ 阅读(277) 评论(0) 推荐(0) 编辑
摘要: C2W char->wchar_tW2C wchar_t->char注意 codpage参数选择CP_OEMCP这样中文和英文都可以成功转换,如果只要转换英文可以使用CP_ACPbool C2W(const char* str,wchar_t* wstr){int len=MultiByteToWideChar(CP_OEMCP,0,str,-1/*null terminated*/,wstr,0);return len==MultiByteToWideChar(CP_OEMCP,0,str,-1/*null terminated*/,wstr,len);}bool W2C(con 阅读全文
posted @ 2011-05-06 21:25 OYJJ 阅读(1043) 评论(0) 推荐(0) 编辑
摘要: POSIX--PortableOperatingSystemInterface for Unix 一套UNIX操作系统兼容性API接口POSIX-2008详细内容参见:http://pubs.opengroup.org/onlinepubs/9699919799/functions/contents.html这里比较关注里面有socket一章,Berkeley的POSIX版本在此有详细的说明,很有价值 阅读全文
posted @ 2011-04-24 16:44 OYJJ 阅读(209) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <string.h>typedef struct tagXDate{ int year; int month; int day;}XDate;bool GetCompileDate(XDate* date){ bool succeed=true; char* complieDate=(char*)malloc(strlen(__DATE__)+1); strcpy_s(complieDate,strlen(__DATE 阅读全文
posted @ 2011-04-24 16:26 OYJJ 阅读(655) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 20 下一页