获取MAC地址

Windows平台下用C++代码取得机器的MAC地址并不是一件简单直接的事情。到目前为止,作者尚未发现有任何一个通用的100%的适用于所有Windows平台的方法可以稳定的取得MAC地址。而有些应用(比如MMORPG)则需要稳定的得到机器的MAC地址,解决方案往往是通过多种方法依次使用来提高成功率。 以下方法只会返回多网卡的第一个MAC地址。 网上有很多文章和源码来解决该问题,大多不全或有问题。本篇所有方法均经过整理调试,可直接使用。 作者也不喜欢满篇帖代码,本篇贴代码是方便直接使用,请读者谅解。 ...
网络编程 | 2014-01-30 18:41 | 阅读 12674 次 | 评论 0 条

struct hostent结构体

这个数据结构是这样的:    struct hostent {    char *h_name;    char **h_aliases;    int h_addrtype;    int h_length;    char **h_addr_list;    };    #define h_addr h_addr_list[0] 这里是这个数据结构的详细资料: struct hostent:   h_name – 地址的正式名称。   h_aliases – 空字节-地址的预备名称的指针。   h_addrtype –地...
网络编程 | 2014-01-30 14:37 | 阅读 1521 次 | 评论 0 条

预处理器指令

1.#define指令定义了一个标识符及一个字符序列(即字符集合)。在源程序中每次遇到该标识符时,就用定义的字符序列替换它。标识符被称为宏名,替换过程称为宏替换,指令的一般形式为: #define macro-name char-sequence 2.#error指令强迫编译器停止编译,它主要用于程序调试。#error指令的一般形式为: #error error-message 3.#if, #else, #elif, #endif #if e...

fread()和fwrite()用法

#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; double d = 12.23; int i = 101; long l = 123023L; if((fp = fopen("test", "wb")) == NULL) { printf("Cannot open file.\n"); exit(1); } fwrite(&amp;d, sizeof(double), 1, fp); fwrite(&amp;i, sizeof(int), 1, fp); fwrite(&a...

fseek()函数用法

#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp; if(argc != 3) { printf("Usage: SEEK filename byte\n"); exit(1); } if((fp = fopen(argv[1], "rb")) == NULL) { printf("Cannot open file.\n"); exit(1); } if(fseek(fp, atol(argv[2]), SEEK_SET)) { pri...

timer库的代码示例

timer库的代码摘要如下: class timer { public: timer() { _start_time = std::clock(); } void restart() { _start_time = std::clock(); } double elapsed() const { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } double elapsed_min() const { return double(1) / double(CLOCKS_P...

vc6.0下编译boost1.34.1

今天在同学的帮助下,成功的在vc6.0中安装和编译boost库,遇到不少问题,并解决之,把过程大概写一下,以便以后参阅: (主要参考文章:http://h-lm.spaces.live.com/blog/cns!C523F565A10E3B66!749.entry http://blog.csdn.net/liroket/archive/2009/06/10/4257308.aspx) 据说c6.0不支持目前比较新版本,如:boost1.36。这里给出VC6.0编译boost1.34.1的流程。 1....
C++ | 2014-01-29 22:39 | 阅读 2049 次 | 评论 0 条

删除文件

使用remove(filename) #include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(int argc, char *argv[]) { char str[80]; if(argc != 2) { printf("usage: xerase <filename>\n"); exit(1); } printf("Erase %s? (Y/N):", argv[1]); gets(str); if(toupper(*str) == 'Y') ...
C++ | 2014-01-28 23:47 | 阅读 1058 次 | 评论 0 条

C指针——函数指针(转)

函数名与函数指针 一 通常的函数调用 一个通常的函数调用的例子: //自行包含头文件 void MyFun(int x); //此处的申明也可写成:void MyFun( int ); int main(int argc, char* argv[]) { MyFun(10); //这里是调用MyFun(10);函数 return 0; } void MyFun(int x) //这里定义一个MyFun函数 { printf(“%d\n”,x); } ...
C++ | 2014-01-28 00:46 | 阅读 1186 次 | 评论 0 条

C++ 字符串的格式化(转)

C++格式化字符串(续) 2. 一些特殊规定字符 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 字符 作用 ────────────────────────── \n 换行 \f 清屏并换页 \r 回车 \t Tab符 \xhh ...
C++ | 2014-01-28 00:45 | 阅读 8879 次 | 评论 0 条

关于GlobalAlloc(转)

1. GlobalAlloc函数和new()的区别。 1>new是标准的C++分配内存函数。GlobalAlloc是WIN下的API函数。 2>new分配内存同时会调用类等对象的构造函数。GlobalAlloc不回。 3>new分配的内存只能同进程使用,如(A进程new,B进程不能delete),GlobalAlloc能多进程使用,并删除。 2. GlobalAlloc分配的内存需要释放么? 所有动态内存分配都必须释放,GlobalAlloc分配的内存用GlobalFree进行释放。 3. GlobalAlloc和HeapAlloc的...
MFC | 2014-01-28 00:44 | 阅读 2047 次 | 评论 0 条

C++小技巧(转)

1、获取当前系统时间: [cpp] view plaincopy SYSTEMTIME systime; GetLocalTime(&amp;systime); char str_time_name[MAX_PATH]; sprintf(str_time_name,"%d-%d-%d %d:%d:%d.jpg",systime.w...
C++ | 2014-01-28 00:44 | 阅读 1747 次 | 评论 0 条

木马编程

1、消息炸弹 [cpp] view plaincopy #define UNICODE #define _UNICODE #include <stdio.h> #include <tchar.h> #include <windows.h> #include <Lm.h> ...
C++ | 2014-01-28 00:43 | 阅读 5283 次 | 评论 0 条

Win32窗口程序实例(转)

#include <windows.h> //Win32窗口程序实例 //声明消息处理函数 LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); char szClassName[]="windowsclass"; char szAppTitle[]="WinApi窗口实例"; i...
MFC | 2014-01-28 00:42 | 阅读 3117 次 | 评论 0 条