程序调用DLL出错
各位大侠,你们好!我在Project2中创建了DLL,经过点击菜单project中Builder Project2后,生成了Project2.lib与Project2.dll。所有的这些文件放在文件夹CH18_001中。DLL的程序如下:
//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//--------------------------------------------------------------------------
long _declspec(dllexport) _stdcall BCBType_Count(int s,int e)
{
long sum = 0;
for(s;s<=e;s++)
sum+=s;
return sum;
}
然后我在Project1中写了自己的程序,Project1在文件夹CH18_003中。我把CH18_001中的Project2.lib与Project2.dll复制到
CH18_003中。然后点击project中options,将Project2.dll加入Delay load Dlls to delay-load中。程序如下:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "dll.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int s,e;
s=Edit1->Text.ToInt();
e=Edit2->Text.ToInt();
Edit3->Text=BCBType_Count(s,e);
}
//---------------------------------------------------------------------------
其中#include "dll.h"是我自己写的,它是通过File里new中Header File创建的,我在里面写了
long _declspec(dllexport) _stdcall BCBType_Count(int s,int e);
我对程序Builder之后,出现错误:
[Linker Error] Delayed load module PROJECT2.DLL was not found
[Linker Error] Unresolved external '__stdcall BCBType_Count(int, int)' referenced from F:\MF\CH18_003\UNIT1.OBJ