Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread rikki cattermole via Digitalmars-d-learn
On 10/06/2018 11:28 PM, cc wrote: Woops, that GetIntPtr came from the .cs header in the same folder as the C++ headers distributed with the SDK, that'll teach me to ctrl+f "class ISteamClient" in all open files and copy/paste before reading. Stay with the c/c++ headers for c/c++ code. We

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread cc via Digitalmars-d-learn
On Sunday, 10 June 2018 at 10:47:58 UTC, rikki cattermole wrote: On 10/06/2018 10:29 PM, cc wrote: And it successfully fires the 3-arg Run method of the callback object. However for some reason the function table of the ISteamClient seems to be off by one.. it kept calling the wrong methods

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread rikki cattermole via Digitalmars-d-learn
On 10/06/2018 10:29 PM, cc wrote: And it successfully fires the 3-arg Run method of the callback object. However for some reason the function table of the ISteamClient seems to be off by one.. it kept calling the wrong methods until I commented one out, in this case GetIntPtr() as seen above,

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread cc via Digitalmars-d-learn
On Sunday, 10 June 2018 at 02:57:34 UTC, evilrat wrote: Only subsystems getters like SteamUser() or SteamInventory() requires wrapping. I really can't understand why they ever choose to silently ignore registering callbacks received with C API systems handles... Thanks to the information

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-09 Thread evilrat via Digitalmars-d-learn
On Sunday, 10 June 2018 at 01:35:40 UTC, cc wrote: On Saturday, 9 June 2018 at 14:11:13 UTC, evilrat wrote: However steam devs decided to shield actual pointer and return pointer sized integer when C API is used(or they just screw up?). Anyway, the pointers for subsystems returned by context

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-09 Thread cc via Digitalmars-d-learn
On Saturday, 9 June 2018 at 14:11:13 UTC, evilrat wrote: However steam devs decided to shield actual pointer and return pointer sized integer when C API is used(or they just screw up?). Anyway, the pointers for subsystems returned by context calls on C++ API and mirrored C API calls are

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-09 Thread evilrat via Digitalmars-d-learn
On Saturday, 9 June 2018 at 03:14:13 UTC, cc wrote: On Saturday, 9 June 2018 at 03:07:39 UTC, cc wrote: I've put together a simplified test program here (124KB): Here is a pastebin of the D source file updated with some additional comments at the end with the callback class definitions from

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
Sample output: Initializing. User logged on: true Starting request. hid: 4838393704146785693 .. Request completed: NumberOfCurrentPlayers_t(1, 5828) Terminating. Not present: any indication that the registered callresult was executed.

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Saturday, 9 June 2018 at 03:07:39 UTC, cc wrote: I've put together a simplified test program here (124KB): Here is a pastebin of the D source file updated with some additional comments at the end with the callback class definitions from the original header files

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Friday, 8 June 2018 at 07:32:54 UTC, evilrat wrote: On Friday, 8 June 2018 at 06:59:51 UTC, cc wrote: On Friday, 8 June 2018 at 02:52:10 UTC, Mike Parker wrote: On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread evilrat via Digitalmars-d-learn
On Friday, 8 June 2018 at 06:59:51 UTC, cc wrote: On Friday, 8 June 2018 at 02:52:10 UTC, Mike Parker wrote: On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any insight to provide it would be greatly appreciated, thanks!

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Friday, 8 June 2018 at 02:52:10 UTC, Mike Parker wrote: On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any insight to provide it would be greatly appreciated, thanks! I've not used any of the C++ interfacing features

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread evilrat via Digitalmars-d-learn
On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: I've defined it in D, as per https://dlang.org/spec/cpp_interface.html#classes : change this to class, or even abstract class as shown in example extern(C++) { interface CCallbackBase { //this() { m_nCallbackFlags

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-07 Thread Mike Parker via Digitalmars-d-learn
On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any insight to provide it would be greatly appreciated, thanks! I've not used any of the C++ interfacing features yet, but my understanding is the extern(C++) has to apply

Passing C++ class to DLL for callbacks from D (Steam)

2018-06-07 Thread cc via Digitalmars-d-learn
Hello, I'm attempting to interface with the Steam API DLL in D and running into some trouble working with callbacks. I'm aware there's already a project here http://derelict-steamworks.dub.pm/ but it seems to have not yet addressed the same issue. Steam provides ways to poll for whether an

Re: Callbacks in D

2016-10-06 Thread Kagamin via Digitalmars-d-learn
https://dlang.org/phobos/std_concurrency.html#.receive

Callbacks in D

2016-10-06 Thread DLearner via Digitalmars-d-learn
Please, could someone post here, or provide a link to, some simple, debugged examples. Best regards

Callbacks in D as void functions

2014-11-13 Thread Wsdes via Digitalmars-d-learn
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

Re: Callbacks in D as void functions

2014-11-13 Thread bearophile via Digitalmars-d-learn
Wsdes: The wiki says that callback functions should be declared as integer functions, What's bad in returning void? Bye, bearophile

Re: Callbacks in D as void functions

2014-11-13 Thread Steven Schveighoffer via Digitalmars-d-learn
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:

Re: Callbacks in D as void functions

2014-11-13 Thread Adam D. Ruppe via Digitalmars-d-learn
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*);

Re: Callbacks in D as void functions

2014-11-13 Thread Wsdes via Digitalmars-d-learn
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

Re: Callbacks in D as void functions

2014-11-13 Thread Adam D. Ruppe via Digitalmars-d-learn
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,

Re: Callbacks in D as void functions

2014-11-13 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: Callbacks in D as void functions

2014-11-13 Thread Mike Parker via Digitalmars-d-learn
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