C++builder4创建及调用DLL

来源:百度知道 编辑:UC知道 时间:2024/05/30 23:40:19
用C++创建DLL工程project1
1.Project1.h如下
extern "C" __declspec(dllimport) int __stdcall test();
2.Project1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void *)
{return 1;
}
//---------------------------------------------------------------int __stdcall test()
{
return 54;
}
然后创建一个程序调用(采用静态调用)
lib库已生成并加入
main.h如下
//---------------------------------------------------------------------------
#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include "Project1.h"
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
////---------------------------------------------------------------------------<

BCbuilder调用DLL是非常麻烦的,需要对不同的DLL进行加载。
加载方法如下:
定义一个函数型变量,与DLL库的函数类型相同,通过以下步骤实现调用:
先装载DLL库,再一个一个的取函数的地址,付给你定义的函数变量,然后就可以在其它地方调用你定义的函数变量就行了。