关于 DLL 问题!

haidao17 2003-12-01 06:23:52
小弟 不知道 DLL 怎么调试
不知道 大侠们 是怎样调试DLL的,请不吝言辞介绍下你们的调试方法!
如果人多分不够,会加分的!
...全文
46 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
haidao17 2003-12-03
  • 打赏
  • 举报
回复
谢谢大家
晚上来揭贴!
hswu 2003-12-02
  • 打赏
  • 举报
回复
当然可以,你调试别的程序怎么样现在就怎么样,你试试就知道了:)
ljianq 2003-12-02
  • 打赏
  • 举报
回复
可以啊。
haidao17 2003-12-02
  • 打赏
  • 举报
回复
“这时你就跟调试普通程序一样调试动态库了.”
我能为 DLL 设置断点 来调试查看吗???
hswu 2003-12-02
  • 打赏
  • 举报
回复
1.写如动态库程序并生成动态库
2.写动态库调用程序并编绎成可执行文件
3.在动态库工程中选Run->Parameters->Host Application 中输入2中的可执行文件
4.运行,这时你就跟调试普通程序一样调试动态库了.
huoniao1976 2003-12-02
  • 打赏
  • 举报
回复
.h
private: // User declarations
HINSTANCE DLLInst,dll1;
void (__stdcall*LC)();
void (__stdcall*yy1)();
void (__stdcall*yy2)();
void (__stdcall*yy3)();
void (__stdcall*sw1)(AnsiString ff);
void (__stdcall*pb)();
void (__stdcall*hide1)();
void (__stdcall*show1)();
.cpp
void __fastcall TFormmain::FormCreate(TObject *Sender)
{ dll1=LoadLibrary("huoniao.dll");
if (dll1)
{ LC=(void (__stdcall*)()) GetProcAddress(dll1,"LC");
if (LC)
{}
else
ShowMessage("没有发现lc转换函数");
yy1=(void (__stdcall*)()) GetProcAddress(dll1,"yy1");
if (yy1)
{}
else
ShowMessage("没有发现yy1转换函数");
sw1=(void (__stdcall*)(AnsiString ff)) GetProcAddress(dll1,"sw1");
if (sw1)
{}
else
ShowMessage("没有发现sw1转换函数");
pb=(void (__stdcall*)()) GetProcAddress(dll1,"pb");
if (pb)
{}
else
ShowMessage("没有发现pb转换函数");
hide1=(void (__stdcall*)()) GetProcAddress(dll1,"hide1");
if (hide1)
{}
else
ShowMessage("没有发现hide1转换函数");
show1=(void (__stdcall*)()) GetProcAddress(dll1,"show1");
if (show1)
{}
else
ShowMessage("没有发现show1转换函数");
yy2=(void (__stdcall*)()) GetProcAddress(dll1,"yy2");
if (yy2)
{}
else
ShowMessage("没有发现yy2转换函数");
yy3=(void (__stdcall*)()) GetProcAddress(dll1,"yy3");
if (yy3)
{}
else
ShowMessage("没有发现yy3转换函数");
}
else
ShowMessage("没有发现动态连接库");
}
geniusdhc 2003-12-02
  • 打赏
  • 举报
回复
1.写如动态库程序并生成动态库
2.写动态库调用程序并编绎成可执行文件
3.在动态库工程中选Run->Parameters->Host Application 中输入2中的可执行文件
4.运行,这时你就跟调试普通程序一样调试动态库了.
----------------------
我就用这种方法.
penu 2003-12-02
  • 打赏
  • 举报
回复
需要制作一个测试dll的host程序,用以测试DLL
然后在DLL的项目选项中设定run参数,指定调用DLL的host程序文件
接下来你即可在DLL项目下进行运行调试。
ThinkX 2003-12-02
  • 打赏
  • 举报
回复
需要写一个宿主程序,在其中调用你的dll。
然后用Run->Parameters->Host Application设置宿主程序,启动后就可以了。
踏岸寻柳 2003-12-02
  • 打赏
  • 举报
回复
需要这么麻烦吗!?
在BCB6里面直接打开你的主程序,再打开*.dll工程的文件,直接下断点就是了。
pzoon 2003-12-01
  • 打赏
  • 举报
回复
DLL
//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// 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 "C" __declspec(dllexport) int PlusNum(int x,int y)
{
return x+y;
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) int MinusNum(int x,int y)
{
return x-y;
}
pzoon 2003-12-01
  • 打赏
  • 举报
回复
动态:
//---------------------------------------------------------------------------

#ifndef UMain2H
#define UMain2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
typedef int (dmax)(int x,int y); //dmax代表DLL函数,后面是参数 1 fang fa
//int (__stdcall *max)(int x,int y); //2 fang fa
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


。CPP
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UMain2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
// 1 fang fa
dmax* max1; //dmax代表DLL的函数
HINSTANCE hd;
hd = LoadLibrary("dll2.dll");
max1 = (dmax*)GetProcAddress(hd,"_max");
Edit3->Text = (*max1)(StrToInt(Edit1->Text),StrToInt(Edit2->Text));
FreeLibrary(hd);
}
//---------------------------------------------------------------------------
pzoon 2003-12-01
  • 打赏
  • 举报
回复
静:
//---------------------------------------------------------------------------

#ifndef UMainH
#define UMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
extern "C" __declspec(dllimport) int PlusNum(int x,int y);
extern "C" __declspec(dllimport) int MinusNum(int x,int y);
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TEdit *Edit2;
TComboBox *ComboBox1;
TEdit *Edit3;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
。cpp
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (ComboBox1->Text == "1")
{
Edit3->Text = PlusNum(StrToInt(Edit1->Text),StrToInt(Edit2->Text));
}
if (ComboBox1->Text == "2")
{
Edit3->Text = MinusNum(StrToInt(Edit1->Text),StrToInt(Edit2->Text));
}

}
zzjzln 2003-12-01
  • 打赏
  • 举报
回复
编译连接后生成DLL,必须生成LIB库,用BCB中IMPLIB生成。

新建一工程,在工程文件中填加:USELIB("PATH\文件名.LIB");

并打开DLL原文件。

编译、运行工程,即可在在程序中使用DLL文件的函数或DLL源文件添加断点进行调试。
IAMCDYY2003 2003-12-01
  • 打赏
  • 举报
回复
打开两个bcb来调试
Gucai 2003-12-01
  • 打赏
  • 举报
回复
不清楚,不过你可以先论坛里搜索搜索一下,说不定会有很多资料。
HenryGo 2003-12-01
  • 打赏
  • 举报
回复
up

13,824

社区成员

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

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