随笔分类 -  C/C++

摘要:int arr[100]; printf("&arr[0]=%d\n",&arr[0]); printf("arr=%d\n",arr); printf("&arr=%d\n",&arr); printf("&arr[0]+1=%d\n",&arr[0]+1); printf("arr+1=%d\n",arr+1); printf("&arr+1=%d\n",&arr+1);运行的结果&arr[0]=12 阅读全文
posted @ 2011-09-01 22:53 OYJJ 阅读(236) 评论(0) 推荐(0)
摘要:sscanf char buf[]="port=5000"; char key[100]=""; char value[100]=""; sscanf(buf,"%[^=]=%[^\n]",key,value); printf("key=%s\n",key); printf("value=%s\n",value); strtok char buf[]="port=5000"; char key[100]=""; char value[1 阅读全文
posted @ 2011-09-01 22:45 OYJJ 阅读(1891) 评论(0) 推荐(1)
摘要:/*加一个成员变量*/ CMenu m_menu;/*添加菜单 in OnInitDialog*/ m_menu.LoadMenu(IDR_MENU/*menu id here*/); SetMenu(&m_menu); 阅读全文
posted @ 2011-08-09 22:34 OYJJ 阅读(1404) 评论(0) 推荐(0)
摘要:环境变量被破坏%SystemRoot% 不能被解析导致。在Visual Studio中,选择工具->选项->工程和解决方案->VC++目录可执行文件添加:C:\Windows\System32\问题可以解决。 阅读全文
posted @ 2011-08-09 22:29 OYJJ 阅读(2052) 评论(0) 推荐(0)
摘要:CRect rect; GetDlgItem(IDC_IMG_NOTEPAD)->GetWindowRect(&rect);//获得空间的绝对坐标 ScreenToClient(&rect);//获得相对于主窗体的坐标 rect.OffsetRect(CSize(5,5));//这里要是要移动的相对位置 GetDlgItem(IDC_IMG_NOTEPAD)->MoveWindow(rect);//移动到目标位置 阅读全文
posted @ 2011-07-17 19:14 OYJJ 阅读(5118) 评论(1) 推荐(0)
摘要://加载NotePad.exe的图标到IDC_IMG_NOTEPAD Cstatic控件上,这段代码显示不出ico图标,原因是什么?? //是type属性设置错了,在资源视图里面,编辑CStatic控件的属性,将它的Type改为icon,即解决。 SHFILEINFO fileInfo; DWORD_PTR dwRet=SHGetFileInfo("C:\\windows\\system32\\notepad.exe",0,&fileInfo,sizeof(SHFILEINFO),SHGFI_ICON); if (dwRet) { ((CStatic*)GetDlg 阅读全文
posted @ 2011-07-17 17:20 OYJJ 阅读(3471) 评论(0) 推荐(0)
摘要://如果这个对话框通过非模态的方式被创建,由于在PostNcDestroy(对话框销毁会被调用)中使用了delete this;不会发生内存泄漏class CMessageDlg:public CDialog{public: void PostNcDestroy();};void CMessageDlg::PostNcDestroy(){ CDialog::PostNcDestroy(); delete this;} 阅读全文
posted @ 2011-07-17 16:51 OYJJ 阅读(395) 评论(0) 推荐(0)
摘要:wchar_t wstr[100]=L"wstr";char str[100];wcstombs(str,wstr,100);//宽字符转多字节mbstowcs(wstr,str,100);//多字节转宽字符 也可以使用:MultiByteToWideChar和WideCharToMultiByte参考:http://blog.csdn.net/iamoyjj/archive/2011/05/06/6400877.aspx 阅读全文
posted @ 2011-06-29 20:34 OYJJ 阅读(470) 评论(0) 推荐(0)
摘要:PE文件格式被组织为一个线性的数据流,它由一个MS-DOS头部开始,接着是一个是模式的程序残余以及一个PE文件标志,这之后紧接着PE文件头和可选头部。这些之后是所有的段头部,段头部之后跟随着所有的段实体。文件的结束处是一些其它的区域,其中是一些混杂的信息,包括重分配信息、符号表信息、行号信息以及字串表数据。PE文件主要信息按顺序IMAGE_DOS_HEADER MS-DOS MZ头部DOS STUB MS-DOS 实模式残余程序NTSIGNATURE PE文件标识IMAGE_FILE_HEADER PE文件头IMAGE_OPTIONAL_HEADER PE可选头IMAGE_SECTION_HE 阅读全文
posted @ 2011-06-09 22:21 OYJJ 阅读(1355) 评论(0) 推荐(0)
摘要:cout.setf(ios::hex,ios::basefield);//设置十六进制显示数值cout.setf(ios::showbase|ios::uppercase);//设置0x头和大写 阅读全文
posted @ 2011-06-08 21:52 OYJJ 阅读(2487) 评论(0) 推荐(0)
摘要:#include <windows.h>#include "console.h"int main(){ PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); CHAR szSysPath[MAX_PATH]; if (GetSystemDirectory(szSysPath,MAX_PATH)>0)//get windows system dir { strcat_s(szSysPath,MAX_PATH,"//no 阅读全文
posted @ 2011-06-06 22:22 OYJJ 阅读(905) 评论(0) 推荐(0)
摘要:首先添加鼠标,图标,菜单资源,然后可以从资源ID加载BOOL InitApplication( HINSTANCE hInstance ){ WNDCLASS wc; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);; //wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hCursor=LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR_PEN));//looad cursor by res 阅读全文
posted @ 2011-06-06 18:36 OYJJ 阅读(946) 评论(0) 推荐(0)
摘要:win32.h#ifndef _X_WIN32_H_#define _X_WIN32_H_BOOL InitApplication(HINSTANCE);BOOL InitInstance(HINSTANCE,int);LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);#endif win32.cpp#include <windows.h>#include "win32.h"HINSTANCE g_hInst;HWND g_hWnd;char g_szAppName[]="WIN32Sample&quo 阅读全文
posted @ 2011-06-06 17:03 OYJJ 阅读(1095) 评论(0) 推荐(0)
摘要:typedef struct tagIPInfo { char ip[30]; }IPInfo; bool GetLocalIPs(IPInfo* ips,int maxCnt,int* cnt) { //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_ERR 阅读全文
posted @ 2011-05-29 11:38 OYJJ 阅读(6076) 评论(0) 推荐(0)
摘要: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 阅读(480) 评论(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 阅读(672) 评论(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 阅读(532) 评论(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 阅读(294) 评论(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 阅读(1065) 评论(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 阅读(232) 评论(0) 推荐(0)