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

Andre Pany andre at s-e-a-p.de
Mon Jul 9 11:07:03 UTC 2018


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é

If found this working, is this OK, or do I have a memory bug here?

         import core.stdc.stdlib: malloc, free;
         string[] result;

         size_t numOutputs = 4;
         const(char**) arr = cast (const(char**)) 
malloc(numOutputs * (char*).sizeof);

         auto status = GetParamNames(arr, numOutputs);

         for(int i = 0; i < numOutputs; i++)
         {
             const(char*) c = arr[i];
             result ~= c.fromStringz.dup;
         }

         free(cast(void*) arr);

Kind regards
André



More information about the Digitalmars-d-learn mailing list