[fpc-devel] Convert C++ Array[1] to FPC
Bram Kuijvenhoven
mailinglists.bram at kuijvenhoven.net
Sun Feb 24 13:31:33 CET 2008
Sooky Boo wrote:
> On 2/23/08, ik <idokan at gmail.com> wrote:
>> {$PACKRECORDS C}
>>
>> On Sat, Feb 23, 2008 at 5:59 AM, Sooky Boo <sookyboo at gmail.com> wrote:
>>>
>>> Please help I am unsure how to port from C++ to fpc this code.
>>> The function this must be passed to says that the structure pointer or
>> size
>>> is invalid.
>>>
>>> ----C++----
>>>
>>> typedef struct _SSLPROTOCOLS {
>>> DWORD dwCount;
>>> SSLPROTOCOL ProtocolList[1]; // array of 'count' structures
>>> } SSLPROTOCOLS, FAR *LPSSLPROTOCOLS;
>>>
>>> ----My Attempt FPC Delphi Mode----
>>>
>>> type SSLPROTOCOLS = record
>>> dwCount :DWORD;
>>> ProtocolList : array[0..0] of SSLPROTOCOL; // array of 'count' structures
>>> end;
>
> Unfortunately still doesn't work :(
The actual size of the SSLPROTOCOLS struct/record should match the value of dwCount. Allocating such a record probably should go like
LPSSLPROTOCOLS(GetMem(sizeOf(SSLPROTOCOLS) + (dwCount - 1) * sizeOf(SSLPROTOCOL)))
Sometimes a dummy record is to be appended at the end of the array, similar to the null character at the end of a null-terminated string. In that case it is possible that this 'sentinel' record is not counted in dwCount, but you should still allocate the space of course. Please refer to the documentation of the header file (I hope there is).
I hope this helps.
Regards,
Bram
More information about the fpc-devel
mailing list