(WIN32 解决)dll 编写与调用详解
IDE:Visual Studio 2005(英文)
中文例似
以 C++入手,以 WIN32 举例
Dll 编写:
首先,新建项目:File/new /Project/Win32/Win32 Project.这时需要键入项目名称(这里以
TestDLL 为项目名称)单击 OK/next 这时显示的界面是 Win32 Application Wizard,选择 DLL 然
后单击 Finish.这样 Dll 项目创建成功。文件树结构如下:
其中 dll.h 是自己建的头文件。创建方法是:右击 Header Files/Add/New Item/Code/Header
File(.h).这时键入文件名 dll 点击 Add 即可.
dll.h 内容如下:
#ifndef DLL
#ifdef MYDLL_EXPORTS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#endif
DLL void HelloWorld ();
#endif
TestDLL.cpp 内容:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "dll.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
DLL void HelloWorld ()
{
MessageBox (0, L"Hello World from DLL!", L"Hi", MB_ICONINFORMATION);
}
BOOL APIENTRY DllMain (HINSTANCE hInst,
DWORD reason,
LPVOID reserved)
{