steamapiregistercallresult( classType, func )
Where classType is the name of the class that inherits from CCallResult, and func is the name of the member function that will handle the result. The function must have the signature:
void func( Param_t *pParam, bool bIOFailure, SteamAPICall_t hSteamAPICall )
Where Param_t is the type of the structure that contains the result data, bIOFailure is a flag indicating whether there was an IO failure during the call, and hSteamAPICall is the handle of the call.
To use the macro, you need to define a class that inherits from CCallResult, and implement a member function that will handle the result. For example, suppose you want to use the Steam API function ISteamUserStats::RequestUserStats, which requests statistics for a user. The function returns a handle of type SteamAPICall_t, and the result data is contained in a structure of type UserStatsReceived_t. You can define a class like this:
steam api register call result example
steam api register call result callback
steam api register call result error
steam api register call result documentation
steam api register call result usage
steam api register call result tutorial
steam api register call result c++
steam api register call result python
steam api register call result unity
steam api register call result unreal engine
steam api register call result c#
steam api register call result java
steam api register call result lua
steam api register call result javascript
steam api register call result golang
steam api register call result rust
steam api register call result swift
steam api register call result kotlin
steam api register call result dart
steam api register call result ruby
steam api register call result php
steam api register call result perl
steam api register call result r
steam api register call result matlab
steam api register call result julia
steam api register call result haskell
steam api register call result scala
steam api register call result clojure
steam api register call result lisp
steam api register call result erlang
steam api register call result elixir
steam api register call result ocaml
steam api register call result f#
steam api register call result delphi
steam api register call result pascal
steam api register call result fortran
steam api register call result cobol
steam api register call result assembly
steam api register call result basic
steam api register call result prolog
steam api register call result logic programming
steam api register call result functional programming
steam api register call result object-oriented programming
steam api register call result procedural programming
steam api register call result declarative programming
steam api register call result imperative programming
steam api register call result concurrent programming
steam api register call result distributed programming
steam api register call result parallel programming
steam api register call result reactive programming
class CUserStatsCallResult : public CCallResult<CUserStatsCallResult, UserStatsReceived_t> public: CUserStatsCallResult() m_hSteamAPICall = k_uAPICallInvalid; void OnUserStatsReceived( UserStatsReceived_t *pParam, bool bIOFailure, SteamAPICall_t hSteamAPICall ); ;
The class inherits from CCallResult<CUserStatsCallResult, UserStatsReceived_t>, which means it can handle results of type UserStatsReceived_t. It also has a member variable m_hSteamAPICall, which will store the handle of the call. The constructor initializes it to an invalid value. The member function OnUserStatsReceived is the callback function that will be called when the result is available. It has the same signature as required by the macro.
The implementation of the function can look something like this:
void CUserStatsCallResult::OnUserStatsReceived( UserStatsReceived_t *pParam, bool bIOFailure, SteamAPICall_t hSteamAPICall )
The function first checks if the handle of the call matches the one stored in the class. If not, it returns without doing anything. This is to avoid handling results from other calls that may have the same handle value. Then, it checks if there was an IO failure during the call. If so, it prints an error message and returns. Next, it checks if the result data contains the correct user ID and game ID. If not, it returns without doing anything. This is to avoid handling results from other users or games that may have requested stats. Finally, it prints some information from the result data, such as the game ID, user ID, and some stat values. It also shows how to get stat values and achievements using the ISteamUserStats interface. At the end, it calls Cancel, which is a member function of CCallResult that cancels the call result and frees the memory associated with it.
To use this class, you need to create an instance of it and register it with the macro before calling the Steam API function. For example:
CUserStatsCallResult g_UserStatsCallResult; // Global variable void RequestUserStats() // Register the call result steamapiregistercallresult( g_UserStatsCallResult, OnUserStatsReceived ); // Call the Steam API function ISteamUserStats *pUserStats = SteamUserStats(); SteamAPICall_t hSteamAPICall = pUserStats->RequestUserStats( STEAM_USER_ID ); // Store the handle g_UserStatsCallResult.SetGameserverFlag(); // Optional, see below g_UserStatsCallResult.SetCall( hSteamAPICall );
The global variable g_UserStatsCallResult is an instance of the class we defined earlier. The function RequestUserStats is where we request the user stats from Steam. First, we register the call result with the macro, passing the instance of the class and the name of the callback function. Then, we call the Steam API function RequestUserStats, passing the user ID we want to get stats for. The function returns a handle of type SteamAPICall_t, which we store in a local variable. Next, we call SetGameserverFlag, which is an optional member function of CCallResult that tells Steam to prioritize this call over other calls from this game server. This is useful if you are running a dedicated server and want to get stats for players quickly. Finally, we call SetCall, which is another member function of CCallResult that sets the handle of the call and starts waiting for the result.
That's it! Now, whenever Steam has the result ready, it will call our callback function automatically and pass it the result data. We don't need to worry about checking or canceling handles manually.
References
[1]: Steam Web API - Valve Developer Community
[2]: steam_api.h (Steamworks Documentation)
[3]: Steamapiregistercallresult Fixed: A Step-by-Step Tutorial St
0493d141df