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

cc cc at nevernet.com
Sun Jun 10 11:28:48 UTC 2018


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 until I commented one out, in this case 
>> GetIntPtr() as seen above, then everything seemed to line up.  
>> Not sure what the proper way to ensure it matches the C++ 
>> layout here, but at least it seems to be mostly working for 
>> now.  Thanks again!
>
> Ugh what GetIntPtr? Unless of course this header file is 
> wrong[0].
>
> Make the members match exactly, order and everything and it 
> should "just work".
>
> [0] 
> https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/steam/isteamclient.h#L113

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.

Anyway I played around with it some more and found the one single 
line that was causing the problem.  It needs this:

HSteamPipe SteamAPI_GetHSteamPipe();

rather than one of these:

HSteamPipe SteamAPI_ISteamClient_CreateSteamPipe(ISteamClient 
instancePtr);
virtual HSteamPipe CreateSteamPipe() = 0;

It looks like the pipe is already created upon initializing and 
calling CreateSteamPipe creates a secondary one that doesn't 
receive callbacks. SteamAPI_GetHSteamPipe is called inline to 
retrieve the current pipe on initialization of the the classed 
version of the API, but the documentation doesn't mention it 
exists at all, leading to confusion when using the flat version.  
Well, mystery solved.



More information about the Digitalmars-d-learn mailing list