什么情况下用现在分词:C++builder4创建及调用DLL

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/27 21:50:51
用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>
////---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

可是在主程序中调用总说
[Linker Error] Unresolved external 'test' referenced from C:\DOCUMENTS AND SETTINGS\BI\桌面\DLL\MAIN.OBJ.
请问,哪里有问题....
只是求一个极简单调用的例子(最好有静态和动态两种)

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