www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't pass [] to extern function object method

reply frame <frame86 live.com> writes:
I have a DLL in D-code which returns an object and want to pass a 
struct S[] to a member function of that object. The first element 
is passed correctly, the rest is just garbage. In fact the next 
item is just a single byte with value 0x11 following some 0x00.

It doesn't matter if I'm using S[], S[]* or S* with .ptr. The 
length of the array is correct but the data isn't except the 
first item.

Is this a trap because of extern function? How can I access the 
next item? Increasing the pointer is equivalent with S[1].
Nov 16 2020
parent reply Jack <jckj33 gmail.com> writes:
On Monday, 16 November 2020 at 21:31:44 UTC, frame wrote:
 I have a DLL in D-code which returns an object and want to pass 
 a struct S[] to a member function of that object. The first 
 element is passed correctly, the rest is just garbage. In fact 
 the next item is just a single byte with value 0x11 following 
 some 0x00.

 It doesn't matter if I'm using S[], S[]* or S* with .ptr. The 
 length of the array is correct but the data isn't except the 
 first item.

 Is this a trap because of extern function? How can I access the 
 next item? Increasing the pointer is equivalent with S[1].
What is the function prototype like and how are you declaring that struct?
Nov 16 2020
parent reply frame <frame86 live.com> writes:
On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote:

 What is the function prototype like and how are you declaring 
 that struct?
The struct is very simple, it contains: struct S { SysTime a; ulong b; double c; ubyte[] d; string e; } And I tried: bool foo(S[] params); // passing a S[] bool foo(S[]* params); // passing a &S[] bool foo(S* params); // passing a S.ptr
Nov 16 2020
parent reply frame <frame86 live.com> writes:
On Monday, 16 November 2020 at 22:22:42 UTC, frame wrote:
 On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote:

 What is the function prototype like and how are you declaring 
 that struct?
The struct is very simple, it contains:
I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context.
Nov 18 2020
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote:
 I found the "bug". It was caused by a debug {} statement within 
 a struct method. I assume that the debug symbol is just 
 incompatible called from the DLL context.
Were the DLL and main program built in different modes (debug/release)? Then this problem is understandable. Otherwise I find this surprising, and probably worth a bug report? — Bastiaan.
Nov 18 2020
parent frame <frame86 live.com> writes:
On Thursday, 19 November 2020 at 07:46:20 UTC, Bastiaan Veelo 
wrote:
 On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote:
 I found the "bug". It was caused by a debug {} statement 
 within a struct method. I assume that the debug symbol is just 
 incompatible called from the DLL context.
Were the DLL and main program built in different modes (debug/release)? Then this problem is understandable. Otherwise I find this surprising, and probably worth a bug report? — Bastiaan.
No, but the DLL was compiled with -debug flag which enables an additional member that the main program cannot see. I think that is the explaination. In fact the flag was not set on the main program.
Nov 19 2020