将二进制数据传递给 D7 中的 dll 函数
谁能给我提供传递任意数量字节的工作示例 通过参数传递给dll函数?
我想在没有任何额外内存单元的情况下执行此操作,仅在基本 Windows 类型上进行操作。
每次调用我需要“发送”大约 300 kb 的数据。
在客户端分配的内存在客户端也应该是空闲的吗?
Could anyone provide me with working example of passing arbitrary number of bytes
through the parameter to a dll function?
I would like to do it without any extra memory unit, just only operate on basic windows types.
I need to "send" about 300 kb data per each call.
Should the memory allocated on the client side be free also on the client side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DLL 函数应该如下所示:
假设您从另一个 Delphi 模块调用它,则该调用可能如下所示:
最好定义一个需要在同一模块中分配和释放内存的接口。
上面的示例在调用者的模块中进行分配和释放。这意味着
Test
方法要么必须在返回之前完全处理Buffer
,要么在返回之前获取Buffer
内容的副本。现在,虽然可以在被调用者的模块中进行分配和释放,但这种情况不太常见。这种情况不太常见,因为这样做通常不太方便。它通常需要更多的 API 函数,或者可能更复杂的接口。当调用者无法确定缓冲区的适当大小时,您将被推入被调用者分配的路线。
当数据从调用者传递到被调用者时,调用者分配始终是最佳选择。当数据流向另一个方向时,被调用者分配更有可能是合适的。
The DLL function should look like this:
Assuming you are calling it from another Delphi module the call could look like this:
It is always preferable to define an interface which requires memory to be allocated and deallocated in the same module.
The above example allocates and deallocates in the caller's module. This means that the
Test
method would either have to process theBuffer
completely before returning, or take a copy of the contents ofBuffer
before returning.Now, whilst it is possible to have the allocation and deallocation in the callee's module, this is less common. It is less common because it is typically less convenient to do it this way. It often entails more API functions, or perhaps more a complex interface. You will be pushed into the route of callee allocation when the caller is not able to determine an appropriate size for the buffer.
When data is being passed from caller to callee than caller allocate is invariably the best choice. When the data flows in the other direction it is more likely that callee allocates would be appropriate.