程序调用DLL出错

zhangjin19860305126 2012-08-10 11:18:35
各位大侠,你们好!我在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

...全文
95 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
缘中人 2012-08-10
  • 打赏
  • 举报
回复
http://blog.csdn.net/amy0428/article/details/4197982
缘中人 2012-08-10
  • 打赏
  • 举报
回复

其中#include "dll.h"是我自己写的,它是通过File里new中Header File创建的,我在里面写了
long _declspec(dllexport) _stdcall BCBType_Count(int s,int e);
dllexport 改为
dllimport
缘中人 2012-08-10
  • 打赏
  • 举报
回复
cb6吧还是2010
  • 打赏
  • 举报
回复
Project2.lib不需要加入,就算加了,就多了一个错误
[Linker Error] Delayed load module PROJECT1.LIB was not found
缘中人 2012-08-10
  • 打赏
  • 举报
回复
你昨天是问过了
lib添加到工程里
  • 打赏
  • 举报
回复
谢谢大侠!我自己调出来了。在DLL.h的long _declspec(dllexport) _stdcall BCBType_Count(int s,int e);前面加上extern "C"就可以了。
  • 打赏
  • 举报
回复
Delay load Dlls to delay-load :点击菜单Project中的Options,弹出对话框,再点击Advanced Linker。
  • 打赏
  • 举报
回复
Delay load Dlls to delay-load:点击菜单Project的Options,弹出对话框,再点击Advanced Linker。
缘中人 2012-08-10
  • 打赏
  • 举报
回复
仔细看看那个例子,肯定可以调用
缘中人 2012-08-10
  • 打赏
  • 举报
回复
Delay load Dlls to delay-load 这个是啥,我咋没用过
  • 打赏
  • 举报
回复
我用的是C++ Builder 5.dllexport 改为dllimport还是不行。

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧