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?
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
Testmethod would either have to process theBuffercompletely before returning, or take a copy of the contents ofBufferbefore 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.