Visual Studio C Slot Machine

Last year for Workstation 6.0, one of the features we added was a plugin for Visual Studio 2005 that allows developers to debug a project (native and managed C/C++, C#, or Visual Basic) inside of a Windows virtual machine (specifically Windows 98, Windows 2000, and later). All of you Windows developers know how much of a pain it is to support multiple versions of Windows, but this tool is designed to make that process much, much easier. The Visual Studio Integrated Debugger (VSID in short) plugin utilizes Visual Studio remote debugging technology to allow you to debug a project inside of a VM as if you were debugging on your host computer with the click of one button.

IMPORTANT: If you have installed previous pre-release versions of Visual C 2008 or Visual Studio 2008, such as Beta 1, Beta 2 or Community Technical Preview (CTP) builds, then you must uninstall these versions via Add/Remove Programs in Control Panel before installing the final released version.

The plugin’s toolbar and menu, added to Visual Studio 2005:

  1. I am trying to write a simple slot machine program that will return three numbers as the slot icons using a loop. I can get the first part just fine (I think). But I am stuck at converting my icons to intergers or character that I can compare to see if it is a winner or not. Here so far: // slot.
  2. Visual Studio.NET's Setup project File System view lets you choose which files will be installed and where they will go. Figure 6-12 shows a typical File System view in a normal Setup project. (Web Setup projects have different defaultsthey just have a single folder labeled Web Application Folder.).


The most difficult part of getting all of this to work is the initial setup. Once you can get your configuration working,
it should work well for a long time. But it is certainly a chore getting your host and guest set up to comply with all of the security regulations that Microsoft requires to successfully remotely debug on another machine. This walkthrough is intended to get you through the process of setting up remote debugging and provide helpful troubleshooting tips in case everything does not go smoothly.

For a full list of all setup steps, Chapter 2 in the VSID manual is a must-read (open up Visual Studio 2005 and go to the VMware menu and click Help Topics), but I will try and summarize the main points. The first thing you will need to do is to make sure that you have the same username and password on your host and guest. This is a built-in security requirement so not just anyone can remotely debug in your machine; Visual Studio automatically uses your host’s login and password as authentication and if they are different than the guest’s, it won’t work. It is very strongly recommended that both your host and guest be on the same domain (or if not on a domain, that they both be in the same workgroup), although my own testing has shown me that it is not always necessary. Anecdotally, I have found that Vista hosts are a little more strict about this than XP hosts, but it is certainly suggested if at all possible.

The next task is to configure the firewall on both your host and guest. For the guest, we recommend that you disable the firewall. For the host, I would recommend that at the least, you set Visual Studio as an exception so that the firewall leaves it alone. If possible, I have found it helpful to disable the firewall on your host as well, because it can sometimes be a bit disruptive. If you have any other security products running on your host or guest, you should make sure that they are also configured correctly. For more information about setting up remote debugging, here are some instructions from Microsoft. This is such a crucial step and I have found that most remote debugging failures come from a host firewall blocking remote debugging.

The final step in setting up remote debugging is changing a few settings in your guest. Here is a short list:

  1. Disable the security prompts that come from running programs off a network share (which is what happens when the plugin runs your host program in the guest through Shared Folders). To do this, open up Internet Explorer, choose Tools > Internet Options > Security > Local Intranet, click Sites, click Advanced and add a new Web site 'file://*.host' (without the quotes).
  2. Make sure the name of your virtual machine is unique on the domain. Conflicts like this often happen if virtual machines are cloned and handed around between multiple people. To change it, go to Start > Control Panel > System > Computer Name and select Change. On Windows 2000, the tab is named 'Network Identification' instead of 'Computer Name'.
  3. For Windows XP virtual machines, change the guest user authentication scheme to Classic. To do this, go to the Control Panel > Administrative Tools > Local Security Policy > Local Policies > Security Options page and set 'Network access: Sharing and security model for local accounts' to 'Classic – local users authenticated as themselves'. Windows XP Home does not have this setting and does not respect it even if you set the corresponding registry key, so that’s why we don’t support debugging in XP Home guests.
  4. If you are running a Windows 98 VM, you will need to perform a couple of extra steps. Take a look at the VSID user manual for the list.

Visual Studio C Slot Machine Software

Now that you have your virtual machine set up for remote debugging, it’s time to set up your Visual Studio project. Thankfully, this is much easier. If the VSID plugin has been installed in Visual Studio 2005, you should see an extra toolbar and a VMware menu. To configure your project, open up your solution in Visual Studio and go to the VMware menu and click Options. To set up your project for remote debugging enter the following pieces of information:

Program C In Visual Studio

  1. In the Command space, enter the full path to the executable that you want to debug in the guest. If it is a path on your host machine, make sure 'Run Command as' is set to 'a host path through a shared folder'. If it is a path in your virtual machine, make sure that 'Run Command as' is set to 'a guest path'.
  2. Verify that the Remote Debug Monitor path is set correctly. If you are debugging a 32-bit application, it should be the path to the 32-bit remote debug monitor. If you are debugging a 64-bit application, it should be the path to the 64-bit remote debug monitor. Typically, the 32-bit remote debug monitor is installed in %Program Files%Microsoft Visual Studio 8Common7IDERemote Debuggerx86msvsmon.exe.
  3. Click 'Virtual Machine' in the left column and enter the path to the virtual machine in the 'Virtual Machine' space of that page.
  4. Look through any other options that you would like to specify. However, all other settings are optional or already have a default specified.

One of the configuration pages:

If all goes well, you should be able to start debugging in your virtual machine by hitting VMware > Start. Free video slots gladiator. If you get an error message, the unfortunate situation is that the Visual Studio extensibility framework doesn’t give us any information about why debugging failed, so you are left to go through more official routes to get that information.

The first reason why debugging often fails is that your virtual machine is not configured to run your application properly. If your application requires the .NET Framework to be installed, make sure that it is installed. You should also make sure that all the dll’s you need are registered in the guest and any other configurations are all correct. To verify that your application is configured properly, simply go to the VMware menu in Visual Studio and select Start Without Debugging. If your application runs properly, then you don’t have any of these problems. But often times you will see an error message complaining that a required component is missing. This is probably the reason why remote debugging is failing, because Visual Studio is trying to debug the program in your guest but the program can’t even run successfully.

Visual Studio C Slot Machine

If you are still running into problems, the next step is to manually remotely debug in your virtual machine using Visual Studio’s built-in framework. The reason why this is important is that Visual Studio will give you much more descriptive error messages than the extensibility framework gives to the plugin. Here are the steps to set it up using a C/C++ project:

  1. With your virtual machine running, go to Workstation, open up the VM Settings editor, select the Options tab, and select Shared Folders. Enable Shared Folders and add two shared folders: 1) Add the folder your application is being compiled in on your host machine; name it 'Project'. 2) Add the folder where the remote debug monitor is on your host machine; name it 'RDM'.
  2. Go into your guest and open up .hostShared FoldersRDMmsvsmon.exe. This is the equivalent of running your host’s remote debug monitor in your guest.
  3. Open up the Project menu and select Properties. Open up the Configuration Properties node on the left and select Debugging. Now write down any existing debugging settings you have, because we may be overwriting these.
  4. Under 'Debugger to launch:' select Remote Windows Debugger. For 'Remote Command', enter the path to your host executable using the Shared Folder you just created. This will be .hostShared FoldersProject<executable name>.exe
  5. Change 'Remote Server Name' to the name of the server that the remote debug monitor created in your guest. To find this, look in your guest at the remote debug monitor; it should say something like 'msvsmon started a new server named ‘grossag@foo’. Waiting for new connections.' In this case, the remote server name is grossag@foo
  6. Now go to Start > Debug. If remotely debugging through the VMware plugin wasn’t working, then this should fail as well and give you a better error message.

If debugging fails with the following error, you should follow the troubleshooting tips above. Big shot slot machine.

C In Visual Studio

Well that’s about it for me. Good luck with remote debugging and feel free to post any questions that you have! And I almost forgot that if you are looking for Visual Studio 2008 support, feel free to download our new Workstation 6.5 beta, although I will warn you that the current beta (build 84113) doesn’t work well with debugging in Windows 2000 guests.

Visual Studio C Project

P: 8
I need some help. I am getting an error of: local function definitions are illegal. What does this mean? Can anybody help me out a little? Thank you.
//Specification: This program simulates a three
//wheeled slot machine. Each wheel will randomly
//display three numbers. When the numbers on the
//wheels match the user is award points. The Slot
//machine requires the user to enter tokens to play.
#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
class slotMachine {
private:
int wheelA;
int wheelB;
int wheelC;
double payOut; //amount of $ won during the current turn
double moneyInMachine; //total amount of $ in the machine
double playersBalance; //the amount of $ not yet played
double gameCost; //the cost of one pull
double moneyPaid; //the money put in by user
public:
//prototypes
slotMachine();
bool displayMenu(void);
bool pullHandle(void);
void spinWheel(int &);
double calculatePayout();
void insertCoin(double );
void displaySpinResults();
int Random(int, int);
void displayTotals();
};
int main(void) {
//create a slot machine object
slotMachine mySlot;
//Start the slot machine game
//Keep running until the user
//decides to quit
bool ok = true;
while (ok){
ok = mySlot.displayMenu();
}
return 0;
}
slotMachine::slotMachine () {
//constructor, set the initial state
//of all the properties
srand((int) time(0));
moneyInMachine = 100;
moneyPaid = 0;
payOut = 0;
wheelA = 0;
wheelB = 0;
wheelC = 0;
gameCost = 1;
}
bool slotMachine::displayMenu(void){
//main menu, executes the command selected by the
//user or returns a value to terminate game execution
//variable
int choice = 0;
//declare variables
char usersChoice = 'E';
bool continueGame = true;
//display menu opitions
cout << 'Welcome to Las Vegas Casino n';
cout << 'Please choose an option: n';
cout << '(E)nd, (P)ull, P(A)Y, (T)otals';
//get the input
cin >> usersChoice;
switch (usersChoice){
case 'E': //end game
continueGame = false;
break;
case 'A': //pay
continueGame = true;
//prompt user to pay
cout << 'Please enter $1.00. n' << gameCost << endl;
//get input
cout << 'Thank you for entering your money. n' << moneyPaid << endl;
break;
case 'P': //user pulls the handle
continueGame = true;
if (pullHandle()){
displaySpinResults();
calculatePayout();
break;
case 'T': //show the totals
continueGame = true;
displayTotals();
break;
}
return continueGame;
}
bool slotMachine::pullHandle(void){//local function defintions are illegal
//checks to see if there is money
//given by user then assigns a random value
//to each wheel. Deducts the cost of one
//pull from the users money.
double moneyInMachine = 100;
int wheelA = 1;
int wheelB = 2;
int wheelC = 3;
moneyInMachine = moneyInMachine - moneyPaid;
cout << 'You have n' << moneyInMachine << endl;
return true;
}
void slotMachine::spinWheel(int &theWheel){//local function definitions are illegal
//assign a random value to a wheel
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
wheelA;
{
wheelA = 1 + rand() % (3 - 1 + 1);
}
wheelB;
{
wheelB = 1 + rand() % (3 - 1 + 1);
}
wheelC;
{
wheelC = 1 + rand() % (3 - 1 + 1);
}
}
double slotMachine::calculatePayout(){// local function defintions are illegal
//decides if the current wheel values merit a
//payout and how much that payout should be.
//deducts the total payout from the total
//amount of money in the machine
int jackPot = 1000;
int goodJob = 10;
int youLose = -5;
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
wheelA wheelB && wheelA wheelC;
{
cout << 'Jackpot!!!' << jackPot << endl;
}
wheelA wheelB || wheelA wheelC || wheelB wheelC;
{
cout << 'Good Job' << goodJob << endl;
}
jackPot;
{
moneyInMachine = moneyInMachine + jackPot;
}
goodJob;
{
moneyInMachine = moneyInMachine + goodJob;
}
return moneyInMachine;
}
void slotMachine::insertCoin(double amount = 0.0){ //local function definitions are illegal
//adds to the amount of money paid by the user
//adds to the total money in the machine
int moneyInMachine = 100;
int moneyPaid = 0;
moneyInMachine = moneyPaid + moneyInMachine;
}
void slotMachine::displaySpinResults(){
//displays the value of the three wheels
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
cout << 'First wheel shows: n' << wheelA << endl;
cout << 'Second wheel shows: n' << wheelB << endl;
cout << 'Third wheel shows: n' << wheelC << endl;
}
void slotMachine::displayTotals(){
//displays the total money in the machine and the number
//of pulls the user has left
cout << 'You have this much money left: $' << moneyInMachine << endl;
cout << 'You have this many turns left: ' << endl;
}
int slotMachine::Random(int lowerLimit, int upperLimit) {
//returns a random number within the given boundary
return 1 + rand() % (upperLimit - lowerLimit + 1);
}
}