Exporting functions from DLL correctly

esotericRa
esotericRa used Ask the Experts™
on
Hello, I am practicing exporting functions from a DLL. I am using the Steam API (www.steampowered.com) for practice. Here's my code so far

      HMODULE steamDLL;
      steamDLL = LoadLibrary("steam.dll");
      FARPROC SteamStartEngine = GetProcAddress(steamDLL, "SteamStartEngine");
      (*SteamStartEngine) (NULL);
      FARPROC SteamStartup = GetProcAddress(steamDLL, "SteamStartup");
      (*SteamStartup) (int UsingMask, NULL);
      FARPROC SteamLogin = GetProcAddress(steamDLL, "SteamLogin");
      (*SteamLogin) (const char* User, const char* Password, int isSecureComputer, NULL)
      FARPROC SteamSetUser = GetProcAddress(steamDLL, "SteamSetUser");
      (*SteamSetUser) (const char* User, int UserSet, NULL)
      FARPROC SteamProcessCall = GetProcAddress(steamDLL, "SteamProcessCall");
      (*SteamProcessCall) (int SteamHandle, NULL, NULL);
      FARPROC SteamIsLoggedIn = GetProcAddress(steamDLL, "SteamIsLoggedIn");
      (*SteamIsLoggedIn) (int isLoggedIn, NULL);
      FARPROC SteamLogout = GetProcAddress(steamDLL, "SteamLogout");
      (*SteamLogout) (NULL);
      FARPROC SteamCleanup = GetProcAddress(steamDLL, "SteamCleanup");
      (*SteamCleanup) (NULL);
      FARPROC SteamShutdownEngine = GetProcAddress(steamDLL, "SteamShutdownEngine");
      (*SteamShutdownEngine) (NULL);
      FARPROC SteamGetAppIds = GetProcAddress(steamDLL, "SteamGetAppIds");
      (*SteamGetAppIds) (int AppIDs[], int MaxAppIDs, NULL);
      FARPROC SteamEnumerateApp = GetProcAddress(steamDLL, "SteamEnumerateApp");
      (*SteamEnumerateApp) (int AppID, NULL, NULL);
      FARPROC SteamIsAppSubscribed = GetProcAddress(steamDLL, "SteamIsAppSubscribed");
      (*SteamIsAppSubscribed) (int AppID, int IsAppSubscribed, int IsAppReady, NULL);
      FARPROC SteamGetAppStats = GetProcAddress(steamDLL, "SteamGetAppStats");
      (*SteamGetAppStats) (NULL, NULL);

obviously this is incorrect because it's giving me errors of all various nature such as...

C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(227) : error C2143: syntax error : missing ')' before 'const'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(227) : error C2059: syntax error : ')'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(229) : error C2065: 'SteamProcessCall' : undeclared identifier
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(229) : error C2100: illegal indirection
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(229) : error C2144: syntax error : missing ')' before type 'int'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(229) : error C2059: syntax error : ')'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(231) : error C2144: syntax error : missing ')' before type 'int'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(231) : error C2059: syntax error : ')'
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(233) : error C2197: 'int (__stdcall *)(void)' : too many actual parameters
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(235) : error C2197: 'int (__stdcall *)(void)' : too many actual parameters
C:\Users\\Documents\C++\\SteamIDRetrieve\SteamIDRetrieve.cpp(237) : error C2197: 'int (__stdcall *)(void)' : too many actual parameters

HELP please :(
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
My first suggestion is to remove type information from statements such as
         (*SteamStartup) (int UsingMask, NULL);
resulting in
         (*SteamStartup) (UsingMask, NULL);

   HMODULE steamDLL;
   steamDLL = LoadLibrary("steam.dll");
   FARPROC SteamStartEngine = GetProcAddress(steamDLL, "SteamStartEngine");
   (*SteamStartEngine) (NULL);
   FARPROC SteamStartup = GetProcAddress(steamDLL, "SteamStartup");
   (*SteamStartup) (UsingMask, NULL);
   FARPROC SteamLogin = GetProcAddress(steamDLL, "SteamLogin");
   (*SteamLogin) (User, Password, isSecureComputer, NULL)
   FARPROC SteamSetUser = GetProcAddress(steamDLL, "SteamSetUser");
   (*SteamSetUser) (User, UserSet, NULL)
   FARPROC SteamProcessCall = GetProcAddress(steamDLL, "SteamProcessCall");
   (*SteamProcessCall) (SteamHandle, NULL, NULL);
   FARPROC SteamIsLoggedIn = GetProcAddress(steamDLL, "SteamIsLoggedIn");
   (*SteamIsLoggedIn) (isLoggedIn, NULL);
   FARPROC SteamLogout = GetProcAddress(steamDLL, "SteamLogout");
   (*SteamLogout) (NULL);
   FARPROC SteamCleanup = GetProcAddress(steamDLL, "SteamCleanup");
   (*SteamCleanup) (NULL);
   FARPROC SteamShutdownEngine = GetProcAddress(steamDLL, "SteamShutdownEngine");
   (*SteamShutdownEngine) (NULL);
   FARPROC SteamGetAppIds = GetProcAddress(steamDLL, "SteamGetAppIds");
   (*SteamGetAppIds) (AppIDs[], MaxAppIDs, NULL);
   FARPROC SteamEnumerateApp = GetProcAddress(steamDLL, "SteamEnumerateApp");
   (*SteamEnumerateApp) (AppID, NULL, NULL);
   FARPROC SteamIsAppSubscribed = GetProcAddress(steamDLL, "SteamIsAppSubscribed");
   (*SteamIsAppSubscribed) (AppID, IsAppSubscribed, IsAppReady, NULL);
   FARPROC SteamGetAppStats = GetProcAddress(steamDLL, "SteamGetAppStats");
   (*SteamGetAppStats) (NULL, NULL);
Top Expert 2007

Commented:
Also, you have several lines such as
   (*SteamLogin) (User, Password, isSecureComputer, NULL)
which need to be terminated by a semicolon, as in
   (*SteamLogin) (User, Password, isSecureComputer, NULL);
Top Expert 2007
Commented:
In this form, the code builds on my box

#include <windows.h>

namespace {

   struct TSteamError {
   };
   struct TSteamProgress {
   };
   struct TSteamApp {
   };
   struct TSteamAppStats {
   };
   
   void (*SteamStartEngine)(TSteamError& SteamErr);
   void (*SteamStartup)(unsigned int UsingMask, TSteamError& SteamErr);
   void (*SteamLogin)(char* User, char* Password, int isSecureComputer, TSteamError& SteamErr);
   void (*SteamSetUser)(char* User, int& UserSet, TSteamError& SteamErr);
   void (*SteamProcessCall)(unsigned int SteamHandle, TSteamProgress& Progress, TSteamError& SteamErr);
   void (*SteamIsLoggedIn)(int& isLoggedIn, TSteamError& SteamErr);
   void (*SteamLogout)(TSteamError& SteamErr);
   void (*SteamCleanup)(TSteamError& SteamErr);
   void (*SteamShutdownEngine)(TSteamError& SteamErr);
   void (*SteamGetAppIds)(unsigned int & AppIDs, unsigned int MaxAppIDs, TSteamError& SteamErr);
   void (*SteamEnumerateApp)(unsigned int AppID, TSteamApp& AppStruc, TSteamError& SteamErr);
   void (*SteamIsAppSubscribed)(unsigned int AppID, unsigned int& IsAppSubscribed, unsigned int& IsAppReady, TSteamError& SteamErr);
   void (*SteamGetAppStats)(TSteamAppStats& AppStats, TSteamError& SteamErr);

   char *User, *Password;
   unsigned int UsingMask;
   int isSecureComputer;
   int UserSet;
   unsigned int SteamHandle;
   int isLoggedIn;
   const int MaxAppIDs = 6;
   TSteamAppStats AppStats[MaxAppIDs];
   unsigned int AppIDs;
   unsigned int IsAppSubscribed;
   unsigned int IsAppReady;
   unsigned int AppID;
   TSteamError SteamErr;
   TSteamProgress streamProgress;
   TSteamApp app;
   TSteamAppStats appStats;
}


void main() {
   HMODULE steamDLL;
   steamDLL = LoadLibrary("steam.dll");
   SteamStartEngine = (void(*)(TSteamError&)) GetProcAddress(steamDLL, "SteamStartEngine");
   (*SteamStartEngine) (SteamErr);
   SteamStartup = (void (*)(unsigned int, TSteamError&)) GetProcAddress(steamDLL, "SteamStartup");
   (*SteamStartup) (UsingMask, SteamErr);
   SteamLogin = (void (*)(char*, char*, int, TSteamError&)) GetProcAddress(steamDLL, "SteamLogin");
   (*SteamLogin) (User, Password, isSecureComputer, SteamErr);
   SteamSetUser = (void (*)(char*, int&, TSteamError&)) GetProcAddress(steamDLL, "SteamSetUser");
   (*SteamSetUser) (User, UserSet, SteamErr);
   SteamProcessCall = (void (*)(unsigned int, TSteamProgress&, TSteamError&)) GetProcAddress(steamDLL, "SteamProcessCall");
   (*SteamProcessCall) (SteamHandle, streamProgress, SteamErr);
   SteamIsLoggedIn = (void (*)(int&, TSteamError&)) GetProcAddress(steamDLL, "SteamIsLoggedIn");
   (*SteamIsLoggedIn) (isLoggedIn, SteamErr);
   SteamLogout = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamLogout");
   (*SteamLogout) (SteamErr);
   SteamCleanup = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamCleanup");
   (*SteamCleanup) (SteamErr);
   SteamShutdownEngine = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamShutdownEngine");
   (*SteamShutdownEngine) (SteamErr);
   SteamGetAppIds = (void (*)(unsigned int&, unsigned int, TSteamError&)) GetProcAddress(steamDLL, "SteamGetAppIds");
   (*SteamGetAppIds) (AppIDs, MaxAppIDs, SteamErr);
   SteamEnumerateApp = (void (*)(unsigned int, TSteamApp&, TSteamError&)) GetProcAddress(steamDLL, "SteamEnumerateApp");
   (*SteamEnumerateApp) (AppID, app, SteamErr);
   SteamIsAppSubscribed = (void (*)(unsigned int, unsigned int&, unsigned int&, TSteamError&)) GetProcAddress(steamDLL, "SteamIsAppSubscribed");
   (*SteamIsAppSubscribed) (AppID, IsAppSubscribed, IsAppReady, SteamErr);
   SteamGetAppStats = (void (*)(TSteamAppStats&, TSteamError&)) GetProcAddress(steamDLL, "SteamGetAppStats");
   (*SteamGetAppStats) (appStats, SteamErr);
}
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
josgood, that worked great.

What I'm trying to do is retrieve the games of the specified account for Steam on an application I'm working on.

here's the code:


It's giving me an error error: C2065: 'SErr' : undeclared identifier

I try to declare SErr with TSteamError SErr; or TSteamError SErr = TSteamError(); and it returns the following errors:

C:\Users\\Documents\C++\\steampractice\steampractice.cpp(257) : error C2065: 'SteamErr' : undeclared identifier
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(288) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(289) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(290) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(295) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(427) : error C2664: 'void (unsigned int,unsigned int &,unsigned int &,struct `anonymous-namespace'::TSteamError &)' : cannot convert parameter 3 from 'int' to 'unsigned int &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(427) : error C2664: 'void (unsigned int,unsigned int &,unsigned int &,struct `anonymous-namespace'::TSteamError &)' : cannot convert parameter 2 from 'int' to 'unsigned int &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(427) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\Documents\C++\\steampractice\steampractice.cpp(445) : error C2440: '=' : cannot convert from 'void' to 'int'
        Expressions of type void cannot be converted to other types
C:\Users\\Documents\C++\\steampractice\steampractice.cpp(447) : error C2440: '=' : cannot convert from 'void' to 'int'

Also if you see any other reason why this wouldn't work, please let me know

thank  you again
#include <windows.h>
#include "stdio.h"
namespace {
 
   struct TSteamError {
   };
   struct TSteamProgress {
   };
   struct TSteamApp {
   };
   struct TSteamAppStats {
   };
   
   void (*SteamStartEngine)(TSteamError& SteamErr);
   void (*SteamStartup)(unsigned int UsingMask, TSteamError& SteamErr);
   void (*SteamLogin)(char* User, char* Password, int isSecureComputer, TSteamError& SteamErr);
   void (*SteamSetUser)(char* User, int& UserSet, TSteamError& SteamErr);
   void (*SteamProcessCall)(unsigned int SteamHandle, TSteamProgress& Progress, TSteamError& SteamErr);
   void (*SteamIsLoggedIn)(int& isLoggedIn, TSteamError& SteamErr);
   void (*SteamLogout)(TSteamError& SteamErr);
   void (*SteamCleanup)(TSteamError& SteamErr);
   void (*SteamShutdownEngine)(TSteamError& SteamErr);
   void (*SteamGetAppIds)(unsigned int & AppIDs, unsigned int MaxAppIDs, TSteamError& SteamErr);
   void (*SteamEnumerateApp)(unsigned int AppID, TSteamApp& AppStruc, TSteamError& SteamErr);
   void (*SteamIsAppSubscribed)(unsigned int AppID, unsigned int& IsAppSubscribed, unsigned int& IsAppReady, TSteamError& SteamErr);
   void (*SteamGetAppStats)(TSteamAppStats& AppStats, TSteamError& SteamErr);
 
   char *User, *Password;
   unsigned int UsingMask;
   int isSecureComputer;
   int UserSet;
   unsigned int SteamHandle;
   int isLoggedIn;
   const int MaxAppIDs = 6;
   TSteamAppStats AppStats[MaxAppIDs];
   unsigned int AppIDs;
   unsigned int IsAppSubscribed;
   unsigned int IsAppReady;
   unsigned int AppID;
   TSteamError SteamErr;
   TSteamProgress streamProgress;
   TSteamApp app;
   TSteamAppStats appStats;
}
 
const char* printGame(int gameID)
        {
            switch (gameID)
            {
                case 10:
                    return "Counter-Strike";
                    break;
                case 20:
                    return "Team Fortress Classic";
                    break;
                case 30:
                    return "Day of Defeat";
                    break;
                case 40:
                    return "Deathmatch Classic";
                    break;
                case 50:
                    return "Opposing Force";
                    break;
                case 60:
                    return "Ricochet";
                    break;
                case 70:
                    return "Half-Life";
                    break;
                case 80:
                    return "Condition Zero";
                    break;
                case 100:
                    return "Condition Zero Deleted Scenes";
                    break;
                case 130:
                    return "Half-Life: Blue Shift";
                    break;
                case 220:
                    return "Half-Life 2";
                    break;
                case 240:
                    return "Counter-Strike: Source";
                    break;
                case 280:
                    return "Half-Life: Source";
                    break;
                case 300:
                    return "Day of Defeat: Source";
                    break;
                case 320:
                    return "Half-Life 2: Deathmatch";
                    break;
                case 340:
                    return "Half-Life 2: Lost Coast";
                    break;
                case 360:
                    return "Half-Life Deathmatch: Source";
                    break;
                case 380:
                    return "Half-Life 2: Episode One";
                    break;
                case 400:
                    return "Portal";
                    break;
                case 420:
                    return "Half-Life 2: Episode Two";
                    break;
                case 440:
                    return "Team Fortress 2";
                    break;
                case 1300:
                    return "SiN Episodes: Emergence";
                    break;
                case 2100:
                    return "Dark Messiah of Might and Magic";
                    break;
                case 2400:
                    return "The Ship";
                    break;
                case 4000:
                    return "Garry's Mod";
                    break;
                case 1200: return "Red Orchestra  Ostfront 41-45"; break;
                case 1210: return "Red Orchestra Beta"; break;
                case 1309: return "SiN 1 Multiplayer"; break;
                case 1313: return "SiN 1"; break;
                case 1500: return "Darwinia"; break;
                case 1510: return "Uplink"; break;
                case 1520: return "DEFCON"; break;
                case 1600: return "Dangerous Waters"; break;
                case 1610: return "Space Empires IV Deluxe"; break;
                case 1620: return "Jagged Alliance 2 Gold"; break;
                case 1630: return "Disciples II  Rise of the Elves"; break;
                case 1640: return "Disciples II  Galleans: return"; break;
                case 1660: return "Birth of America"; break;
                case 1670: return "Iron Warriors  T72 Tank Command"; break;
                case 1690: return "Space Empires V"; break;
                case 1700: return "Arx Fatalis"; break;
                case 1900: return "Earth 2160"; break;
                case 2200: return "Quake III Arena"; break;
                case 2270: return "Wolfenstein 3D"; break;
                case 2280: return "The Ultimate Doom"; break;
                case 2290: return "Final Doom"; break;
                case 2300: return "Doom II"; break;
                case 2310: return "Quake"; break;
                case 2320: return "Quake II"; break;
                case 2330: return "Quake II Mission Pack 1  The Reckoning"; break;
                case 2340: return "Quake II Mission Pack 2  Ground Zero"; break;
                case 2350: return "Quake III  Team Arena"; break;
                case 2360: return "Hexen"; break;
                case 2370: return "Hexen  Deathkings of the Dark Citadel"; break;
                case 2390: return "Heretic  Shadow of the Serpent Riders"; break;
                case 2500: return "Shadowgrounds"; break;
                case 2520: return "Gumboy - Crazy Adventures"; break;
                case 2610: return "GUN"; break;
                case 2620: return "Call of Duty"; break;
                case 2625: return "Call of Duty Singleplayer"; break;
                case 2630: return "Call of Duty 2 Multiplayer"; break;
                case 2635: return "Call of Duty 2 Singleplayer"; break;
                case 2640: return "Call of Duty  United Offensive"; break;
                case 2720: return "ThreadSpace  Hyperbol Stress Test"; break;
                case 2740: return "ThreadSpace  Hyperbol Dedicated Server"; break;
                case 2800: return "X2  The Threat"; break;
                case 2810: return "X3  Reunion"; break;
                case 2900: return "688(I) Hunter-Killer"; break;
                case 2910: return "Fleet Command"; break;
                case 2920: return "Sub Command"; break;
                case 2930: return "Birth of America"; break;
                case 2990: return "FlatOut 2"; break;
                case 3000: return "GTI Racing"; break;
                case 3010: return "Xpand Rally"; break;
                case 3300: return "Bejeweled 2 Deluxe"; break;
                case 3200: return "Painkiller Gold Edition"; break;
                case 3310: return "Chuzzle Deluxe"; break;
                case 3320: return "Insaniquarium Deluxe"; break;
                case 3330: return "Zuma Deluxe"; break;
                case 3340: return "AstroPop Deluxe"; break;
                case 3350: return "Bejeweled Deluxe"; break;
                case 3360: return "Big Money Deluxe"; break;
                case 3370: return "Bookworm Deluxe"; break;
                case 3380: return "Dynomite Deluxe"; break;
                case 3390: return "Feeding Frenzy 2 Deluxe"; break;
                case 3400: return "Hammer Heads Deluxe"; break;
                case 3410: return "Heavy Weapon Deluxe"; break;
                case 3420: return "Iggle Pop Deluxe"; break;
                case 3430: return "Pizza Frenzy Deluxe"; break;
                case 3440: return "Rocket Mania Deluxe"; break;
                case 3450: return "Typer Shark Deluxe"; break;
                case 3460: return "Talismania Deluxe"; break;
                case 3470: return "Bookworm Adventures Deluxe"; break;
                case 3700: return "Sniper Elite"; break;
                case 3800: return "Advent Rising"; break;
                case 3810: return "BloodRayne"; break;
                case 3820: return "BloodRayne 2"; break;
                case 3830: return "Psychonauts"; break;
                case 3900: return "Sid Meier's Civilization IV"; break;
                case 3910: return "Sid Meier's Civilization III Complete"; break;
                case 3920: return "Sid Meier's Pirates!"; break;
                case 3930: return "Serious Sam 2"; break;
                case 3960: return "Shattered Union"; break;
                case 3970: return "Prey"; break;
                case 4100: return "Poker Superstars II"; break;
                case 4200: return "RACE Internal Beta"; break;
                case 4230: return "RACE"; break;
                case 4300: return "RoboBlitz"; break;
                case 4400: return "City Life"; break;
                case 4410: return "City Life Deluxe"; break;
                case 4500: return "S.T.A.L.K.E.R.  Shadow of Chernobyl"; break;
                case 4600: return "Full Pipe"; break;
                case 4700: return "Medieval II  Total War"; break;
                case 4730: return "Outrun 2006  Coast 2 Coast"; break;
                case 4800: return "Heroes of Annihilated Empires"; break;
                case 4900: return "Zen of Sudoku"; break;
                case 6100: return "Eets"; break;
                case 6200: return "Ghost Master"; break;
                case 6210: return "Vegas Make It Big"; break;
                case 6300: return "Dreamfall  The Longest Journey"; break;
                case 6310: return "The Longest Journey"; break;
                case 6400: return "Joint Task Force"; break;
                case 6510: return "Lost Planet Extreme Condition"; break;
                case 6570: return "Onimusha 3  Demon Siege"; break;
                case 6600: return "Bullet Candy"; break;
                case 6880: return "Just Cause"; break;
                case 7060: return "Infernal"; break;
                case 7110: return "Jade Empire  Special Edition"; break;
                case 7420: return "Wik and the Fable of Souls"; break;
                case 7600: return "Sid Meier's Railroads"; break;
                case 7670: return "Bioshock"; break;
                case 8400: return "Geometry Wars"; break;
                case 9000: return "Spear of Destiny"; break;
                case 9010: return "Return to Castle Wolfenstein"; break;
                case 9030: return "Quake Mission Pack 2  Dissolution of Eternity"; break;
                case 9040: return "Quake Mission Pack 1  Scourge of Armagon"; break;
                case 9050: return "Doom 3"; break;
                case 9060: return "Hexen II"; break;
                case 9070: return "Doom 3  Resurrection of Evil"; break;
                case 9180: return "Commander Keen"; break;
                default:
                    return "Unknown Game";
                    break;
            }//switch
 
        }
 
 
void main() 
{
   HMODULE steamDLL;
   steamDLL = LoadLibrary("steam.dll");
   SteamStartEngine = (void(*)(TSteamError&)) GetProcAddress(steamDLL, "SteamStartEngine");
   (*SteamStartEngine) (SteamErr);
   SteamStartup = (void (*)(unsigned int, TSteamError&)) GetProcAddress(steamDLL, "SteamStartup");
   (*SteamStartup) (UsingMask, SteamErr);
   SteamLogin = (void (*)(char*, char*, int, TSteamError&)) GetProcAddress(steamDLL, "SteamLogin");
   (*SteamLogin) (User, Password, isSecureComputer, SteamErr);
   SteamSetUser = (void (*)(char*, int&, TSteamError&)) GetProcAddress(steamDLL, "SteamSetUser");
   (*SteamSetUser) (User, UserSet, SteamErr);
   SteamProcessCall = (void (*)(unsigned int, TSteamProgress&, TSteamError&)) GetProcAddress(steamDLL, "SteamProcessCall");
   (*SteamProcessCall) (SteamHandle, streamProgress, SteamErr);
   SteamIsLoggedIn = (void (*)(int&, TSteamError&)) GetProcAddress(steamDLL, "SteamIsLoggedIn");
   (*SteamIsLoggedIn) (isLoggedIn, SteamErr);
   SteamLogout = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamLogout");
   (*SteamLogout) (SteamErr);
   SteamCleanup = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamCleanup");
   (*SteamCleanup) (SteamErr);
   SteamShutdownEngine = (void (*)(TSteamError&)) GetProcAddress(steamDLL, "SteamShutdownEngine");
   (*SteamShutdownEngine) (SteamErr);
   SteamGetAppIds = (void (*)(unsigned int&, unsigned int, TSteamError&)) GetProcAddress(steamDLL, "SteamGetAppIds");
   (*SteamGetAppIds) (AppIDs, MaxAppIDs, SteamErr);
   SteamEnumerateApp = (void (*)(unsigned int, TSteamApp&, TSteamError&)) GetProcAddress(steamDLL, "SteamEnumerateApp");
   (*SteamEnumerateApp) (AppID, app, SteamErr);
   SteamIsAppSubscribed = (void (*)(unsigned int, unsigned int&, unsigned int&, TSteamError&)) GetProcAddress(steamDLL, "SteamIsAppSubscribed");
   (*SteamIsAppSubscribed) (AppID, IsAppSubscribed, IsAppReady, SteamErr);
   SteamGetAppStats = (void (*)(TSteamAppStats&, TSteamError&)) GetProcAddress(steamDLL, "SteamGetAppStats");
   (*SteamGetAppStats) (appStats, SteamErr);
 
   int iSteamReturn = 0;
            int iUserSet = 0;
            int isLoggedIn = 0;
            int sHandle;
            int startoptions = 15;
			iSteamReturn = SteamStartup(startoptions, SErr);
			sHandle = SteamLogin("innocuous", "bypass", 1, SErr);
			iSteamReturn = SteamIsLoggedIn(isLoggedIn, SErr);
 
            if (isLoggedIn == 1)
            {
 
                sHandle = SteamSetUser("innocuous", iUserSet, SErr);
				if (iUserSet == 1)
                {
                    //We are now authenticated
 
                    int isAppSubscribed = 0;
                    int isAppReady = 0;
                    //uint AppID = 70; //only used in original code
                    int AppIDs[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 130, 220, 240, 280, 300, 320, 340, 360, 380, 400, 420, 440, 1300, 2100, 2400, 4000,
                        1001,
                        1200,
                        4145,
                        1210,
                        1309,
                        1313,
                        1500,
                        1510,
                        1520,
                        1600,
                        1610,
                        1620,
                        1630,
                        1640,
                        1660,
                        1670,
                        1690,
                        1700,
                        1900,
                        2160,
                        2200,
                        2270,
                        2280,
                        2290,
                        2300,
                        2310,
                        2320,
                        2330,
                        2340,
                        2350,
                        2360,
                        2370,
                        2390,
                        2500,
                        2520,
                        2610,
                        2620,
                        2625,
                        2630,
                        2635,
                        2640,
                        2720,
                        2740,
                        2800,
                        2810,
                        2900,
                        2910,
                        2920,
                        2930,
                        2990,
                        3000,
                        3010,
                        3300,
                        3200,
                        3310,
                        3320,
                        3330,
                        3340,
                        3350,
                        3360,
                        3370,
                        3380,
                        3390,
                        3400,
                        3410,
                        3420,
                        3430,
                        3440,
                        3450,
                        3460,
                        3470,
                        3700,
                        3800,
                        3810,
                        3820,
                        3830,
                        3900,
                        3910,
                        3920,
                        3930,
                        3960,
                        3970,
                        4100,
                        4200,
                        4230,
                        4300,
                        4400,
                        4410,
                        4500,
                        4600,
                        4700,
                        4730,
                        4800,
                        4900,
                        6100,
                        6200,
                        6210,
                        6300,
                        6310,
                        6400,
                        6510,
                        6570,
                        6600,
                        6880,
                        7060,
                        7110,
                        7420,
                        7600,
                        7670,
                        8400,
                        9000,
                        9010,
                        9030,
                        9040,
                        9050,
                        9060,
                        9070,
                        9180};
 
                    for (int index = 0; index < sizeof(AppIDs); index++)
                    {
 
                        //iSteamReturn = SteamIsAppSubscribed(AppID, ref isAppSubscribed, ref isAppReady, ref SErr);
                        iSteamReturn = SteamIsAppSubscribed(AppIDs[index], isAppSubscribed, isAppReady, SErr);
 
                        if (isAppSubscribed == 1)
                        {
 
                                printf("game = %s\n", printGame(AppIDs[index]));
                        }
 
                    }
 
 
                    //end of games list
                    puts("Finished");
 
                }
 
            }
 
            sHandle = SteamLogout(SErr);
 
            iSteamReturn = SteamCleanup(SErr);
 
            iSteamReturn = SteamShutdownEngine(SErr);
 
 
        }

Open in new window

Top Expert 2007

Commented:
>>It's giving me an error error: C2065: 'SErr' : undeclared identifier
You need to declear sErr, as in
   TSteamError SErr;
   iSteamReturn = SteamStartup(startoptions, SErr);

>>C:\Users\\Documents\C++\\steampractice\steampractice.cpp(288) : error C2440: '=' : cannot convert from 'void' to 'int'
>>        Expressions of type void cannot be converted to other types
The methods are all declared to be of type void, as in
      void (*SteamStartup)(unsigned int UsingMask, TSteamError& SteamErr);
so you can't assign the result of the call to anything.

Do you have a header file for steam.dll from steampowered.com?

Author

Commented:
No, I know people have done it without the header file, though.

Here's an example of a working C# script that does what I'm trying to do in C++.

Any help would be fantastic
/***********************************
 * Tulle @ hack-y0u.org 2007
 * 
 * Code base jacked from Mitsukarina
 * of cs.run.ru.
 * 
 * Direct all questions to me via PM
 * 
 * *********************************/
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
 
 
namespace Account_Hacker
{
    public partial class frmSteamGameChecker : Form
    {
 
        //properties
        public int setBreak = 0; //used during shutdown
 
        public frmSteamGameChecker()
        {
            InitializeComponent();
        }
 
        private void btnStart_Click(object sender, EventArgs e)
        {
            rtbOutput.Clear();
 
            btnManualCheck.Enabled = false;
            btnStart.Enabled = false;
 
            Application.DoEvents();
 
            TSteamError SErr = new TSteamError();
            int iSteamReturn = 0;
            int iUserSet = 0;
            int isLoggedIn = 0;
            string SteamUserName = txtUsername.Text.ToString();
            string SteamUserPassword = txtPassword.Text.ToString();
            uint sHandle;
            uint startoptions = 15;
 
            //iSteamReturn = SteamStartEngine(ref SErr); //code below checks for errors
 
            iSteamReturn = SteamStartEngine(ref SErr);
            if (SErr.eSteamError != eSteamError.eSteamErrorNone) { MessageBox.Show("Steam Error : " + SErr.ErrDescription); } 
 
            iSteamReturn = SteamStartup(startoptions, ref SErr);
 
            TSteamProgress TProgress = new TSteamProgress();
            TProgress.Valid = 1;
 
            sHandle = SteamLogin(SteamUserName, SteamUserPassword, 1, ref SErr);
 
            while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
            {
                Application.DoEvents();
 
                if (setBreak == 1)
                    break;
            }
 
            iSteamReturn = SteamIsLoggedIn(ref isLoggedIn, ref SErr);
 
            if (isLoggedIn == 1)
            {
 
                sHandle = SteamSetUser(SteamUserName, ref iUserSet, ref SErr);
 
                TProgress = new TSteamProgress();
                TProgress.Valid = 1;
 
                while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
                {
                    Application.DoEvents();
 
                    if (setBreak == 1)
                        break;
                }
 
                if (iUserSet == 1)
                {
                    //We are now authenticated
 
                    rtbOutput.Text += "Authenticated!\n\n";
                    rtbOutput.Text += "[Games]\n";
 
                    uint isAppSubscribed = 0;
                    uint isAppReady = 0;
                    //uint AppID = 70; //only used in original code
                    uint[] AppIDs = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 130, 220, 240, 280, 300, 320, 340, 360, 380, 400, 420, 440, 1300, 2100, 2400, 4000,
                        1001,
                        1200,
                        4145,
                        1210,
                        1309,
                        1313,
                        1500,
                        1510,
                        1520,
                        1600,
                        1610,
                        1620,
                        1630,
                        1640,
                        1660,
                        1670,
                        1690,
                        1700,
                        1900,
                        2160,
                        2200,
                        2270,
                        2280,
                        2290,
                        2300,
                        2310,
                        2320,
                        2330,
                        2340,
                        2350,
                        2360,
                        2370,
                        2390,
                        2500,
                        2520,
                        2610,
                        2620,
                        2625,
                        2630,
                        2635,
                        2640,
                        2720,
                        2740,
                        2800,
                        2810,
                        2900,
                        2910,
                        2920,
                        2930,
                        2990,
                        3000,
                        3010,
                        3300,
                        3200,
                        3310,
                        3320,
                        3330,
                        3340,
                        3350,
                        3360,
                        3370,
                        3380,
                        3390,
                        3400,
                        3410,
                        3420,
                        3430,
                        3440,
                        3450,
                        3460,
                        3470,
                        3700,
                        3800,
                        3810,
                        3820,
                        3830,
                        3900,
                        3910,
                        3920,
                        3930,
                        3960,
                        3970,
                        4100,
                        4200,
                        4230,
                        4300,
                        4400,
                        4410,
                        4500,
                        4600,
                        4700,
                        4730,
                        4800,
                        4900,
                        6100,
                        6200,
                        6210,
                        6300,
                        6310,
                        6400,
                        6510,
                        6570,
                        6600,
                        6880,
                        7060,
                        7110,
                        7420,
                        7600,
                        7670,
                        8400,
                        9000,
                        9010,
                        9030,
                        9040,
                        9050,
                        9060,
                        9070,
                        9180};
 
                    for (int index = 0; index < AppIDs.Length; index++)
                    {
 
                        //iSteamReturn = SteamIsAppSubscribed(AppID, ref isAppSubscribed, ref isAppReady, ref SErr);
                        iSteamReturn = SteamIsAppSubscribed(AppIDs[index], ref isAppSubscribed, ref isAppReady, ref SErr);
 
                        if (isAppSubscribed == 1)
                        {
                            //Do Something!
                            //rtbOutput.Text += "-Half-Life\n";
                            if (printGame(AppIDs[index]) == "Unknown Game")
                            {
                                rtbOutput.Text += "-Unknown Game (AppID: " + AppIDs[index] + ")\n";
                            }
                            else
                            {
                                rtbOutput.Text += "-" + printGame(AppIDs[index]) + "\n";
                            }
                        }
 
                        Application.DoEvents();
                    }
 
 
                    //end of games list
                    rtbOutput.Text += "[End]\n\n";
 
                }
 
            }
            else
            {
                rtbOutput.Text += "Failed to authenticate (invalid username/password).\n";
            }
 
            sHandle = SteamLogout(ref SErr);
 
            TProgress = new TSteamProgress();
            TProgress.Valid = 1;
 
            while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
            {
                Application.DoEvents();
 
                if (setBreak == 1)
                {
                    MessageBox.Show("CALLED");
                    break;
                }
            }
 
            setBreak = 0;
 
            iSteamReturn = SteamCleanup(ref SErr);
 
            iSteamReturn = SteamShutdownEngine(ref SErr);
 
            btnManualCheck.Enabled = true;
            btnStart.Enabled = true;
 
        }
 
        public void addAccount(string username, string password, string email)
        {
            ListViewItem addItem;
            addItem = lvAccounts.Items.Add(username);
            addItem.SubItems.Add(password);
            addItem.SubItems.Add(email);
        }
 
        #region Methods and Structure
 
        public enum eSteamError
        {
            eSteamErrorNone = 0,
            eSteamErrorUnknown = 1,
            eSteamErrorLibraryNotInitialized = 2,
            eSteamErrorLibraryAlreadyInitialized = 3,
            eSteamErrorConfig = 4,
            eSteamErrorContentServerConnect = 5,
            eSteamErrorBadHandle = 6,
            eSteamErrorHandlesExhausted = 7,
            eSteamErrorBadArg = 8,
            eSteamErrorNotFound = 9,
            eSteamErrorRead = 10,
            eSteamErrorEOF = 11,
            eSteamErrorSeek = 12,
            eSteamErrorCannotWriteNonUserConfigFile = 13,
            eSteamErrorCacheOpen = 14,
            eSteamErrorCacheRead = 15,
            eSteamErrorCacheCorrupted = 16,
            eSteamErrorCacheWrite = 17,
            eSteamErrorCacheSession = 18,
            eSteamErrorCacheInternal = 19,
            eSteamErrorCacheBadApp = 20,
            eSteamErrorCacheVersion = 21,
            eSteamErrorCacheBadFingerPrint = 22,
            eSteamErrorNotFinishedProcessing = 23,
            eSteamErrorNothingToDo = 24,
            eSteamErrorCorruptEncryptedUserIDTicket = 25,
            eSteamErrorSocketLibraryNotInitialized = 26,
            eSteamErrorFailedToConnectToUserIDTicketValidationServer = 27,
            eSteamErrorBadProtocolVersion = 28,
            eSteamErrorReplayedUserIDTicketFromClient = 29,
            eSteamErrorReceiveResultBufferTooSmall = 30,
            eSteamErrorSendFailed = 31,
            eSteamErrorReceiveFailed = 32,
            eSteamErrorReplayedReplyFromUserIDTicketValidationServer = 33,
            eSteamErrorBadSignatureFromUserIDTicketValidationServer = 34,
            eSteamErrorValidationStalledSoAborted = 35,
            eSteamErrorInvalidUserIDTicket = 36,
            eSteamErrorClientLoginRateTooHigh = 37,
            eSteamErrorClientWasNeverValidated = 38,
            eSteamErrorInternalSendBufferTooSmall = 39,
            eSteamErrorInternalReceiveBufferTooSmall = 40,
            eSteamErrorUserTicketExpired = 41,
            eSteamErrorCDKeyAlreadyInUseOnAnotherClient = 42,
            eSteamErrorNotLoggedIn = 101,
            eSteamErrorAlreadyExists = 102,
            eSteamErrorAlreadySubscribed = 103,
            eSteamErrorNotSubscribed = 104,
            eSteamErrorAccessDenied = 105,
            eSteamErrorFailedToCreateCacheFile = 106,
            eSteamErrorCallStalledSoAborted = 107,
            eSteamErrorEngineNotRunning = 108,
            eSteamErrorEngineConnectionLost = 109,
            eSteamErrorLoginFailed = 110,
            eSteamErrorAccountPending = 111,
            eSteamErrorCacheWasMissingRetry = 112,
            eSteamErrorLocalTimeIncorrect = 113,
            eSteamErrorNetwork = 200
        }
 
        public enum eDetailedPlatformErrorType
        {
            eNoDetailedErrorAvailable,
            eStandardCerrno,
            eWin32LastError,
            eWinSockLastError,
            eDetailedPlatformErrorCount
        }
 
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
        public struct TSteamError
        {
            public eSteamError eSteamError;
            public eDetailedPlatformErrorType eDetailedErrorType;
            public uint ErrCode;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
            public string ErrDescription;
        }
 
        TSteamError SErr = new TSteamError();
 
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
        public struct TSteamProgress
        {
            public int Valid;
            public int Percent;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
            public string Progress;
        }
 
        //Login calls
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamStartEngine(ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamStartup(uint UsingMask, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint SteamLogin(string User, string Password, int isSecureComputer, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint SteamSetUser(string User, ref int UserSet, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamProcessCall(uint SteamHandle, ref TSteamProgress Progress, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamIsLoggedIn(ref int isLoggedIn, ref TSteamError SteamErr);
 
        //cleanup calls
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint SteamLogout(ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamCleanup(ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamShutdownEngine(ref TSteamError SteamErr);
 
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
        public struct TSteamAppStats
        {
            public uint NumApps;
            public uint MaxNameChars;
            public uint MaxVersionLabelChars;
            public uint MaxLaunchOptions;
            public uint MaxLaunchOptionDescChars;
            public uint MaxLaunchOptionCmdLineChars;
            public uint MaxNumIcons;
            public uint MaxIconSize;
        }
 
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
        public struct TSteamApp
        {
            public string Name;
            public uint maxNameChars;
            public string latestVersionLabel;
            public uint maxLatestVersionLabelChars;
            public string currentVersionLabel;
            public uint maxCurrentVersionLabelChars;
            public string cacheFile;
            public uint maxCacheFileChars;
            public uint id;
            public uint latestVersionId;
            public uint currentVersionId;
            public uint minCacheFileSizeMB;
            public uint maxCacheFileSizeMB;
            public uint numLaunchOptions;
            public uint numIcons;
            public uint numVersions;
            public uint numDependencies;
        }
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamGetAppStats(ref TSteamAppStats AppStats, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamGetAppIds(uint[] AppIDs, uint MaxAppIDs, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamEnumerateApp(uint AppID, ref TSteamApp AppStruc, ref TSteamError SteamErr);
 
        [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SteamIsAppSubscribed(uint AppID, ref uint IsAppSubscribed, ref uint IsAppReady, ref TSteamError SteamErr);
 
        private string printGame(uint gameID)
        {
            switch (gameID)
            {
                case 10:
                    return "Counter-Strike";
                    break;
                case 20:
                    return "Team Fortress Classic";
                    break;
                case 30:
                    return "Day of Defeat";
                    break;
                case 40:
                    return "Deathmatch Classic";
                    break;
                case 50:
                    return "Opposing Force";
                    break;
                case 60:
                    return "Ricochet";
                    break;
                case 70:
                    return "Half-Life";
                    break;
                case 80:
                    return "Condition Zero";
                    break;
                case 100:
                    return "Condition Zero Deleted Scenes";
                    break;
                case 130:
                    return "Half-Life: Blue Shift";
                    break;
                case 220:
                    return "Half-Life 2";
                    break;
                case 240:
                    return "Counter-Strike: Source";
                    break;
                case 280:
                    return "Half-Life: Source";
                    break;
                case 300:
                    return "Day of Defeat: Source";
                    break;
                case 320:
                    return "Half-Life 2: Deathmatch";
                    break;
                case 340:
                    return "Half-Life 2: Lost Coast";
                    break;
                case 360:
                    return "Half-Life Deathmatch: Source";
                    break;
                case 380:
                    return "Half-Life 2: Episode One";
                    break;
                case 400:
                    return "Portal";
                    break;
                case 420:
                    return "Half-Life 2: Episode Two";
                    break;
                case 440:
                    return "Team Fortress 2";
                    break;
                case 1300:
                    return "SiN Episodes: Emergence";
                    break;
                case 2100:
                    return "Dark Messiah of Might and Magic";
                    break;
                case 2400:
                    return "The Ship";
                    break;
                case 4000:
                    return "Garry's Mod";
                    break;
                case 1200: return "Red Orchestra  Ostfront 41-45"; break;
                case 1210: return "Red Orchestra Beta"; break;
                case 1309: return "SiN 1 Multiplayer"; break;
                case 1313: return "SiN 1"; break;
                case 1500: return "Darwinia"; break;
                case 1510: return "Uplink"; break;
                case 1520: return "DEFCON"; break;
                case 1600: return "Dangerous Waters"; break;
                case 1610: return "Space Empires IV Deluxe"; break;
                case 1620: return "Jagged Alliance 2 Gold"; break;
                case 1630: return "Disciples II  Rise of the Elves"; break;
                case 1640: return "Disciples II  Galleans: return"; break;
                case 1660: return "Birth of America"; break;
                case 1670: return "Iron Warriors  T72 Tank Command"; break;
                case 1690: return "Space Empires V"; break;
                case 1700: return "Arx Fatalis"; break;
                case 1900: return "Earth 2160"; break;
                case 2200: return "Quake III Arena"; break;
                case 2270: return "Wolfenstein 3D"; break;
                case 2280: return "The Ultimate Doom"; break;
                case 2290: return "Final Doom"; break;
                case 2300: return "Doom II"; break;
                case 2310: return "Quake"; break;
                case 2320: return "Quake II"; break;
                case 2330: return "Quake II Mission Pack 1  The Reckoning"; break;
                case 2340: return "Quake II Mission Pack 2  Ground Zero"; break;
                case 2350: return "Quake III  Team Arena"; break;
                case 2360: return "Hexen"; break;
                case 2370: return "Hexen  Deathkings of the Dark Citadel"; break;
                case 2390: return "Heretic  Shadow of the Serpent Riders"; break;
                case 2500: return "Shadowgrounds"; break;
                case 2520: return "Gumboy - Crazy Adventures"; break;
                case 2610: return "GUN"; break;
                case 2620: return "Call of Duty"; break;
                case 2625: return "Call of Duty Singleplayer"; break;
                case 2630: return "Call of Duty 2 Multiplayer"; break;
                case 2635: return "Call of Duty 2 Singleplayer"; break;
                case 2640: return "Call of Duty  United Offensive"; break;
                case 2720: return "ThreadSpace  Hyperbol Stress Test"; break;
                case 2740: return "ThreadSpace  Hyperbol Dedicated Server"; break;
                case 2800: return "X2  The Threat"; break;
                case 2810: return "X3  Reunion"; break;
                case 2900: return "688(I) Hunter-Killer"; break;
                case 2910: return "Fleet Command"; break;
                case 2920: return "Sub Command"; break;
                case 2930: return "Birth of America"; break;
                case 2990: return "FlatOut 2"; break;
                case 3000: return "GTI Racing"; break;
                case 3010: return "Xpand Rally"; break;
                case 3300: return "Bejeweled 2 Deluxe"; break;
                case 3200: return "Painkiller Gold Edition"; break;
                case 3310: return "Chuzzle Deluxe"; break;
                case 3320: return "Insaniquarium Deluxe"; break;
                case 3330: return "Zuma Deluxe"; break;
                case 3340: return "AstroPop Deluxe"; break;
                case 3350: return "Bejeweled Deluxe"; break;
                case 3360: return "Big Money Deluxe"; break;
                case 3370: return "Bookworm Deluxe"; break;
                case 3380: return "Dynomite Deluxe"; break;
                case 3390: return "Feeding Frenzy 2 Deluxe"; break;
                case 3400: return "Hammer Heads Deluxe"; break;
                case 3410: return "Heavy Weapon Deluxe"; break;
                case 3420: return "Iggle Pop Deluxe"; break;
                case 3430: return "Pizza Frenzy Deluxe"; break;
                case 3440: return "Rocket Mania Deluxe"; break;
                case 3450: return "Typer Shark Deluxe"; break;
                case 3460: return "Talismania Deluxe"; break;
                case 3470: return "Bookworm Adventures Deluxe"; break;
                case 3700: return "Sniper Elite"; break;
                case 3800: return "Advent Rising"; break;
                case 3810: return "BloodRayne"; break;
                case 3820: return "BloodRayne 2"; break;
                case 3830: return "Psychonauts"; break;
                case 3900: return "Sid Meier's Civilization IV"; break;
                case 3910: return "Sid Meier's Civilization III Complete"; break;
                case 3920: return "Sid Meier's Pirates!"; break;
                case 3930: return "Serious Sam 2"; break;
                case 3960: return "Shattered Union"; break;
                case 3970: return "Prey"; break;
                case 4100: return "Poker Superstars II"; break;
                case 4200: return "RACE Internal Beta"; break;
                case 4230: return "RACE"; break;
                case 4300: return "RoboBlitz"; break;
                case 4400: return "City Life"; break;
                case 4410: return "City Life Deluxe"; break;
                case 4500: return "S.T.A.L.K.E.R.  Shadow of Chernobyl"; break;
                case 4600: return "Full Pipe"; break;
                case 4700: return "Medieval II  Total War"; break;
                case 4730: return "Outrun 2006  Coast 2 Coast"; break;
                case 4800: return "Heroes of Annihilated Empires"; break;
                case 4900: return "Zen of Sudoku"; break;
                case 6100: return "Eets"; break;
                case 6200: return "Ghost Master"; break;
                case 6210: return "Vegas Make It Big"; break;
                case 6300: return "Dreamfall  The Longest Journey"; break;
                case 6310: return "The Longest Journey"; break;
                case 6400: return "Joint Task Force"; break;
                case 6510: return "Lost Planet Extreme Condition"; break;
                case 6570: return "Onimusha 3  Demon Siege"; break;
                case 6600: return "Bullet Candy"; break;
                case 6880: return "Just Cause"; break;
                case 7060: return "Infernal"; break;
                case 7110: return "Jade Empire  Special Edition"; break;
                case 7420: return "Wik and the Fable of Souls"; break;
                case 7600: return "Sid Meier's Railroads"; break;
                case 7670: return "Bioshock"; break;
                case 8400: return "Geometry Wars"; break;
                case 9000: return "Spear of Destiny"; break;
                case 9010: return "Return to Castle Wolfenstein"; break;
                case 9030: return "Quake Mission Pack 2  Dissolution of Eternity"; break;
                case 9040: return "Quake Mission Pack 1  Scourge of Armagon"; break;
                case 9050: return "Doom 3"; break;
                case 9060: return "Hexen II"; break;
                case 9070: return "Doom 3  Resurrection of Evil"; break;
                case 9180: return "Commander Keen"; break;
                default:
                    return "Unknown Game";
                    break;
            }//switch
 
        }//printGame
 
 
 
        #endregion
 
        private void btnGames_Click(object sender, EventArgs e)
        {
            TSteamError SErr = new TSteamError();
            int iSteamReturn = 0;
            TSteamAppStats AppStats = new TSteamAppStats();
 
            iSteamReturn = SteamGetAppStats(ref AppStats, ref SErr);
 
            if (AppStats.NumApps > 0)
            {
 
                uint[] RawAppIDs;
                RawAppIDs = new uint[AppStats.NumApps];
                iSteamReturn = SteamGetAppIds(RawAppIDs, AppStats.NumApps, ref SErr);
 
                foreach (uint RawAppID in RawAppIDs)
                {
 
                    TSteamApp AppNFO = new TSteamApp();
                    AppNFO.Name = new String(' ', 255);
                    AppNFO.maxNameChars = 255;
                    AppNFO.currentVersionLabel = new String(' ', 255);
                    AppNFO.maxCurrentVersionLabelChars = 255;
                    AppNFO.latestVersionLabel = new String(' ', 255);
                    AppNFO.maxLatestVersionLabelChars = 255;
                    AppNFO.cacheFile = new String(' ', 255);
                    AppNFO.maxCacheFileChars = 255;
 
                    iSteamReturn = SteamEnumerateApp(RawAppID, ref AppNFO, ref SErr);
 
                    //Do Something!
                    rtbOutput.Text += "-Checkpoint.\n";
                }
 
            }
 
 
        }
 
        private void btnTest_Click(object sender, EventArgs e)
        {
            TSteamError SErr = new TSteamError();
            int iSteamReturn = 0;
            uint isAppSubscribed = 0;
            uint isAppReady = 0;
            uint AppID = 70;
            iSteamReturn = SteamIsAppSubscribed(AppID, ref isAppSubscribed, ref isAppReady, ref SErr);
 
            if (isAppSubscribed == 1)
            {
                //Do Something!
                rtbOutput.Text += "-Half-Life\n";
            } 
        }
 
        private void frmMain_Load(object sender, EventArgs e)
        {
            if (!File.Exists(Application.StartupPath + "\\steam.dll"))
            {
                MessageBox.Show("Steam.dll must be placed in the same directory as this program.", "Error");
                this.Close();
            }
        }
 
        private void btnStart_Click_1(object sender, EventArgs e)
        {
            btnManualCheck.Enabled = false;
            btnStart.Enabled = false;
 
            rtbOutput.Text += "[Started]\n\n";
            Application.DoEvents();
 
            if (cbUsername.Checked == true)
            {
                foreach (ListViewItem item in lvAccounts.Items)
                {
                    checkForGames(item.SubItems[0].Text, item.SubItems[1].Text);
                }
            }
 
            if (cbEmail.Checked == true)
            {
                foreach (ListViewItem item in lvAccounts.Items)
                {
                    checkForGames(item.SubItems[2].Text, item.SubItems[1].Text);
                }
            }
 
            rtbOutput.Text += "\n\n[Finished]";
 
            btnManualCheck.Enabled = true;
            btnStart.Enabled = true;
        }
 
        private void checkForGames(string tSteamUserName, string tSteamPassword)
        {
 
 
            TSteamError SErr = new TSteamError();
            int iSteamReturn = 0;
            int iUserSet = 0;
            int isLoggedIn = 0;
            string SteamUserName = tSteamUserName;
            string SteamUserPassword = tSteamPassword;
            uint sHandle;
            uint startoptions = 15;
 
            //iSteamReturn = SteamStartEngine(ref SErr); //code below checks for errors
 
            iSteamReturn = SteamStartEngine(ref SErr);
            if (SErr.eSteamError != eSteamError.eSteamErrorNone) { MessageBox.Show("Steam Error : " + SErr.ErrDescription); }
 
            iSteamReturn = SteamStartup(startoptions, ref SErr);
 
            TSteamProgress TProgress = new TSteamProgress();
            TProgress.Valid = 1;
 
            sHandle = SteamLogin(SteamUserName, SteamUserPassword, 1, ref SErr);
 
            while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
            {
                Application.DoEvents();
            }
 
            iSteamReturn = SteamIsLoggedIn(ref isLoggedIn, ref SErr);
 
            if (isLoggedIn == 1)
            {
 
                sHandle = SteamSetUser(SteamUserName, ref iUserSet, ref SErr);
 
                TProgress = new TSteamProgress();
                TProgress.Valid = 1;
 
                while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
                {
                    Application.DoEvents();
                }
 
                if (iUserSet == 1)
                {
                    //We are now authenticated
 
                    rtbOutput.Text += "[" + tSteamUserName + "]\n\n";
                    rtbOutput.Text += "[Games]\n";
 
                    uint isAppSubscribed = 0;
                    uint isAppReady = 0;
                    //uint AppID = 70; //only used in original code
                    uint[] AppIDs = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 130, 220, 240, 280, 300, 320, 340, 360, 380, 400, 420, 440, 1300, 2100, 2400, 4000,
                        1001,
                        1200,
                        4145,
                        1210,
                        1309,
                        1313,
                        1500,
                        1510,
                        1520,
                        1600,
                        1610,
                        1620,
                        1630,
                        1640,
                        1660,
                        1670,
                        1690,
                        1700,
                        1900,
                        2160,
                        2200,
                        2270,
                        2280,
                        2290,
                        2300,
                        2310,
                        2320,
                        2330,
                        2340,
                        2350,
                        2360,
                        2370,
                        2390,
                        2500,
                        2520,
                        2610,
                        2620,
                        2625,
                        2630,
                        2635,
                        2640,
                        2720,
                        2740,
                        2800,
                        2810,
                        2900,
                        2910,
                        2920,
                        2930,
                        2990,
                        3000,
                        3010,
                        3300,
                        3200,
                        3310,
                        3320,
                        3330,
                        3340,
                        3350,
                        3360,
                        3370,
                        3380,
                        3390,
                        3400,
                        3410,
                        3420,
                        3430,
                        3440,
                        3450,
                        3460,
                        3470,
                        3700,
                        3800,
                        3810,
                        3820,
                        3830,
                        3900,
                        3910,
                        3920,
                        3930,
                        3960,
                        3970,
                        4100,
                        4200,
                        4230,
                        4300,
                        4400,
                        4410,
                        4500,
                        4600,
                        4700,
                        4730,
                        4800,
                        4900,
                        6100,
                        6200,
                        6210,
                        6300,
                        6310,
                        6400,
                        6510,
                        6570,
                        6600,
                        6880,
                        7060,
                        7110,
                        7420,
                        7600,
                        7670,
                        8400,
                        9000,
                        9010,
                        9030,
                        9040,
                        9050,
                        9060,
                        9070,
                        9180};
 
                    for (int index = 0; index < AppIDs.Length; index++)
                    {
 
                        //iSteamReturn = SteamIsAppSubscribed(AppID, ref isAppSubscribed, ref isAppReady, ref SErr);
                        iSteamReturn = SteamIsAppSubscribed(AppIDs[index], ref isAppSubscribed, ref isAppReady, ref SErr);
 
                        if (isAppSubscribed == 1)
                        {
                            //Do Something!
                            //rtbOutput.Text += "-Half-Life\n";
                            if (printGame(AppIDs[index]) == "Unknown Game")
                            {
                                rtbOutput.Text += "-Unknown Game (AppID: " + AppIDs[index] + ")\n";
                            }
                            else
                            {
                                rtbOutput.Text += "-" + printGame(AppIDs[index]) + "\n";
                            }
                        }
 
                        Application.DoEvents();
                    }
 
 
                    //end of games list
                    rtbOutput.Text += "[End]";
 
                }
 
            }
            else
            {
                rtbOutput.Text += "[Invalid Account] " + tSteamUserName + "\n";
            }
 
            sHandle = SteamLogout(ref SErr);
 
            TProgress = new TSteamProgress();
            TProgress.Valid = 1;
 
            while (SteamProcessCall(sHandle, ref TProgress, ref SErr) == 0)
            {
                Application.DoEvents();
            }
 
            iSteamReturn = SteamCleanup(ref SErr);
 
            iSteamReturn = SteamShutdownEngine(ref SErr);
            
        }
 
        private void frmSteamGameChecker_FormClosing(object sender, FormClosingEventArgs e)
        {
            setBreak = 1; //end steam loops
        }
    }
}

Open in new window

Top Expert 2007

Commented:
That C# code appears to hold the key, as you say.

For example, the C# code defines
   [DllImport("steam.dll", CallingConvention = CallingConvention.Cdecl)]
   public static extern int SteamStartup(uint UsingMask, ref TSteamError SteamErr);

In C++, that appears as
   int (*SteamStartup)(unsigned int UsingMask, TSteamError& SteamErr);
and
   SteamStartup = (int (*)(unsigned int, TSteamError&)) GetProcAddress(steamDLL, "SteamStartup");
   iSteamReturn = SteamStartup(startoptions, SErr);

You'll need to make similar changes for
   int (*SteamStartEngine)(TSteamError& SteamErr);
   int (*SteamStartup)(unsigned int UsingMask, TSteamError& SteamErr);
   int (*SteamLogin)(char* User, char* Password, int isSecureComputer, TSteamError& SteamErr);
   int (*SteamSetUser)(char* User, int& UserSet, TSteamError& SteamErr);
   int (*SteamIsLoggedIn)(int& isLoggedIn, TSteamError& SteamErr);
   int (*SteamLogout)(TSteamError& SteamErr);
   int (*SteamCleanup)(TSteamError& SteamErr);
   int (*SteamShutdownEngine)(TSteamError& SteamErr);
   int (*SteamIsAppSubscribed)(int AppID, int& IsAppSubscribed, int& IsAppReady, TSteamError& SteamErr);
and comment out the calls I made
   //(*SteamStartup) (UsingMask, SteamErr);
   //(*SteamLogin) (User, Password, isSecureComputer, SteamErr);
   //(*SteamSetUser) (User, UserSet, SteamErr);
   //(*SteamIsLoggedIn) (isLoggedIn, SteamErr);
   //(*SteamLogout) (SteamErr);
   //(*SteamCleanup) (SteamErr);
   //(*SteamShutdownEngine) (SteamErr);
   //(*SteamIsAppSubscribed) (AppID, IsAppSubscribed, IsAppReady, SteamErr);
since you have your own calls in your code

There are also several argument type changes to match actual parameters passed, which the compiler will point out to you.

The C# code defines TSteamProgress
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
        public struct TSteamProgress
        {
            public int Valid;
            public int Percent;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
            public string Progress;
        }
which I believe translates to C++ as
   struct TSteamProgress {
      int Valid;
      int Percent;
      char Progress[255];
   };
you'll need to make similar updates to struct TSteamError, struct TSteamApp, and struct TSteamAppStats.
trinitrotolueneDirector - Software Engineering

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial