Jump to content
The simFlight Network Forums

C++ SDK Issues


Recommended Posts

Hi

As I am new on this forum I'd like to say hello to everybody.

From some time I am into little project development. This is small I/O boards project based on PIC microcontrollers. I have done PIC part and now I am trying to connect everything to FSUIPC. I am not very good C programmer but I will try to build simple application to connect my hardware with FSUIPC.

I have tried sample code from C SDK library and I am getting errors, which I can't fix.

This is my C++ code

/*  UIPChello.c	Displays UIPC link data in a message box */
#include "stdafx.h"
#include 

#include "FSUIPC_User.h"

char *pszErrors[] =
	{	"Okay",
		"Attempt to Open when already Open",
		"Cannot link to FSUIPC or WideClient",
		"Failed to Register common message with Windows",
		"Failed to create Atom for mapping filename",
		"Failed to create a file mapping object",
		"Failed to open a view to the file map",
		"Incorrect version of FSUIPC, or not FSUIPC",
		"Sim is not version requested",
		"Call cannot execute, link not Open",
		"Call cannot execute: no requests accumulated",
		"IPC timed out all retries",
		"IPC sendmessage failed all retries",
		"IPC request contains bad data",
		"Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC",
		"Read or Write request cannot be added, memory for Process is full",
	};


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{	DWORD dwResult;

	if (FSUIPC_Open(SIM_ANY, &dwResult))
	{	char chMsg[128], chTimeMsg[64];
		char chTime[3];
		BOOL fTimeOk = TRUE;
		static char *pFS[] = { "FS98", "FS2000", "CFS2", "CFS1", "Fly!", "FS2002", "FS2004" };  // Change made 060603

		// Okay, we're linked, and already the FSUIPC_Open has had an initial
		// exchange with FSUIPC to get its version number and to differentiate
		// between FS's.

		// Now to auto-Register with FSUIPC, to save the user of an Unregistered FSUIPC
		// having to Register UIPCHello for us:
		static char chOurKey[] = "IKB3BI67TCHE"; // As obtained from Pete Dowson

		if (FSUIPC_Write(0x8001, 12, chOurKey, &dwResult))
			FSUIPC_Process(&dwResult); // Process the request(s)

		// I've not checked the reslut of the above -- if it didn't register us,
		// and FSUIPC isn't fully user-Registered, the next request will not
		// return the FS lock time

		// As an example of retrieving data, well also get the FS clock time too:
		if (!FSUIPC_Read(0x238, 3, chTime, &dwResult) ||
				// If we wanted other reads/writes at the same time, we could put them here
				!FSUIPC_Process(&dwResult)) // Process the request(s)
			fTimeOk = FALSE;

		// Now display all the knowledge we've accrued:
		if (fTimeOk)
			wsprintf(chTimeMsg, "Request for time ok: FS clock = %02d:%02d:%02d", chTime[0], chTime[1], chTime[2]);

		else
			wsprintf(chTimeMsg, "Request for time failed: %s", pszErrors[dwResult]);

		wsprintf(chMsg, "Sim is %s,   FSUIPC Version = %c.%c%c%c%c\r%s",
			(FSUIPC_FS_Version && (FSUIPC_FS_Version <= 7)) ? pFS[FSUIPC_FS_Version - 1] : "Unknown FS", // Change made 060603
			'0' + (0x0f & (FSUIPC_Version >> 28)),
			'0' + (0x0f & (FSUIPC_Version >> 24)),
			'0' + (0x0f & (FSUIPC_Version >> 20)),
			'0' + (0x0f & (FSUIPC_Version >> 16)),
			(FSUIPC_Version & 0xffff) ? 'a' + (FSUIPC_Version & 0xff) - 1 : ' ',
			chTimeMsg);
		MessageBox (NULL, chMsg, "UIPChello: Link established to FSUIPC", 0) ;
	}

	else
		MessageBox (NULL, pszErrors[dwResult], "UIPChello: Failed to open link to FSUIPC", 0) ;

	FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here
   return 0 ;
}

And errors I'm getting after debuging in VISUAL C++ 2005:

1>------ Build started: Project: test2, Configuration: Debug Win32 ------
1>Compiling...
1>test2.cpp
1>.\test2.cpp(28) : error C2373: 'WinMain' : redefinition; different type modifiers
1>        C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winbase.h(1875) : see declaration of 'WinMain'
1>Build log was saved at "file://c:\Documents and Settings\MEDIA\My Documents\Visual Studio 2005\Projects\test2\test2\Debug\BuildLog.htm"
1>test2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I was trying to google it but nothing helps. Anyone can help me with this code, please.

Thanks in advance.

Link to comment
Share on other sites

I have tried sample code from C SDK library and I am getting errors, which I can't fix.

...

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

...

1>.\test2.cpp(28) : error C2373: 'WinMain' : redefinition; different type modifiers

1> C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\winbase.h(1875) : see declaration of 'WinMain'

...

I was trying to google it but nothing helps.

Why on Earth "google" when you can simply do what the error message tells you -- i.e. see the declaration of WinMain in winbase.h? The compiler tells you already that you have the wrong type modifier for WinMain. So, check the header "winbase.h", see why. It even gives you the line number -- 1875.

Here, your code compiles fine. In the header the modifier "WINAPI" is defined as "__stdcall", the same as "CALLBACK". They are used interchangeably. The way for you to work it out is clear. And isn't there any other example of using WinMain you can find for your compiler? Nothing provided with it? Copy whatever is used in something which compiles.

Regards

Pete

Link to comment
Share on other sites

Hi Pete

Thanks for quick reply, but unfortunatelly I don't know completely what are you talking about, sorry for that but my knowledge of C is very limited. I am trying to learn something to get my project working. Is there any chance to get any link or more clear tips for me. I will appreciate very much for more help.

Regards

Marcin

Link to comment
Share on other sites

Thanks for quick reply, but unfortunatelly I don't know completely what are you talking about

Which English words didn't you understand? The error message points you to a definition of something in a file, a definition which you are violating for some reason. Surely it is within your ability to look at the given line number in the specified file to see what it might say? Can't you open text files in an editor and look at them?

sorry for that but my knowledge of C is very limited.

I think you need to learn more before trying to attempt something like this, then. Sorry, but you will simply be completely out of your depth. You are really in the wrong place to learn programming. You need to start somewhere else I think.

Good luck!

Regards

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.