Hello all, Visual C++ Express ?

Dedicated Forum for developers of programs/utilities. To announce new or updated products, to share knowledge and ideas for development.

Moderator: CrazySchmidt

Hello all, Visual C++ Express ?

Postby BaLrOg on Sun May 14, 2006 8:04 pm

Hello Gents,

I was wondering if there are any among you that have had some coding experience with the MS visual C++ Epress enviroment and could provide a novice with a little help on my way to learning the above?

I am trying to learn this simplified version of the C++ language suite with a view to 'eventauly' implementing WWSensei's Devicelink wrapper to develop simple applications (primarily for my own use) that will enhance my flight simpit with out the need for multiple joysticks buttons and bells.

However as with all those that try to run before they can walk I have fallen flat on my face at the first hurdle.

My problem seems to stem from the configuration of the Visual C++ Express enviroment, as whenever I try to compile WWSensei's wrapper I get errors when it comes to sections of code like the one below.

#include <windows.h>
#include <stdio.h>

Now I have followed to the letter the instructions for installing listed here

http://msdn.microsoft.com/vstudio/expre ... fault.aspx

but still the application reports that they cannot be found?

Any ideas, pointers, or suggestions of any kind would be greatly appreciated.

Regards

BaLrOg
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby CrazySchmidt on Sun May 14, 2006 8:16 pm

Sorry BaLrOg, I'm a VB guy and I still haven't made the move to dot NET :shock:

Good luck with it.

Cheers, CrazySchmidt. :)
User avatar
CrazySchmidt
Utilities Developer
 
Posts: 358
Joined: Wed Dec 08, 2004 1:59 am
Location: Auckland, New Zealand

Postby BaLrOg on Sun May 14, 2006 11:09 pm

No worries, I just thought I would ask.

(sorry about the double post there - page hung whilst I was posting)

I will keep plugging away at the problem myself any how and who knows I may have an epiphany along the way. Im sure its probably something straight forward that I am missing. Guess I am going to have to go the dreaded 'hello world' route, its just so dam boring lol

I did see your Tutorials on VB though and who knows if C++ gets to be to much I may give that a whirl too.

After all how hard can it be ....... :shock:
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby 3./JG51_Specter on Sun May 21, 2006 5:55 am

Balrog,

Have you figured it out yet? If you could post the error you're getting it might shed some more light on it.

One quick thing you could try is to do a file search for windows.h in the VC++ directory. Since this is a free version, microsoft might have only supplied their mfc classes and not the whole windows sdk.

I tried to take a look at what the error could possible be, but Sensei's link seems to be dead. I've never used VC++ express, but have used the pro version a little. I've been programming in C and C++ for a few years now.
Image
User avatar
3./JG51_Specter
Lance Air Corporal
 
Posts: 24
Joined: Sun May 21, 2006 4:09 am
Location: USA

Postby BaLrOg on Sun May 21, 2006 4:54 pm

Hi Specter, yes figured it out I had already downloaded the windows sdk but it would seem I had neglected to set the links up with in the editor to tell it where to look :oops:

So after setting them up it found them ok, that was only one hurdle though and I have decided it might be better for me to get myself a little more solid footing in the c++ language before I try to do anything with Sensei's wrapper.

I guess I was just crossing my fingers against my better judgement that it would be as straight forward as simply creating a form (that part with visual is quite simple) to interface with the wrapper ( this and the compilation process are the tricky bit for me).

I will keep pluging away though ,work permitting and every now and then have a stab at it. My main problem so far is that I need to spend some time familiarizing my self with the interface and the methods of compilation

Rest assured if I make any progress then I will post back with info.

What would be of use I guess would be the source for or advice on how a simple form that would allow you to select engines 1 ,2,3, or 4 could and should be compiled using the wrapper. I have obtained a gnu version of C++ called blood shed also and whilst it is not as noob freindly as visual 'looks' I suspect it will be of more use.

Also I now have the C++ primer plus ( a book with wich one could murder wombats if dropped from a great height) so if the worst comes to the worst I guess I could start at the begining with 'hello world'

A far cry from a touch screen interface for the control of my aircraft but a step I have accepted is going to be necessary if I am to get the kind of tools I require.

Also who knows it might actualy be fun I learnt to speak a little Norwegian I guess I could learn C++, however I doubt it will get me a beer in a pub :wink:

Thanks for your interest and any tips or pointers you can offer will be great!

Regards

Balrog
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby 3./JG51_Specter on Sun May 21, 2006 11:22 pm

That's good to hear, forgetting to link librariers is a common problem even with the more experienced.

First of all if you haven't seen this post yet, Sensei shows how to access his wrapper.

Now on to learning C++, that book will come in handy. I still have a beginner's reference that I look up from time to time, because I forget the exact behavior of a keyword or how inheritance is effected, etc ... If you are new to the Object Oriented paradigm, I would try to find a book on this also (if the one you have doesn't already cover it). When looking for info, look at java also. It is very similar to C++ and most of the ideas apply.

Here is how I would approach the engine program.

First, forget about a GUI for now. These are a major PITA if you are just learning. Start with a console app (i.e. dos window). Just like any complex system planning is key. Jumping right into coding without knowing how everything interacts or even what you want it to do.

I found this site . Its overly formalized for just starting to learn how to code, but it does give you an idea of how to approach your first programs.

For my first program I would make a text driven console application that would switch the engines. First it would be without any wrapper. I would write a class that would handle and parse the menu. (think like a command prompt)

Methods that probably need to be there
init - initializes the interface (not really needed till you introduce the wrapper)
run - starts the program loop
parse - parses the command prompt
IsRunning - returns true if console is running (helpful for program loop)

Add supporting methods to switch different engines

In the methods that would have a command to the device wrapper, have it output a text message say, "Engine 1 Selected", etc ... When you are finished with this part, you want to make sure that it acts in the way that you want it to.

When this part works satisfactory, add the wrapper and get that working. When this is working, try writing a gui interface for it or add more functionality, like a landing gear switch. In this way, you have a pretty good idea where the bug is. On the other hand, if you jump right in and attack the problem like a shot gun, bugs could be everywhere and anywhere.

If you like I can write a quick class to see an example. I'm not sure about your experience, so I started at the most basic level. I hope this helped and it wasn't too scattered.
Image
User avatar
3./JG51_Specter
Lance Air Corporal
 
Posts: 24
Joined: Sun May 21, 2006 4:09 am
Location: USA

Postby BaLrOg on Mon May 22, 2006 8:00 pm

Many thanks for taking the time to respond Spectre and be assured I do appreciate all the help I get :)

I do have some familiarity with the concepts and structure programing languages, but my exposure to C++ comprises of the odd compilation of code using the 'make' commands for the linux enviroment.

Whilst that has exposed me to the concept of libraries I have by no means a solid understanding of them it has been a very long time since I produced anything that could be termed a program / application.

To be honest the time I had for coding went out the window around the same time the the C language was emerging the so the main problem I have is the syntax of the C++ language and some of its jargon i.e I have no idea what and how a 'wrapper' is supposed to interact with external code (although I am starting to understand the concept behind it I think? :shock: )

The example code would be a great help and If its not too much of a hinderance then please do feel free to twist my head in the right direction.

The consol aplication, as you say has become apparent to me also that it is the best way to start and I intend to put the gui side of things on the back burner until I get a better understanding of how the bare bones of the code work.

Yes I saw that piece of code but the bit that had me somewht foxed was here at the very begining (wouldnt you know it). Without actualy having checked it, it looks like this line is 'setting up' the devicelink wrapper to be refered to as 'My_dl'

C_DeviceLink my_dl;
my_dl.Init(); // this creates the devicelink object and initializes the primary UDP client connection

Now it seems to me that in order for that part of the code to work then device link either needs to be a part of your code or exist as a seperate header or library within the project folder?

I am not sure if I am making sense there and again the holes in my knowledge are probably letting me down. The rest of the code makes sense to me and I understand the function of pretty much all of it, ie the calls to commands/funtions from within the devicelink and the passing of variables ect.

As you say, and the more I am investigating myself , the more it does seem to me that the object orientated aspect is my main stumbling block. This is where I seem to get most of my problems and I shall see if I can find a suitable text that will cover this area. Hadnt thought about the Java root but some of the developers at work have a few books lying around on the subject and I will take a peek at what they are reading and see if it can help. We tend to get driven back down into the bowls of the support department if were caught up in developer land in daylight but that is one advantage of working nights. By the way thanks for the link to the web site I have a shift at work coming up and that will make interesting reading.

Again many thanks for taking the time to talk me through the process and I will Have another crack at this using the consol approach that you have sugested.

Of course again any example code to get me on my way would be greatfully recieved if its not too much trouble and don't worry about losing me I will scream if it gets to painfull.

Regards

Balrog
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby 3./JG51_Specter on Tue May 23, 2006 8:35 am

A wrapper is really just an interface. This particular one interfaces with devicelink. It supplies a function like GearDown(), then carries out all the message handling to make this happen via udp.

There was one typo I found in Sensei's code.
devicelink.cpp:741 err = sscanf (pdest, "16%s", &m_game_ip);
This reads a string beginning with 16

should be
err = sscanf (pdest, "%16s", &m_game_ip);
This reads a string 16 characters long (which is the length of a standard IP address)

As promised here's some example code. I have to confess I couldn't get it to work. It compiles fine, but for some reason WWSensei's wrapper won't connect. I think its more to the fact that I wrote the code on linux, compiled it for win32 using xmingw and then ran the program through wine.

This is the way object oriented programming was explained to me, think of an object like a thing. All things have a collection of traits and functions. An aircraft may be blue, have wings, stabilizers and have the ability to roll, yaw and pitch.

Continuing with the analogy, each object is made up of a collection of others. You, the pilot, pull back on the stick (this is a method). All you know is the stick and that it will move you up and down. However, the aircraft is made up of several objects to complete this, hydraulics, cable linkages, elevator, etc ... You really don't care about the elevator's deflection angle, but it is integral to the aircraft's attitude.

In C++ classes make up the data structure and objects are the realization of the class.

P-51 is a class, Glamorous Glenis (Yeager's -51) is an object

Also there is Inheritance, traits are taken from parent classes
Fighter would be a parent
P-51 and Fw-190 would be child classes that share fighter traits

A quick background in C++ files, the build works in two stages. First, the compiler builds object files (.o, .obj) using the source and header files (.cpp). After this stage there should be one object file for every source file. This is when the linker is used, it collects all the object files and libraries into an executable program.

If you are still using VC express, creating a project and adding all the files into it should do this all automatically. You will have to go into the project properties, there should be a linker tab where there is a textbox for additional libraries. Add -lwsock32 I think, -l (ell) means link to library and wsock32 is the network socket library for windows. You may have to dig around a bit to find the correct syntax. I'm really rusty with MSVC, I've pretty much sworn off Windows except to play games and migrated to Linux.

If you've switched over to a gnu compiler.
compile: g++ -c -o object.o source.cpp (for each file)
link: g++ -o dlc.exe *.o -lwsock32

You can also add the debug flag for Sensei's code in the devicelink.cpp, this will show a lot of useful error messages.
g++ -c -DDEBUG_OUTPUT -o devicelink.o devicelink.cpp

Without further adeiu. Place these files in the same directory as WWSensei's wrapper. The code is commented if you have any questions feel free to ask.

dlconsole.h - DLConsole class definition
Code: Select all
#ifndef __DLCONSOLE_H_
#define __DLCONSOLE_H_

#include "devicelink.h"
/*!   \class DLConsole dlconsole.h "dlconsole.h"
*   \brief Console interface to IL-2 Device Link
*   \author Chris Guthrie (3./JG51_Specter)
*   \version 1.0
*
*   Command line prompt like interface to 1c/Maddox's flight simulator IL-2 Sturmovik and
*   iterations.  This class utilizes WWSensei's C_DeviceLink wrapper.
*/
class DLConsole
{
   private:
   /// \brief console run status flag   
   bool _bRunFlag;
   /// \brief instance of wrapper class
   C_DeviceLink _devlink;
   
   public:
   DLConsole();
   
   bool run();
   
   /*!   \brief Checks status of console run status
    *   \return true if running, false otherwise
    */
   bool isRunning() {return _bRunFlag;}
   
   protected:
   void parse (char cmd);
   void printHelp ();
   
   
};

#endif //__DLCONSOLE_H_


dlconsole.cpp - All the methods of the DLConsole class
Code: Select all
#include "dlconsole.h"
#include <iostream>

using namespace std;

/*!   \brief   Default Constructor
*   Sets values for class members
*/
DLConsole :: DLConsole () {
   _bRunFlag = false;
}

/*!   \brief Starts the console and enters the main loop
*   \return true if succesful
*/   
bool DLConsole :: run () {
   char cmd;
   char buffer[32];
   
   //caviot of wrapper, must set the length of the buffer
   memset (buffer, ' ', 32);
   
   //initializes devicelink interface
   if ( ! (_bRunFlag = _devlink.IsInitialized()) )
      _bRunFlag = _devlink.Init();
   
   if (isRunning()) {
      //Welcome message   
      _devlink.GetDLVersion (buffer);
      cout << "Connected version " << buffer << "\n";
      
      //console command loop
      while (isRunning()) {
         cout << "\n>";
         cin >> cmd;
      
         parse(cmd);
      }
      return true;
   } else
      return false;
}

/*!   \brief run entered command
*   \param cmd command to run
*/
void DLConsole :: parse (char cmd) {

   switch (cmd) {
   
   case 'q':
   case 'Q':
      _bRunFlag = false;
      break;
      
   case 'h':
   case 'H':
      printHelp();
      break;
   case '1':
      if (_devlink.ToggleEng1Select())
         cout << "Engine 1 Toggled\n";
      break;
      
   case '2':
      if (_devlink.ToggleEng2Select())
         cout << "Engine 2 Toggled\n";
      break;

   case 'n':
   case 'N':
      if (_devlink.ToggleNavLights())
         cout << "Nav Lights Toggled\n";
      break;
      
   default:
      cout << "Unknown cmd (" << cmd << ")\n";   
   }
}

/*! \brief prints help message to stdout
*/
void DLConsole :: printHelp() {
   cout << "Help --\n";
   cout << "\t q \t exit\n";
   cout << "\t h \t this help message\n";
   cout << "\t 1 \t Switch Engine #1\n";
   cout << "\t 2 \t Switch Engine #2\n";
   cout << "\t n \t Toggle Nav Lights\n";
}


main.cpp - the infamous main function that starts all
Code: Select all
#include "dlconsole.h"
#include <iostream>
/*
* File: main.cpp
* Purpose:   This is a small c application that serves as a comand console to interface with
*      the 1C/Maddox Il-2 series device link.
*
* Req'd:   WWSensei's DeviceLink Wrapper
*      
* Version:   1.0
* Author:   Chris Guthrie (3./JG51_Specter)
*
*Thanks:   WWSensei for his work on the devicelink wrapper
*
* Legal Stuff:
*      I submit this source code under the BLA (Beer License Agreement).  You are free to
*      use this code in anyway you like.  I only request that I and others receive credit where do.
*      Also, if we happen to find ourselves in a pub somewhere, share how you found this
*      useful over a round or two.
*
*      Use at your own risk, I'm not responsible for any damages or problems that might
*      be directly or indirectly caused by this source code.  This includes bashing your head
*      on the keyboard out of frustration.
*/      

using namespace std;

/*! \brief Entry Point
* Standard C/C++ entry function, runs a device link console then exits
*/
int main (int argc, char * argv[]) {
   DLConsole dlc;
   
   if (! dlc.run()) {
      cout << "Error:\n";
      cout << "\t Unable to start Device Link Console\n";
   }
   
   return 0;
}
Image
User avatar
3./JG51_Specter
Lance Air Corporal
 
Posts: 24
Joined: Sun May 21, 2006 4:09 am
Location: USA

Postby BaLrOg on Tue May 23, 2006 9:01 pm

Wow thanks a lot mate thats going to be a great help. Your description is very good and does help make some sense of the whole object based format.

As suggested I have started to use a gnu compatable compiler (bloodshed C++) as well as Visual C++. Hoping that if I can make it work on the gnu platform I can transpose it to the Visual one (fingers crossed there). Primarily though I will attempt all my initial experiments with bloodshed as it seems quite a capable ide with what appears to be good cross compatability with linux.

http://www.bloodshed.net/dev/index.html

It allows for using the cgywin and mingw enviroments (something I realised I needed when I noticed your includes in the other piece of code you wrote that called for socket.h and in.h) so hopefully it should be quite comfortable dealing with linux based code, or any other platform for that matter. I may well go ahead and rebuild myself a linux machine at some point but for now windoze will do the job, for now :wink:

Any way first things first is to get the code you have provided compiled and running and then take it from there.

Once again thanks for your continuing assistance and the examples you have provided.

Regards

Iain
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby BaLrOg on Wed May 24, 2006 4:34 am

Well it compiled no problem same problem you had though in that it doesn't seem to connect to the remote machine? Still its good to have a piece of code I can play with and half the learning process is hunting out the bugs so I look forward to tracking this one down.

Just one question they reference to 16 being the standard length of an ip address. I take it that is in the format xxx.xxx.xxx.xxx wouldn't that mean it was 15 characters instead ?

Just a thought. Maybe I will try and change that number and see if it works then


Thanks again

Iain
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby 3./JG51_Specter on Wed May 24, 2006 8:42 pm

BaLrOg wrote:Just one question they reference to 16 being the standard length of an ip address. I take it that is in the format xxx.xxx.xxx.xxx wouldn't that mean it was 15 characters instead ?


C++ usese a Null character terminated string. A normal c string is of type (char *). This in reality is a pointer to a part of memory starting at the address stored in the variable. The compiler will read sequentually through the memory until it finds a null character (ASCII code 0). So when you allocate the memory for a string, you always have to add 1 more byte. At best you get a bunch of garbage characters tacked on, at worst you have a memory leak that will crash the program.

I dug around in the wrapper some today. First problem that I found was the error checking for the buffer methods (set_command_buff, get_cmd_buff, etc ...) They chech for an adequate buffer size, but the code passes a buffer that is the correct size but full of null characters. It always would fail this test on my computer.

After I commented these out, I tweaked the network code a little bit and I finally got it to communicate back and forth. It still doesn't parse the response, but I know the server and client are communicating.

If you haven't tried compiling this in MSVC already, give it a shot. I can't believe that WWSensei unleashed his code without testing it first, its most likely an incompatability with the gnu compiler. I'll dig around and see if I can find my long lost copy of Visual C++ and try it too.
Image
User avatar
3./JG51_Specter
Lance Air Corporal
 
Posts: 24
Joined: Sun May 21, 2006 4:09 am
Location: USA

Postby BaLrOg on Wed May 24, 2006 10:02 pm

C++ usese a Null character terminated string. A normal c string is of type (char *).


Thanks that is a very useful piece of information to have and is duley noted for future reference. I kinda guessed it would be something like that but I thought I would ask anyhow.

Yes I only compiled mine using the gcc environ. I will have a crack at it with my version of Visual when I get back home and see what the result is.
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby BaLrOg on Thu May 25, 2006 4:17 am

Nope no joy my end with visual C but I suspect that is my total lack of experience with the package, and possibly that visual just likes to do things a bit differently from the accepted norm.

I seem to have the same problem with linking and although I did find a linker section its a little on the overwhelming side as far as options go. I am begining to appreciate what you meant when you said that gui based compilers can be a pain in the azz, and I think it may well benifit me later to stick with the gnu compatable package for now.

Any how

I am going to spend some time getting my directory structure and build area tidy and possibly re-install on a 'clean' machine (currently working on the same machine I do all my other gunk on).

I have a long road ahead of me before I am capable of just diving in there and thrashing the code about but I am not ready to quit just yet. I have plenty of example code to poke over now thanks to both you and Sensei's posts. And its an interesting subject and learning process for me.
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Postby 3./JG51_Specter on Thu May 25, 2006 9:34 am

I pm'd WWSensei over at Ubi and cc'd your account tHeBaLrOgRoCkS. Well I hope its your account anyway. Hopefully he can shed some light on why this isn't working.

I've been meaning to say this for the last few posts now. I didn't mean to be rude.

I enjoy helping people and its my way of paying back to the kind people who spared the time to teach me a thing or two. You're welcome.
Image
User avatar
3./JG51_Specter
Lance Air Corporal
 
Posts: 24
Joined: Sun May 21, 2006 4:09 am
Location: USA

Postby BaLrOg on Thu May 25, 2006 7:43 pm

Arrgh I've been rumbled!! Oh well I guess thats me back on the run again. Yes guilty as charged but thanks for breaking it to the comunity gently. :D

I spent some time after work playing around with it again and although I did not have much success with the compilation (masses of errors, mostly about various headers not found, need to get my head around Visuals linker) it was and interesting excerscise in familiarization with the Visual enviroment.

I tried porting the example console program you gave me and also had a stab at adapting Sensei's to them same structure.

However as you say it will help to know what base system the wrapper was written with so that (if possible we can attack the problem from the same front).

Anyhow thanks for the update and feel free to pm me either here or at the 'Zoo' :wink:

Regards

BaLrOg
User avatar
BaLrOg
Corporal
 
Posts: 26
Joined: Thu May 11, 2006 5:51 pm
Location: Wiltshire, UK

Next

Return to Developers Central

Who is online

Users browsing this forum: No registered users and 1 guest

cron