DLL: (const char *paramNames[],size_t numParams)

Basile B. b2.temp at gmx.com
Mon Jul 9 11:39:46 UTC 2018


On Monday, 9 July 2018 at 11:10:01 UTC, Basile B. wrote:
> On Monday, 9 July 2018 at 10:56:18 UTC, Andre Pany wrote:
>> On Monday, 9 July 2018 at 10:38:54 UTC, Basile B. wrote:
>>> On Monday, 9 July 2018 at 10:33:03 UTC, Andre Pany wrote:
>>> Hi, no it's not correct i think, right translation would be
>>>
>>>     extern(C) void GetParamNames(const char** paramNames, 
>>> size_t numParams);
>>>
>>> If you use the D array syntax you'll get into troubles 
>>> because of ABI i think.
>>>
>>> Baz.
>>
>> Thanks, it seems I also have to allocate the pointer before 
>> with the numbers of numParams.
>> In python the code looks s.th. like this
>>
>> self.output_names = (c_char_p * self.number_outputs)()
>>
>> Do you know that is the equivalent in D?
>>
>> Kind regards
>> André
>
> you don't need to allocate but to retrieve each string, do 
> something like this:
>
>     foreach(i; 0 .. numParams)
>     {
>         string p = fromStringz(paramNames + i)
>     }
>
> although i have a doubt for pointer arithmetic. Maybe it should 
> be incremented by
>
>     i * size_t.sizeof
>
> since char.sizeof is 1. Maybe someone else will be more helpful 
> here.
>
> Baz.

Ok, i've read your other answers and it seems that you have a way 
to test so i think you'll figure it out yourself, but you don't 
need to alloc. Once the fromStringz verified to be good maybe 
dup/idup in case the C lib free the stuff but that's all.


More information about the Digitalmars-d-learn mailing list