diff --git a/steamclient/steamclient.cpp b/steamclient/steamclient.cpp index a185c616..4dbbce4a 100644 --- a/steamclient/steamclient.cpp +++ b/steamclient/steamclient.cpp @@ -1,21 +1,37 @@ -#define WIN32_LEAN_AND_MEAN -// #include "dll.h" +#define WIN32_LEAN_AND_MEAN #include "Windows.h" #ifdef _WIN64 -#define DLL_NAME "steam_api64.dll" + #define DLL_NAME "steam_api64.dll" #else -#define DLL_NAME "steam_api.dll" + #define DLL_NAME "steam_api.dll" #endif -extern "C" __declspec(dllexport) void *CreateInterface(const char *pName, int *pReturnCode) +extern "C" __declspec( dllexport ) void* __cdecl CreateInterface( const char *pName, int *pReturnCode ) { - // PRINT_DEBUG("%s", pName); + using fn_create_interface_t = void* (__cdecl *)(const char *); - HMODULE steam_api = LoadLibraryA(DLL_NAME); + auto steam_api = LoadLibraryA(DLL_NAME); + if (!steam_api) { + if (pReturnCode) *pReturnCode = 0; + return nullptr; + } - void *(__stdcall * create_interface)(const char *) = reinterpret_cast(GetProcAddress(steam_api, "SteamInternal_CreateInterface")); + auto create_interface = (fn_create_interface_t)GetProcAddress(steam_api, "SteamInternal_CreateInterface"); + if (!create_interface) { + if (pReturnCode) *pReturnCode = 0; + return nullptr; + } - return create_interface(pName); + auto ptr = create_interface(pName); + if (pReturnCode) { + if (ptr) { + *pReturnCode = 1; + } else { + *pReturnCode = 0; + } + } + + return ptr; }