代码改变世界

Visual C++ 2011-5-10

2011-05-10 22:28  Clingingboy  阅读(588)  评论(0编辑  收藏  举报

 

一.MAX_PATH与_MAX_PATH

http://zhidao.baidu.com/question/120361012.html
http://zhidao.baidu.com/question/127061770.html

二.组合路径(_makepath)和分割路径(_splitpath)

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    char path_buffer[_MAX_PATH];
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    char fname[_MAX_FNAME];
    char ext[_MAX_EXT];

    _makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" ); // C4996
    // Note: _makepath is deprecated; consider using _makepath_s instead
    printf( "Path created with _makepath: %s\n\n", path_buffer );
    _splitpath( path_buffer, drive, dir, fname, ext ); // C4996
    // Note: _splitpath is deprecated; consider using _splitpath_s instead
    printf( "Path extracted with _splitpath:\n" );
    printf( "  Drive: %s\n", drive );
    printf( "  Dir: %s\n", dir );
    printf( "  Filename: %s\n", fname );
    printf( "  Ext: %s\n", ext );
}

输出结果:
Path created with _makepath: c:\sample\crt\makepath.c
Path extracted with _splitpath:
  Drive: c:
  Dir: \sample\crt\
  Filename: makepath
  Ext: .c

三.ATL的Time封装

1.CTime

CTime time(CTime::GetCurrentTime());
SYSTEMTIME timeDest;
time.GetAsSystemTime(timeDest);
FILETIME fileTime;
::SystemTimeToFileTime(&timeDest, &fileTime);   


2.CTimeSpan
用于CTime的相加减
CTime t(1999, 3, 19, 22, 15, 0); // 10:15 PM March 19, 1999
t += CTimeSpan(0, 1, 0, 0);      // 1 hour exactly
ATLASSERT(t.GetHour() == 23);   

3.CFileTime
对FILETIME的封装

http://support.microsoft.com/kb/188768

四.AfxMessageBox与MessageBox的区别

http://blog.csdn.net/emily_zy/archive/2009/06/04/4239526.aspx

五.regsvr32和dll入口点

使用regsvr32命令可以调用内置的DllRegisterServer和DllUnregisterServer方法,一般这些方法都用于写注册表和注销注册表用.下面介绍如何使用

1.在dll中实现DllRegisterServer和DllUnregisterServer这两个方法,简单起见,不与注册表有关

#include <Windows.h>

STDAPI DllRegisterServer(void)
{
    MessageBox(NULL, "DllRegisterServerTest", "", MB_OK);
    return 0;
}

STDAPI DllUnregisterServer(void)
{
    MessageBox(NULL, "DllUnregisterServerTest", "", MB_OK);
    return 0;
}

2.在def文件中输出这些函数

LIBRARY      "DellRegTest.DLL"

EXPORTS
    DllRegisterServer    PRIVATE
    DllUnregisterServer    PRIVATE

3.用regsvr32 命令来进入dll入口点(即上面的DllRegisterServer方法)

假如dll的名字为DellRegTest.dll,则命令如下
regsvr32 DellRegTest.dll

regsvr32 还有其他的相关命令
http://baike.baidu.com/view/40743.htm

http://www.cppblog.com/kenny/archive/2011/05/02/144490.html

以前还以为DllRegisterServer为内置方法实现的,原来是要自己实现了,解决了我心中想了很久的一个疑问.

六.函数的声明与定义

不仅仅是声明在头文件中,在同个文件也可以

void hello();
void hello()
{
}
int main( void )
{
    hello();
}