请教 c++builder xe2 动态调用dll方法
dll文件名是clntTransfer.dll
#include <vcl.h>
#include <windows.h>
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <IdAntiFreezeBase.hpp>
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdConnectThroughHttpProxy.hpp>
#include <IdCustomTransparentProxy.hpp>
#include <IdIOHandler.hpp>
#include <IdIOHandlerSocket.hpp>
#include <IdIOHandlerStack.hpp>
#include <IdSocks.hpp>
#include <IdTCPClient.hpp>
#include <IdTCPConnection.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.IdAntiFreeze.hpp>
#include <Vcl.ExtCtrls.hpp>
#pragma hdrstop
extern "C" __declspec(dllexport) __stdcall int MyTest(int,int);
#pragma argsused
TIdTCPClient *UploadClient;
TIdIOHandlerStack *IdIOHandlerStack1;
TIdAntiFreeze *IdAntiFreeze1;
TIdConnectThroughHttpProxy *IdConnectThroughHttpProxy1;
TIdSocksInfo *IdSocksInfo1;
UnicodeString srvPort,srvIP;
TProgressBar *ProgressBar1;
//-----------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
__declspec(dllexport) __stdcall int MyTest(int n1,int n2)
{
int t;
t= n1*n2;
return t;
}
//==========================================================
dll调用;
int __stdcall (*MyTest)(int,int);
void __fastcall TfrClient::Button2Click(TObject *Sender)
{
HINSTANCE hdll;
AnsiString proname;
FARPROC pr;
UnicodeString dllflName=ExtractFilePath(Application->ExeName)+"clntTransfer.dll";
try {
if (hdll==NULL) {
hdll=LoadLibrary(L"clntTransfer.dll");
}
if (hdll!=NULL) {
proname="MyTest";
pr=GetProcAddress(hdll,"MyTest");
if (pr!=NULL) {
MyTest=(int __stdcall (__cdecl *)(int,int))pr;
ShowMessage(MyTest(10,20));
} else {
ShowMessage("打开函数错误。");
}
}else {
ShowMessage("打开动态链接库错误。");
}
} __finally {
FreeLibrary(hdll);
}
}
我在c++builder xe2 上做的。
在动态导入dll时候是成功的但是取函数地址时取不到出现“打开函数错误。”信息。
我在网上找了很多都是这种方法,难道xe2 例外吗?
请高手帮忙看看。
#include <vcl.h>
#include <windows.h>
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <IdAntiFreezeBase.hpp>
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdConnectThroughHttpProxy.hpp>
#include <IdCustomTransparentProxy.hpp>
#include <IdIOHandler.hpp>
#include <IdIOHandlerSocket.hpp>
#include <IdIOHandlerStack.hpp>
#include <IdSocks.hpp>
#include <IdTCPClient.hpp>
#include <IdTCPConnection.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.IdAntiFreeze.hpp>
#include <Vcl.ExtCtrls.hpp>
#pragma hdrstop
extern "C" __declspec(dllexport) __stdcall int MyTest(int,int);
#pragma argsused
TIdTCPClient *UploadClient;
TIdIOHandlerStack *IdIOHandlerStack1;
TIdAntiFreeze *IdAntiFreeze1;
TIdConnectThroughHttpProxy *IdConnectThroughHttpProxy1;
TIdSocksInfo *IdSocksInfo1;
UnicodeString srvPort,srvIP;
TProgressBar *ProgressBar1;
//-----------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
__declspec(dllexport) __stdcall int MyTest(int n1,int n2)
{
int t;
t= n1*n2;
return t;
}
//==========================================================
dll调用;
int __stdcall (*MyTest)(int,int);
void __fastcall TfrClient::Button2Click(TObject *Sender)
{
HINSTANCE hdll;
AnsiString proname;
FARPROC pr;
UnicodeString dllflName=ExtractFilePath(Application->ExeName)+"clntTransfer.dll";
try {
if (hdll==NULL) {
hdll=LoadLibrary(L"clntTransfer.dll");
}
if (hdll!=NULL) {
proname="MyTest";
pr=GetProcAddress(hdll,"MyTest");
if (pr!=NULL) {
MyTest=(int __stdcall (__cdecl *)(int,int))pr;
ShowMessage(MyTest(10,20));
} else {
ShowMessage("打开函数错误。");
}
}else {
ShowMessage("打开动态链接库错误。");
}
} __finally {
FreeLibrary(hdll);
}
}
我在c++builder xe2 上做的。
在动态导入dll时候是成功的但是取函数地址时取不到出现“打开函数错误。”信息。
我在网上找了很多都是这种方法,难道xe2 例外吗?
请高手帮忙看看。
...全文
相关推荐
Delphi Indy需要的两个OpenSSL DLL
解决了Indy没有自带OpenSSL DLL的问题 32位的,XE10-XE11.2亲测能用 放到程序目录下就可以了 觉得有用的麻烦给个5星,谢谢
Delphi 13.1控件之TMS FNC UI Pack v7.2.0.0 for Delphi & CB XE7-13 Florence Full Source.rar
Delphi 13.1控件之TMS FNC UI Pack v7.2.0.0 for Delphi & CB XE7-13 Florence Full Source.rar
MyDAC7.6.11D7-XE3-10.2-10.3-FS.rar
MyDAC7.6.11D7-XE3-10.2-10.3-FS.rar
c++ Builder 中如何调用VC编写的动态链接库
c++ Builder 中如何调用VC编写的动态链接库
c++builder XE 10 封装log4z日志管理动态库
c++builder XE10实现日志分类管理,接口有写入,更改路径和名称、日志打印最低等级


