• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Creating a module dll, problem

Messages
3
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
 
Not that this is of any use to solving your problem, but...
Code:
try including code in code-tags for readability.
And secondly, FS9 may be a little too old for VS2008, just guessing.

Cheers.
 
Go with this block:
Code:
if (LOWORD(wParam) == ID_MY_MENUITEM) 
	{
	lookup_var(&AMBIENT_PRES_MBARvar);
	sprintf_s(buffer,"Pressure = %8.3f", AMBIENT_PRES_MBARvar.var_value.n );
	MessageBox(NULL, buffer, "HURA", MB_OK | MB_ICONEXCLAMATION);
//	return 0;
	}

Note that "return 0;" is commented out. I think that was your problem.

Doug
 
Well the thing is if i comment out the lookup_var it doesnt crash, but this still may be the problem. I will try to comment that out etc and see if it works thanks. I have part of my circuit build on a breadboard just need to get the interface working! Still alot of work left though......

Thanks...
 
Last edited:
Well I tried that and it still crashes when i select that menu item. If i remove the lookup_var, than it works fine.....
 
Back
Top