Jump to content
The simFlight Network Forums

hi, some problems with windows programming


Recommended Posts

Hi,

I try to build the FSUIPC application beneeth with VC 5.0, but I have two problems:

First the linker asks for an entry "_main", I don'know how I can solve that. secondly I want to give some time to other applications too, so I need some call to let this program sleep for a 500 msec; How can I do that.

Has someone a solution for me? Thanks in advance

Hugo

* UIPCmess Displays a scrolling message on the wind screen */

#include

#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;

int i, len;

char message[128];

byte regByte, count, countP = -1;

short mode = -1;

BOOL rCountOk = TRUE, fullReg = TRUE;

FILE *messFile;

if (FSUIPC_Open(SIM_ANY, &dwResult)) {

/* Okay, we're linked, and already the FSUIPC_Open has had an initial

exchange with FSUIPC, check if it is a full registered version */

if (!FSUIPC_Read(0x330C, 1, &regByte, &dwResult) ||

!FSUIPC_Process(&dwResult) || !(regByte & 4)) fullReg = FALSE;

if (fullReg) {

/* Open the message file */

if (messFile = fopen ("FSmess.def", "rt")) {

do {

/* Okay, do a loop and check every 500 msec for a change of the

counter value */

if (FSUIPC_Read(0x66FF, 1, &count, &dwResult) &&

FSUIPC_Process(&dwResult)) {

/* Read the user reserved space at 0x66FF. We have used this

to store the status counter of the Button Programming */

if (count != countP) {

countP = count;

/* Set pointer to the begin of the file */

fseek (messFile, 0l, SEEK_SET);

/* Read the number of records, equal to count */

for (i = 0; i < count; i++) fgets (message, 128, messFile);

len = strlen(message) - 1;

message [len] = '\0';

/* Put the message on the screen */

if (FSUIPC_Write(0x3380, len, message, &dwResult)) {

/* Make it scrolling for 1 sec */

if (FSUIPC_Write(0x32FA, 2, &mode, &dwResult))

/* Process the requests */

FSUIPC_Process(&dwResult);

else

MessageBox (NULL, pszErrors[dwResult],

"UIPCmess: Failed to write to 0x32FA", 0);

}

else

MessageBox (NULL, pszErrors[dwResult],

"UIPCmess: Failed to write message 0x3380", 0);

}

}

/* wait 500 msec */

/* wait (500); */

} while (1);

}

else

MessageBox (NULL, "Cannot open the message file \"FSmess.def\"",

"UIPCmess", 0);

}

else

MessageBox (NULL, "Full registered version is necessary",

"UIPCmess", 0);

}

else

MessageBox (NULL, pszErrors[dwResult],

"UIPCmess: Failed to open link to FSUIPC", 0);

FSUIPC_Close();

return 0 ;

}

Link to comment
Share on other sites

First the linker asks for an entry "_main", I don'know how I can solve that.

That's the main entry point provided by the basic library code needed with any Windows program. Sounds like you've excluded all the standard libraries. WinMain is the entry point in your code which it calls, for a Windows (as opposed to DOS) type program.

secondly I want to give some time to other applications too, so I need some call to let this program sleep for a 500 msec; How can I do that.

There's a Windows API called "Sleep(milliseconds)". But your whole program reads like a DOS program. A Windows program should surely at least have a message loop to process messages, and a Window (even if hidden/invisible) in which to process them. Then it would be much more user friendly to use SetTimer to generate a wake-up call every 500 mSecs., allowing the program to process messages (like WM_CLOSE) as well, and generally be responsive.

If you do it the way you've done it you could instead rename WinMain as main and compile it as a DOS program. (A "Win32 Console" program is probably the more proper name -- whatever, it would run in a DOS window).

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.