静态调用DLL

lysh137856 2004-12-06 02:44:45
有一MwNetGate.dll,里面有一函数:function ConnectOpen(const Uid: WideString; const Password: WideString;const ServerIP: WideString; ServerPort: Integer):Integer;
我把MwNetGate.dll转换成MwNetGate.lib,并Project->Add to Project把此文件加载到工程中后,
在.h中声明如下:int ConnectOpen(const WideString Uid,const WideString Password,const WideString ServerIP,int ServerPort);
然后调用:
 void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(ConnectOpen("13178930258","123456","61.242.89.115",8018)==0);
{
Application->MessageBox("成功!","成功",MB_OK);
}
else
{
Application->MessageBox("失败!","失败",MB_OK);
}

}
总是提示出错:[C++ Error] User_sendmsg.cpp(112): E2054 Misplaced else

请各位大侠指点!小弟感激不尽!
...全文
356 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
krakan 2004-12-13
  • 打赏
  • 举报
回复
先自己写一个usedll.h文件,把dll的入口函数,及自定义函数写进去,再把这个.h文件加到你的工程里就行了,在使用这个dll的.cpp文件头声名“include usedll.h ”
真如实观 2004-12-12
  • 打赏
  • 举报
回复
哦,你的DLL是Delphi写的,要bcb调用?在单元文件里声明吧。
真如实观 2004-12-12
  • 打赏
  • 举报
回复
我说不清楚,你不如找本书算了?
flowercity 2004-12-09
  • 打赏
  • 举报
回复
我说的很清楚了
lysh137856 2004-12-07
  • 打赏
  • 举报
回复
谢谢大侠的指点!
如何用LoadLibrary函数直接读Dll读呀!
lfher 2004-12-07
  • 打赏
  • 举报
回复
你用LoadLibrary函数直接读一下Dll,看这个函数有没有
lysh137856 2004-12-07
  • 打赏
  • 举报
回复
那如果BCB中要引用这个DLL,应如何做,谢谢!小弟刚用BCB!
lysh137856 2004-12-07
  • 打赏
  • 举报
回复
谢谢楼上的大侠!
我试了一下,还是有如下错误:
[Linker Error] Unresolved external 'ConnectOpen' referenced from E:\SENDMSG\USER_SENDMSG.OBJ
flowercity 2004-12-07
  • 打赏
  • 举报
回复
一样的要转换
lysh137856 2004-12-07
  • 打赏
  • 举报
回复
如果是Delphi提供的DLL,应如何以组件方式加到BCB中呢?
flowercity 2004-12-07
  • 打赏
  • 举报
回复
对于vc提供的dll
首先 implib *.lib *.dll 转换
使用方法有两种
一:Project->Add to Project
二:在工程文件里面的最上面添加#pragma link "*.lib"

在使用这个dll中提供的函数的文件里面,包含这个dll的*.h文件,同时dll、lib、h文件在当前目录下
lysh137856 2004-12-07
  • 打赏
  • 举报
回复
谢谢大侠!

我想再问:.dll文件可以以组件方式加到BCB中吗?应如何加呢?
xiaomatian 2004-12-07
  • 打赏
  • 举报
回复
你用LoadLibrary函数直接读一下Dll。具体方法搜一下,很多的
lfher 2004-12-06
  • 打赏
  • 举报
回复
你的函数声明是不是在TForm定义里面,必须在外边声明:
extern "C" __declspec(dllimport) __stdcall int ConnectOpen(const WideString Uid,const WideString Password,const WideString ServerIP,int ServerPort);
class TForm1: public TForm
{
__published: // IDE-managed Components

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);

};
lysh137856 2004-12-06
  • 打赏
  • 举报
回复
我已经把MwNetGate.dll转换成MwNetGate.lib,并Project->Add to Project把此文件加载到工程中了呀
constantine 2004-12-06
  • 打赏
  • 举报
回复
这个错误是你声明了函数,但是没有实现
你有没有加 lib 到工程里啊,要不估计就是dll有问题
lysh137856 2004-12-06
  • 打赏
  • 举报
回复
谢谢大侠赐教!
试了一下,错误:[Linker Error] Unresolved external 'ConnectOpen' referenced from E:\SENDMSG\USER_SENDMSG.OBJ
chiengod 2004-12-06
  • 打赏
  • 举报
回复
在.h中声明如下:extern "C" __declspec(dllimport) __stdcall int ConnectOpen(const WideString Uid,const WideString Password,const WideString ServerIP,int ServerPort);
lysh137856 2004-12-06
  • 打赏
  • 举报
回复
[Linker Error] Unresolved external 'TForm1::ConnectOpen(const System::WideString, const System::WideString, const System::WideString, int)' referenced from E:\SENDMSG\USER_SENDMSG.OBJ
改了还是有这个错误!谢谢大侠赐教!
hailin10 2004-12-06
  • 打赏
  • 举报
回复
文件夹最好不要哟用中文名称
加载更多回复(5)

1,178

社区成员

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

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