Thread overview
extern (c) struct ?
Mar 08, 2018
Robert M. Münch
Mar 08, 2018
Adam D. Ruppe
Mar 09, 2018
Robert M. Münch
March 08, 2018
I have a pretty complex struct with C++ typed private members etc. in it which I want to use from D.

Obviously I don't want to/can't rebuild the struct definiton in D and I don't need access to all the members just some simple C API ones are enough.

How can I get access to this struct from D? I mean something like:

alias my_d_struct = extern(c) my_cpp_struct;


-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

March 08, 2018
On Thursday, 8 March 2018 at 15:51:53 UTC, Robert M. Münch wrote:
> I have a pretty complex struct with C++ typed private members etc. in it which I want to use from D.

How are you accessing it? If it is by pointer only passing it to methods, you can simply:

struct my_cpp_struct;

and define functions:

extern(C)
void foo(my_cpp_struct* arg);


then just declare functions you need and always use as opaque pointer.
March 09, 2018
On 2018-03-08 16:03:57 +0000, Adam D. Ruppe said:

> How are you accessing it? If it is by pointer only passing it to methods, you can simply:
> 
> struct my_cpp_struct;
> 
> and define functions:
> 
> extern(C)
> void foo(my_cpp_struct* arg);

Hi, :-/ seems I was a bit confused by all the backs and forth on my side. Yes, this will of course work and is sufficient to move on. And the defined functions can be aliased, right?

> then just declare functions you need and always use as opaque pointer.

When running in the VisualD environment in debugging mode, I can't dive into the my_cpp_struct. Seems the debugger doesn't uncover opaque pointers. Or do I need to tell it somehow about it?

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster