How to return an instance from a DLL?

2019-05-06 13:50发布

I am programming a DLL. I have to return an instance of TBitmap to the host application. The DLL has another UNIT, wich is a Form, that it has a TImageList for storing images. I wrote a function that I want to return an Image from the TImageList (from the DLL to the host application. How can I do this?

Thanks, Yulién.

4条回答
Summer. ? 凉城
2楼-- · 2019-05-06 14:39

Basically what you need to do is not return an object. In this case you want to return bitmap, why not just return HBitmap handle?

查看更多
倾城 Initia
3楼-- · 2019-05-06 14:39

Objects are combinations of code and data. A normal DLL does not support that, because it only supports the C Application Binary Interface (C ABI) but there is a kind of DLLs that does: BPL files. In other words, you need to create a .bpl file and not a .dll file. This requires both that file and the user to be Delphi, of course.

查看更多
欢心
4楼-- · 2019-05-06 14:47

You can't return an object per se, but you can return a pointer to an object. Refer to Mastering Delphi 6 and this description of Vtables in delphi.

查看更多
Animai°情兽
5楼-- · 2019-05-06 14:51

Read this old thread on borland.public.delphi.nativeapi: Delphi Object in DLL - does this work?.

The link to a .pdf in the last message is gone, but thanks to Internet Archive Wayback Machine one can download it (look at Exporting Objects from DLLs at page 412).

Edit: it turns out that book's interesting part, for our purpose, is also available @ Google Books, so one can read it on-line.

查看更多
登录 后发表回答