一、知识要点
1、使用空语句时,应加注释,以便知晓此处是故意省略的
2、指针的size
int value[] = {1, 2, 3, 4, 5};
int *p = value;
size_t sz = sizeof(p) / sizeof(*p);
3、调试方法
int main
{
#ifndef NDEBUG
cout << "run to here" << endl; //如果程序中未定义NDEBUG,则执行这句,可通过此方法添加调试语句,并通过
#define NDEBUG使调试语句不执行
#endif
}
二、遗留
1、assert
2、异常
三、工作收获
今天学习了如何使用VS2008创建动态链接库并使用
a.打开Visual Studio 2008,File -> New -> Project…,选择Win32 Console Application,Name设置为test.
b.Application type设置为dll,勾选Empty project,单击Finish按钮
c.新建test.h文件,内容如下:
#ifndef TEST_H
#define TEST_H
#ifdef TEST_BUILD
#define TEST_DLL __declspec(dllexport)
#else
#define TEST_DLL __declspec(dllimport)
#endif
class TEST_DLL MyTest
{
public:
int __stdcall add(int x, int y);
};
#endif
d.新建test.cpp文件,内容如下:
#include "test.h"
#define TEST_BUILD
int __stdcall MyTest::add(int x, int y)
{
return (x+y);
}
e.分别在Debug和Release模式下编译,这时在文件夹test\Debug和test\Release内都有test.dll和test.lib文件,将test\Debug里面的 test.lib重新命名为testd.lib。只需保留test\Release中的dll文件。test.dll,testd.lib,test.lib和test.h就是我们使用这个动态库所需的文件。在使用这个动态库的代码中添加:
#ifdef _DEBUG
#pragma comment(lib, "testd.lib")
#else
#pragma comment(lib, "test.lib")
#endif
——————————
回家跳操,走起~~~