gpt4 book ai didi

delphi - 如何将 Bitmap 传递到 C++ 和 Delphi 中的 DLL 函数中?

转载 作者:行者123 更新时间:2023-12-03 15:21:12 28 4
gpt4 key购买 nike

我想创建一个 DLL 插件以与 Delphi 和其他语言(主要是 C++)一起使用。如何以 C++ 和 Delphi 友好的方式传递位图?它可以只是 Delphi TBitmap 的句柄吗? C++ 程序应该能够使用 WinApi 对其进行解码,对吗?

最佳答案

您不能传递 Delphi TBitmap 对象,因为它仅对 Delphi 代码有意义。您需要传递的是HBITMAP ,Windows 位图的句柄。

Delphi TBitmap 类只是 Windows 位图的包装器,并且可以提供 HBITMAP 句柄。您需要注意的是这些句柄的所有权。

如果您有 Delphi TBitmap,您可以通过调用 ReleaseHandle 获取 HBITMAP TBitmap 的方法。 ReleaseHandle 返回的句柄不再由 TBitmap 对象拥有和管理,这正是您想要的。您将该句柄传递给 C++ 代码并让它成为所有者。它负责处理该句柄。

ReleaseHandle 的文档说:

Returns the handle to the bitmap so that the TBitmap object no longer knows about the handle.

Use ReleaseHandle to disassociate the bitmap from the bitmap handle. Use it when you need to give a bitmap handle to a routine or object that will assume ownership (or destroy) the bitmap handle.

在另一个方向上,您的 Delphi 代码将收到 HBITMAP从 C++ 代码中获取所有权。通过分配给 TBitmap 实例的 Handle 属性来实现这一点。

详细信息因语言而异,但无论如何,所有语言都能够处理 HBITMAP

关于delphi - 如何将 Bitmap 传递到 C++ 和 Delphi 中的 DLL 函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15625158/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com