bcb调用bcb编译的动态库都出错,要哭了。

失落的羊 2010-03-17 10:36:40
winxp + bcb6.0

库文件如下:我是编译的C库 ,只输出一个函数

//---------------------------------------------------------------------------

#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;
}
//---------------------------------------------------------------------------


extern __declspec(dllexport)
int __stdcall FucFormActive(int bFormID);

int __stdcall FucFormActive(int bFormID)
{
return bFormID+300;

}



然后在应用程序中,如下静态调用(前面生成的bc.lib文件已经加入了工程):
编译通过,连接出错。

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__declspec(dllimport) int __stdcall FucFormActive(int bFormID);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
int cc=FucFormActive(20);

ShowMessage("It is"+IntToStr(cc));

}

}


求解?
...全文
130 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
周药师 2010-03-18
  • 打赏
  • 举报
回复
祝贺lz解决问题了

"Unresolved external FucFormActive"
lz看见这些错误,提示没有找到FucFormActive
应该自己多想想,多思考
mabaoyes 2010-03-18
  • 打赏
  • 举报
回复
keiy 正解。加上就可以.
恭喜楼主搞定问题!
失落的羊 2010-03-17
  • 打赏
  • 举报
回复
谢谢楼上的几位。keiy 正解。加上就可以了。
ydlchina 2010-03-17
  • 打赏
  • 举报
回复
需要在BCB的项目中加入输入接口库(import library),打开工程项目,使用BCB View|Project Manager打开项目列表,向项目中加入接口库(*.lib)。

做个测试通过(CB2010)
柯本 2010-03-17
  • 打赏
  • 举报
回复
你的DLL是C的,那么调用时要用:
extern "C" __declspec(dllimport) int __stdcall FucFormActive(int bFormID);
失落的羊 2010-03-17
  • 打赏
  • 举报
回复
链接错误如下:
[Linker Error] Unresolved external '__stdcall FucFormActive(int)' referenced from F:\TMPWORKSHOP\BCB_DLL\USE_DLL\UNIT1.OBJ
失落的羊 2010-03-17
  • 打赏
  • 举报
回复
顺便说一下,我用生成的bc.dll,动态调用,程序是正常的。
1)VsDll为vs2010工程,编译生成动态库。 2)BCBCall为bcb工程,调用动态库 3)Viewdll.exe为查看DLL导出文件的工具。 注意事项一: VSDll里面有一个 KpHttps.def LIBRARY "KpHttps" EXPORTS InitKpHttp Project > Properties... > Linker > Input > Module Definition File 里面加入你刚才的KpHttps.def文件,重新编译就行了。出来的InitKpHttp函数前面没有下划线,后面没有@8或者@ABCDEF之类的。 注意事项二: 用C++Builder的implib工具生成DLL对应的lib文件。如:implib xx.lib xxx.dll。 生成lib文件之后,C++Builder便可以使用这个lib文件了。 注意事项三: 文件头的声明应该完全一样,否则(呵呵),会出现链接错误。 #ifdef DLL_API #define DLL_API extern "C" _declspec(dllexport) #else #define DLL_API extern "C" _declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif DECLDIR int __stdcall InitKpHttp(void); DECLDIR int UnInitKpHttp(void); DECLDIR int KpHttpRequest(char *strurl,char *strhost,char *strresult,int &resultle;); DECLDIR int KpHttpsRequest(char *strurl,char *strhost,char *strresult,int &resultle;); DECLDIR int KpHttpPost(char *strurl,char *strhost,char *strPost,int postlen,char *strresult,int &resultle;); DECLDIR int KpHttpsPost(char *strurl,char *strhost,char *strPost,int postlen,char *strresult,int &resultle;); DECLDIR int KpUpLoadFile(char *strurl,char *strhost,char *filebuf,int filelen,char *strresult,int &resultle;); DECLDIR int KpDownLoadFile(char *strurl,char *strhost,char *filebuf,int &filelen;,char *strresult,int &resultle;); #ifdef __cplusplus } #endif

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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