Hi all,
I already posted this to Code Project, but maybe you have a
solution for my problem.
I am trying to write a wrapper for a C API in D. In C I have the
following definition of a callback type:
typedef void (*Callback)(void*);
In a struct all members are of the type Callback. In the main
Wsdes:
The wiki says that callback
functions should be declared as integer functions,
What's bad in returning void?
Bye,
bearophile
On 11/13/14 9:49 AM, Wsdes wrote:
Hi all,
I already posted this to Code Project, but maybe you have a
solution for my problem.
I am trying to write a wrapper for a C API in D. In C I have the
following definition of a callback type:
typedef void (*Callback)(void*);
in D, this would be:
On Thursday, 13 November 2014 at 14:50:00 UTC, Wsdes wrote:
I am trying to write a wrapper for a C API in D. In C I have the
following definition of a callback type:
typedef void (*Callback)(void*);
I would translate this directly to D:
extern(C) alias Callback = void function(void*);
On Thursday, 13 November 2014 at 15:17:45 UTC, Adam D. Ruppe
wrote:
On Thursday, 13 November 2014 at 14:50:00 UTC, Wsdes wrote:
I am trying to write a wrapper for a C API in D. In C I have
the
following definition of a callback type:
typedef void (*Callback)(void*);
I would translate this
On Thursday, 13 November 2014 at 15:58:34 UTC, Wsdes wrote:
void MyDtaCB(void* v){
// Do stuff
}
Events.OnData = cast(Callback) MyDtaCB;
this compiles but might crash, the extern(C) is important on a
callback to be used from a C program. I'd really recommend adding
that to the function,
On 11/13/14 10:58 AM, Wsdes wrote:
First of all, the link to the wiki that has an example of callbacks in C
and D:
http://dlang.org/interfaceToC.html
Secondly, I tried your code and that was exactly what I was thinking and
what I tried before. Then I thought I'd turn to the wiki example, so
On 11/14/2014 12:58 AM, Wsdes wrote:
Anyway, I think I got the problem solved. Well, there seems to never
have been any problem as I am taught now. I asked the developer of the C
API this morning if I should try to implement the callback functions
redundantly in D and he said he will have a