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

cc cc at nevernet.com
Sun Jun 10 10:29:59 UTC 2018


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 you supplied I was able to get it 
working without a wrapper, like so:

extern(C++) abstract class ISteamClient {
	//public abstract IntPtr GetIntPtr();
	public abstract uint CreateSteamPipe();
	public abstract bool BReleaseSteamPipe(uint hSteamPipe);
	public abstract uint ConnectToGlobalUser(uint hSteamPipe);
	public abstract uint CreateLocalUser(ref uint phSteamPipe,uint 
eAccountType);
	public abstract void ReleaseUser(uint hSteamPipe,uint hUser);
	public abstract ISteamUser GetISteamUser(uint hSteamUser,uint 
hSteamPipe,const(char)* pchVersion);
	...
	public abstract ISteamUserStats GetISteamUserStats(uint 
hSteamUser,uint hSteamPipe,const(char)* pchVersion);
	...
}

HSteamUser hSteamUser = SteamAPI_GetHSteamUser();
HSteamPipe hSteamPipe = SteamAPI_GetHSteamPipe();
auto steamClient = cast(ISteamClient) 
SteamInternal_CreateInterface(STEAMCLIENT_INTERFACE_VERSION);
auto userStats = steamClient.GetISteamUserStats(hSteamUser, 
hSteamPipe, STEAMUSERSTATS_INTERFACE_VERSION);
auto hid = 
SteamAPI_ISteamUserStats_GetNumberOfCurrentPlayers(userStats);
auto cbk = new CallResult!NumberOfCurrentPlayers_t();
SteamAPI_RegisterCallResult(cbk, hid);


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!


More information about the Digitalmars-d-learn mailing list