在DLL里使用多线程的问题?????

Artas 2003-11-10 04:27:26
我的程序要调用我自己写的一个DLL,在这个DLL里再使用线程处理一些数据,有关DLL(包括多线程的代码)都在DLL.CPP文件里,代码如下:

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

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

class TMyThread : public TThread
{
private:
void __fastcall Execute(void);
public:
__fastcall TMyThread(void);
};

void __fastcall ThreadDone(TObject *Sender);// 线程结束时执行的函数
//-----------------------------------------------------------------------

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//-----------------------------------------------------------------------

__fastcall TMyThread::TMyThread()
: TThread(false)
{
}
//-----------------------------------------------------------------------

void __fastcall TMyThread::Execute()
{
ShowMessage("Execute");
}
//-----------------------------------------------------------------------

void __fastcall ThreadDone(TObject *Sender)
{
ShowMessage("ThreadDone");
}
//-----------------------------------------------------------------------

extern "C" __declspec(dllexport) void __stdcall Test()
{
TMyThread *MyThread = new TMyThread;
MyThread->OnTerminate = ThreadDone;
}
//-----------------------------------------------------------------------

一编译就是显示如下错误:
[C++ Error] Unit1.cpp(66): E2034 Cannot convert 'void (_fastcall *)(TObject *)' to 'void (_fastcall * (_closure )(TObject *))(TObject *)'

不知道怎么改??????????????????????
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ThinkX 2003-11-10
  • 打赏
  • 举报
回复
随便建一个类,将ThreadDone加上去就可以了
改为

struct SomeClass
{
void __fastcall ThreadDone(TObject *Sender);
};
void __fastcall SomeClass::ThreasDome(TObject *Sender)
{
// 写代码
}
要注意 __closure这个Borland扩展的关键字,是它使两种类型的函数指针不兼容的。
Artas 2003-11-10
  • 打赏
  • 举报
回复
但是各位,我这个DLL没有窗体啊??那怎么办啊?总不能为了这个整个空窗体吧?????
nightfallrove 2003-11-10
  • 打赏
  • 举报
回复
为什么呢?

谁解释一下,
netsys2 2003-11-10
  • 打赏
  • 举报
回复
这样就没有问题了:


//-----------------------------------------------------------------------
//放到主程序中
void __fastcall TFrmMain::ThreadDone(TObject *Sender)
{
ShowMessage("ThreadDone");
}

//这个也在主程序
void __stdcall Test()
{
TMyThread *MyThread = new TMyThread;
MyThread->OnTerminate = ThreadDone;
}
//-----------------------------------------------------------------------
sfemil 2003-11-10
  • 打赏
  • 举报
回复
其中一个解决方法就是 将线程终止时处理的函数定义到线程类中。

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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