I am in the middle of trying to build an interface for my flight sim (fs2004). Just learning the basic about talking to flight sim via a dll i made in the modules folder, compiled with visual c++ 2008 express, all compiles good. It crashes when i try to read a simple variable. If anyone can steer in the right direction as to why it crashes that would be great. i have been reading for hours and try many different ways of doing this basic task (reading pressure millibars). Here is the code:
Basically after i call lookup_var it crashes.
#include <windows.h>
#include "gauges.h"
/* This is the module's import table. */ \
GAUGESIMPORT ImportTable = \
{ \
{ 0x00000000, (PPANELS)NULL }, \
{ 0x00000000, NULL } \
}; \
\
\
void FSAPI module_init(void) {
}
void FSAPI module_deinit(void) {}
/* This is the module's export table. */ \
GAUGESLINKAGE Linkage = \
{ \
0x00000000, \
module_init, \
module_deinit, \
0, \
0, \
0x900, {0}
};
// The standard window procedure used by the flight simulator
WNDPROC oldWndProc;
// Flight simulator main window handle
HWND hFSimWindow;
#define MENU_ENTRY "My Mo&dule"
#define ID_MY_MENUITEM 40001
#define INIT_MY_MENUITEM 40002
/**
* Main window procedure that is called by the flight simulator to process
* incoming window messages.
*/
FLOAT64 AmbientPressMB = 0 ;
MODULE_VAR AMBIENT_PRES_MBARvar = {AMBIENT_PRES_MBAR};
LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char buffer[20];
switch (uMsg) {
case WM_NCPAINT:
{
HMENU hMenu, hMyMenu;
hMenu = GetMenu(hwnd);
if (hMenu != NULL) {
int i;
// Look for our menu entry in the main menu.
for (i = 0; i < GetMenuItemCount(hMenu); i++) {
char buf[128];
GetMenuString(hMenu, i, buf, 128, MF_BYPOSITION);
if (strcmp(buf, MENU_ENTRY) == 0) {
// It is already here, we do not need to add it again
break;
}
}
if (i < GetMenuItemCount(hMenu)) {
// It is already here, we do not need to add it again
break;
}
/* Create new menu. NOTE: It seems that this will be
* reached more times, so we cannot save the handle, because
* in such case it could be destroyed and we will not have
* any access to it in the simulator.
*/
hMyMenu = CreateMenu();
AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "My &First Menu Entry");
AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, INIT_MY_MENUITEM, "See");
// add the created menu to the main menu
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);
}
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == INIT_MY_MENUITEM) {
}
if (LOWORD(wParam) == ID_MY_MENUITEM) {
// THIS SEEMS TO CRASH IT
lookup_var(&AMBIENT_PRES_MBARvar);
AmbientPressMB = AMBIENT_PRES_MBARvar.var_value.n;
//sprintf("Value = %d",mad_altitude_set.var_value.n);
MessageBox(hwnd, "hello", "HURA", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
break;
case PANEL_SERVICE_PRE_UPDATE:
break;
}
// Call the original window procedure to handle all other messages
return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
}
/**
* Entry point of the DLL.
*/
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
hFSimWindow = FindWindow("FS98MAIN", NULL);
oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);
break;
}
return TRUE;
}
Thanks
Basically after i call lookup_var it crashes.
#include <windows.h>
#include "gauges.h"
/* This is the module's import table. */ \
GAUGESIMPORT ImportTable = \
{ \
{ 0x00000000, (PPANELS)NULL }, \
{ 0x00000000, NULL } \
}; \
\
\
void FSAPI module_init(void) {
}
void FSAPI module_deinit(void) {}
/* This is the module's export table. */ \
GAUGESLINKAGE Linkage = \
{ \
0x00000000, \
module_init, \
module_deinit, \
0, \
0, \
0x900, {0}
};
// The standard window procedure used by the flight simulator
WNDPROC oldWndProc;
// Flight simulator main window handle
HWND hFSimWindow;
#define MENU_ENTRY "My Mo&dule"
#define ID_MY_MENUITEM 40001
#define INIT_MY_MENUITEM 40002
/**
* Main window procedure that is called by the flight simulator to process
* incoming window messages.
*/
FLOAT64 AmbientPressMB = 0 ;
MODULE_VAR AMBIENT_PRES_MBARvar = {AMBIENT_PRES_MBAR};
LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char buffer[20];
switch (uMsg) {
case WM_NCPAINT:
{
HMENU hMenu, hMyMenu;
hMenu = GetMenu(hwnd);
if (hMenu != NULL) {
int i;
// Look for our menu entry in the main menu.
for (i = 0; i < GetMenuItemCount(hMenu); i++) {
char buf[128];
GetMenuString(hMenu, i, buf, 128, MF_BYPOSITION);
if (strcmp(buf, MENU_ENTRY) == 0) {
// It is already here, we do not need to add it again
break;
}
}
if (i < GetMenuItemCount(hMenu)) {
// It is already here, we do not need to add it again
break;
}
/* Create new menu. NOTE: It seems that this will be
* reached more times, so we cannot save the handle, because
* in such case it could be destroyed and we will not have
* any access to it in the simulator.
*/
hMyMenu = CreateMenu();
AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "My &First Menu Entry");
AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, INIT_MY_MENUITEM, "See");
// add the created menu to the main menu
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);
}
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == INIT_MY_MENUITEM) {
}
if (LOWORD(wParam) == ID_MY_MENUITEM) {
// THIS SEEMS TO CRASH IT
lookup_var(&AMBIENT_PRES_MBARvar);
AmbientPressMB = AMBIENT_PRES_MBARvar.var_value.n;
//sprintf("Value = %d",mad_altitude_set.var_value.n);
MessageBox(hwnd, "hello", "HURA", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
break;
case PANEL_SERVICE_PRE_UPDATE:
break;
}
// Call the original window procedure to handle all other messages
return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
}
/**
* Entry point of the DLL.
*/
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
hFSimWindow = FindWindow("FS98MAIN", NULL);
oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);
break;
}
return TRUE;
}
Thanks

