1. __DATE__
The compilation date of the current source file. The date is a string literal of the formMmm dd yyyy. The month nameMmm is the same as for dates generated by the library functionasctime declared in TIME.H.
__TIME__
The most recent compilation time of the current source file. The time is a string literal of the formhh:mm:ss.
例子:
#include<time.h>
#include<stdio.h>
int main()
{
char strmsg[200];
sprintf(strmsg,"INF:Compile Date %s Time %s",__DATE__, __TIME__);
printf("%s\n",strmsg);
}
2.返回关于文件属性的结构体 类似Linux的basename
#define _WIN32_WINNT 0x0400
#include "windows.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
printf ("Target file is %s.\n", argv[1]);
hFind = FindFirstFile(argv[1], &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
} else {
printf ("The first file found is %s\n", FindFileData.cFileName);
FindClose(hFind);
}
return (0);
}
3.#ifdef __cplusplus 有什么作用?
一般用于将C++代码以标准C形式输出(即以C的形式被调用),这是因为C++虽然常被认为是C的超集,但是C++的编译器还是与C的编译器不同的。C中调用C++中的代码这样定义会是安全的。
一般的考虑跨平台使用方法如下:
#ifdefined(__cplusplus)||defined(c_plusplus) //跨平台定义方法
extern "C"{
#endif
//... 正常的声明段
#ifdefined(__cplusplus)||defined(c_plusplus)
}
#endif
简单的用在windows下可以如下定义:
#ifdef __cplusplus
extern "C"{
//... 正常的声明段
}
#endif
SendMessage该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。