Download

how add steam api to C++ project?

hi, for example i made my custom class based on Blueprint Function Library and want expose steam function RequestLobbyList() to blueprints (Steam Matchmaking & Lobbies (Steamworks Documentation)), so to do it i have to call function like

SteamAPICall_t RequestLobbyList()

but accidently C++ project can’t find what SteamAPICall_t is, in steamwork sdk Steamworks it’s defined like

// handle to a Steam API call
typedef uint64 SteamAPICall_t;
const SteamAPICall_t k_uAPICallInvalid = 0x0;

of couse i can copy these lines inside my C++ project, but is here a way to connect whole steamwork sdk and let visual studio find such declarations itself (automatically)?

link to whole project folder https://yadi.sk/d/l_yn3IwBgRVs2

to be more specific:

  1. i added custom C++ class called steam_functions
  2. in VS i got 2 files


steam_functions.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Steam_Functions.generated.h"

/**
 * 
 */
UCLASS()
class STEAM_TRAINING_API USteam_Functions : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
	UFUNCTION(BlueprintCallable, Category = "Steam")
	void UE_RequestLobbyList();
	
	
};



and steam_functions.cpp



#include "steam_training.h"
#include "Steam_Functions.h"
#include "steam_api.h"

void USteam_Functions::UE_RequestLobbyList()
{
	SteamAPI_SetMiniDumpComment("Minidump comment: SteamworksExample.exe
");
}


error happen exactly on line



SteamAPI_SetMiniDumpComment("Minidump comment: SteamworksExample.exe
");

Error	5	error LNK2019: unresolved external symbol __imp_SteamAPI_SetMiniDumpComment referenced in function "private: void __cdecl USteam_Functions::UE_RequestLobbyList(void)" (?UE_RequestLobbyList@USteam_Functions@@AEAAXXZ)	D:\ue4\projects\4.7.6\steam_training\Intermediate\ProjectFiles\Steam_Functions.cpp.obj	steam_training


seems VS have no idea where get this function’s body and i have no idea how link (implicitly) .lib file with solution that already a library! on http://stackoverflow.com/questions/5234899/no-linker-option-in-visual-studio-project-properties man told lubrary solution have no linker option!!! and that’s true, in raw win32 app linker option exist!

p.s. i’m using MVS express 2013 for windows 7 x64

found .Lib Files as Linker Input | Microsoft Docs, but for some reason my express version don’t have c/c++ folder like on Set C++ compiler and build properties in Visual Studio | Microsoft Docs

is it caused by express version? have someone not express and can confirm it?

installed 2013 ultimate and what you think? c/c++ folder doesn’t exist as well! just wtf? when i create new win32 project both in express and ultimate c/c++ folder exist in properties! in this case i have really few questions:

  1. is it blocked or just missed by launcher when generating vs solution?
  2. if it’s blocked, then why and how should i then use steam functions?!?!

Hi happyhorror,

Why do you need to manually integrate the SteamWorks SDK? UE4 already has it integrated (see OnlineSubsystemSteam) which has calls to the RequestLobbyList and such already provided for you. In any event, I opened up my project and I have the VC++ Directories, if you right click on your project -> properties, it’ll be under the Configuration Properties.

Rama actually has an excellent guide for setting up SteamWorks within a project here.

so i added some extra lines from rama’s guide, but in VS i still can’t use, because from steam api example project it should be called like

SteamAPICall_t hSteamAPICall = SteamMatchmaking()->RequestLobbyList();

and VS doesn’t know what SteamMatchmaking is, i can find where definition of SteamMatchmaking, but VS says

Error 9 error LNK2019: unresolved external symbol __imp_SteamMatchmaking referenced in function “private: void __cdecl USteam_Functions::UE_RequestLobbyList(void)” (?UE_RequestLobbyList@USteam_Functions@@AEAAXXZ) D:\ue4\projects\4.7.6\steam_training\Intermediate\ProjectFiles\Steam_Functions.cpp.obj steam_training

but SteamMatchmaking() is inside steam_api.h

S_API ISteamMatchmaking *S_CALLTYPE SteamMatchmaking();

for any unknown reason to me VS can’t see/understand it, while RequestLobbyList() is ok or doesn’t checked due error on SteamMatchmaking()

You probably want to also read through this document if you haven’t yet.

If the system can’t find the API, then that tells me your Build.cs/Target.cs files aren’t setup properly. Once those are fixed, you’ll need to regenerate your project solution (just right click on your UProject file and select Regenerate Solutions) so it actually reads the config changes and populates your include directories to point at the Steamworks SDK in the ThirdParty directory.

my build.cs



// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class steam_training : ModuleRules
{
	public steam_training(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

		PrivateDependencyModuleNames.AddRange(new string] { 
			"OnlineSubsystem",
			"OnlineSubsystemUtils"
		});

		// Uncomment if you are using Slate UI
		// PrivateDependencyModuleNames.AddRange(new string] { "Slate", "SlateCore" });
		
		// Uncomment if you are using online features
		PrivateDependencyModuleNames.Add("OnlineSubsystem");
		// if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64))
		// {
		//		if (UEBuildConfiguration.bCompileSteamOSS == true)
		//		{
					DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
		//		}
		// }
	}
}

my target.cs

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class steam_trainingTarget : TargetRules
{
	public steam_trainingTarget(TargetInfo Target)
	{
		Type = TargetType.Game;
		bUsesSteam = true;
	}

	//
	// TargetRules interface.
	//

	public override void SetupBinaries(
		TargetInfo Target,
		ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
		ref List<string> OutExtraModuleNames
		)
	{
		OutExtraModuleNames.AddRange( new string] { "steam_training" } );
	}
}


is here any mistakes?

i also want say, that steam pop up work fine in packaged game, steam statistic too http://steamcommunity.com/profiles/76561198000683981/ Spacewar 0.6 hour, but i really don’t know how get access to steam functions, because ingine does only steam init

what did i try:

  1. in projetc settings in VS add path to steam_api.h folder at include line
  2. in projetc settings in VS add path to steam_api.lib folder at include lib line

here is image for example 2015-05-04 23-43-28 Скриншот экрана.png — Yandex.Disk

errors are:



Error	6	error LNK2019: unresolved external symbol __imp_SteamMatchmaking referenced in function "private: void __cdecl USteam_Functions::UE_RequestLobbyList(void)" (?UE_RequestLobbyList@USteam_Functions@@AEAAXXZ)	D:\ue4\projects\4.7.6\steam_training\Intermediate\ProjectFiles\Steam_Functions.cpp.obj	steam_training

Error	7	error LNK1120: 1 unresolved externals	D:\ue4\projects\4.7.6\steam_training\Binaries\Win64\UE4Editor-steam_training.dll	steam_training

Error	8	error : Failed to produce item: D:\ue4\projects\4.7.6\steam_training\Binaries\Win64\UE4Editor-steam_training.dll	D:\ue4\projects\4.7.6\steam_training\Intermediate\ProjectFiles\ERROR	steam_training

Error	9	error MSB3073: The command ""D:\ue4\installed\Epic Games\4.7\Engine\Build\BatchFiles\Rebuild.bat" steam_trainingEditor Win64 Development "D:\ue4\projects\4.7.6\steam_training\steam_training.uproject" -rocket" exited with code 2.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	43	5	steam_training


Hmm, looks correct. And you’ve copied over the DLLs and such?

if you mean engine

D:\ue4\installed\Epic Games\4.7\Engine\Binaries\ThirdParty\Steamworks\Steamv130\Win64

then yes, there are dlls i have got from sdk

if you mean my EU projeject folder, then there isn’t dlls, but packaged game folder have dlls as well and bring steam pop up work fine with shift+tab

the only file i couldn’t find from rama’s guide is

WinPlatform.Automation.cs

In Visual Studio, this file is in the folder Programs/Automation/Win.Automation/WinPlatform.Automation.cs. Open it, and check that this string has your Steam API version:



 string SteamVersion = "Steamv131";


searched WinPlatform.Automation.cs over whole HDD by name, 0 matches, probably this file inside UE source code and not just compiled one, but in case shift+tab pop up work fine, sure this string fine too, the only problem - VS can’t find from where should it take



SteamAPICall_t hSteamAPICall = SteamMatchmaking()->RequestLobbyList();


but VS doesn’t inderline it with red and right click go to definition/declaration work fine on SteamMatchmaking/RequestLobbyList/SteamAPICall_t , all three lead to steam_api.h

Hmm, only other thing I could suggest is that make sure you are linking against the 64 bit binary if your app is 64bit (i.e. steam_api64.lib).

yeah, it’s fine too, i added both paths to x64 lib and x32, i will make archive in a minute with whole project if you can waste some time for me and try it on your own, maybe somehow magicaly it would work on your PC and then we can try find the difference

in OnlineSubsystemSteam.cpp at D:\ue4\installed\Epic Games\4.7\Engine\Source\Runtime\Online\OnlineSubsystemSteam\Private\OnlineSubsystemSteam.cpp i also changed this function at line 404



bool FOnlineSubsystemSteam::IsEnabled()
{
	if (bSteamworksClientInitialized || bSteamworksGameServerInitialized)
	{
		return true;
	}

	// Check the ini for disabling Steam
	bool bEnableSteam = true;
	GConfig->GetBool(TEXT("OnlineSubsystemSteam"), TEXT("bEnabled"), bEnableSteam, GEngineIni);
	if (bEnableSteam)
	{
		// Steam doesn't support running both the server and client on the same machine
		bEnableSteam = !FParse::Param(FCommandLine::Get(),TEXT("MultiprocessOSS"));
//#if UE_EDITOR
		if (bEnableSteam)
		{
			bEnableSteam = IsRunningDedicatedServer() || IsRunningGame();
		}
//#endif
	}

	return bEnableSteam;
}


so i just commented these //#if UE_EDITOR and //#endif to try allow steam in editor as well, but seems it didn’t help and it’s blocked somewhere else inside source code of engine additionally

One other thing to try might be just start from scratch, follow Rama’s tutorial line by line, and see what you get. If I get a chance, I’ll run through things locally and see what I can find out.

uploading yet whole archive with projetc, a bit big 1.8 gb, but there’s everything, i did it under 4.7.6 engine

as i said in packaged game steam pop up work fine, the only problem in VS, checked rama’s guide again, nothing new

here is link https://yadi.sk/d/l_yn3IwBgRVs2, if you can waste some time for me, would be great, because maybe noone yet tryed use steam functions and only just pop up, then our research additionaly to rama’s guide may save days digging around later for someone! :smiley:

i don’t even sure epic’s tryed use steam function from UE project, because in Engine they use Steam init of course and rebuilding whole engine seems very strange for me, but i got source code already and ready for such !@#$%^

searched in google

unreal engine “RequestLobbyList”

and what you think i got? right, nothing, did someone esle even try use RequestLobbyList for matchmaking in UE? seems not or it was so lucky smart guy, who didn’t ask anywhere in internet lol

https://www.google.ru/search?q=unreal+engine+RequestLobbyList&oq=unreal+engine+RequestLobbyList&aqs=chrome..69i57.2835j0j4&sourceid=chrome&ie=UTF-8#newwindow=1&q=unreal+engine+"RequestLobbyList"

googled lnk2019 error, found Linker Tools Error LNK2019 | Microsoft Docs but it doesn’t help, the only one thing i tryed is:

add steam_api.h to solution, but it didn’t change anything, still same error

i’ve found that SteamMatchmaking() defined like



S_API ISteamMatchmaking *S_CALLTYPE SteamMatchmaking();


and S_API defined like



#define S_API extern "C" __declspec( dllimport )


at Linker Tools Error LNK2019 | Microsoft Docs there are few examples of extern causing such error, but i don’t sure if it same in our case