www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - extern (c) struct ?

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Mar 08 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
Mar 08 2018
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Mar 08 2018