Sorry the title is kind of confusing, but it is the best way I could explain it without taking up too much space. And please excuse my formatting, I'm pretty new to stackoverflow. Here is the problem, I have some sample code that I found for a C# wrapper for a C++ SDK. The program that uses the SDK is called ActiveWorlds. The code is here:
using System;
using AW;
namespace GreeterBotCSharp
{
class GreeterBot
{
/// <summary>
/// Main entry point into the GreeterBot program.
/// </summary>
/// <param name="args">Command line arguments.</param>
static void Main(string[] args)
{
//Prompt the user for their citizen number.
Console.Write("Enter citizen number: ");
int citizenNumber = int.Parse(Console.ReadLine());
//Prompt the user for their privilege password.
Console.Write("Enter privilege password: ");
string privilegePassword = Console.ReadLine();
//Prompt the user for a world to enter.
Console.Write("Enter a world name: ");
string world = Console.ReadLine();
//Create a new copy of the GreeterBot and run it.
GreeterBot bot = new GreeterBot();
bot.Run(citizenNumber, privilegePassword, world);
}
/// <summary>
/// Runs a new GreeterBot with the specified owner and privilege password.
/// </summary>
/// <param name="owner">The citizen number of the person who owns the bot.</param>
/// <param name="password">The privilege password of the person who owns the bot.</param>
/// <param name="world">The name of the world to greet in.</param>
private void Run(int owner, string password, string world)
{
try
{
//Create a new instance and set events
Instance greeterBot = new Instance();
greeterBot.EventAvatarAdd += new Instance.Event(greeterBot_EventAvatarAdd);
//Log the instance into the ActiveWorlds universe
try
{
greeterBot.SetInt(Attributes.LoginOwner, owner);
greeterBot.SetString(Attributes.LoginPrivilegePassword, password);
greeterBot.SetString(Attributes.LoginName, "GreeterBot");
greeterBot.Login();
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to login (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
//Enter a world and attempt to go to ground zero.
try
{
greeterBot.Enter(world);
greeterBot.StateChange();
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to enter world at ground zero (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
//Event dispatch loop. This is important, without it events would not be dispatched appropriately.
while (Utility.Wait(-1) == 0) ;
}
catch (InstanceException ex)
{
Console.WriteLine("Unexpected Error (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
}
/// <summary>
/// Event handler for avatars entering the proximity of the bot.
/// </summary>
/// <param name="sender">The instance that received the event. This is extremely important,
/// especially if instances share common event handlers. We use it here to control the instance.</param>
void greeterBot_EventAvatarAdd(Instance sender)
{
try
{
//Store the session and name of the avatar, and the name of the world.
int userSession = sender.GetInt(Attributes.AvatarSession);
string userName = sender.GetString(Attributes.AvatarName);
string worldName = sender.GetString(Attributes.WorldName);
//Greet the user via a whisper. Whisper makes use of a session number to target a user
//Session numbers are an extremely important concept in the SDK and are used to identify
//users when certain events occur or when sending some command to a specific user.
sender.Whisper(userSession, "Welcome to {0}, {1}! Enjoy your stay.", worldName, userName);
//Show that the user was greeted on the console.
Console.WriteLine("Greeter user {0}.", userName);
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to greet user (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
}
}
}
}
But it doesn't work! Here is my specs:
- Microsoft Windows 8.1
- Microsoft Visual Studio Express 2012 for Windows
- mcafee Internet Security (You never know...)
Here is what the project consists of:
- A Visual C# Empty Project
- x86 solution platform(required)
And includes the following files
- A C# Class called MainScript.cs (which houses the code above)
- An AW.Core.dll file in the project's root folder, added as a Reference. (This is the wrapper)
- An Aw.dll file located in RootFolder\bin\x86\Release\ (This is the C++ DLL used by the wrapper)
- The usual things in a C# Empty Project
those are the only things I have adjusted The errors I get are:
Error 3 'AW.Utility' does not contain a definition for 'ReturnCodes' Line 54 Column 81
Error 5 'AW.Utility' does not contain a definition for 'ReturnCodes' Line 66 Column 102
Error 7 'AW.Utility' does not contain a definition for 'ReturnCodes' Line 76 Column 78
Error 9 'AW.Utility' does not contain a definition for 'ReturnCodes' Line 105 Column 82
Error 1 The type name 'Events' does not exist in the type 'AW.Instance' Line 42 Column 59
Error 2 The type or namespace name 'InstanceException' could not be found (are you missing a using directive or an assembly reference?) Line 52 Column 24
Error 4 The type or namespace name 'InstanceException' could not be found (are you missing a using directive or an assembly reference?) Line 64 Column 24
Error 6 The type or namespace name 'InstanceException' could not be found (are you missing a using directive or an assembly reference?) Line 74 Column 20
Error 2 The type or namespace name 'InstanceException' could not be found (are you missing a using directive or an assembly reference?) Line 103 Column 20
You may be wondering where you can get your hands on the .dlls, here is a few links
- The Activeworlds SDK (The C++ .dll) is found here: http://wiki.activeworlds.com/index.php?title=SDK
- The download for the SDK (The C++ .dll) I'm using is here: http://objects.activeworlds.com/downloads/awsdk101.zip
- The source code for the wrapper (The C# .dll) you can find here:
https://github.com/Bloyteg/AW.SDK.Core
(Note, the information may not be all that accurate) - The download for the C# wrapper you can find here:
https://github.com/Bloyteg/AW.SDK.Core/releases/download/0.3.14.100/AW.Core.zip
(The reason for the quotes is because I can't post any more links)
Please take a look at this. I'm very new to Visual Studio because I usually code in Unity 3D with MonoDevelopment. I'm an ameteur C# coder so please be patient. This is a not very well documented process and often the developers who work with it are to busy for the likes of me. Plus the other coders use VB.net and C++ rather than C#.