1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Menu in FS9 (C++)

Discussion in 'Tools programming' started by livai, 26/5/07.

  1. livai

    livai

    Joined:
    9/5/06
    Messages:
    11
    Country:
    canada
    Hi everyone :)

    I trying to add a menu inside my FS9 and used the "tutorial" code of Cyril Hruscak.
    Well, it's not working with my VC++ express (I'm a noob in C++ ;)

    If you have and idee, here is the code
    main.c
    Code:
    /* Microsoft Flight Simulator 2004 Module Example.
     *
     * Copyright (c) 2004, Cyril Hruscak.
     * You may freely redistribute and/or modify this code provided this copyright
     * notice remains unchanged. Usage of the code is at your own risk. I accept
     * no liability for any possible damage using this code.
     *
     * It shows how to create a module dll ("Modules" directory of the main
     * FS directory) that can be loaded by the FS2004. It also shows how to add
     * a new menu entry to the main flight simulator menu.
     */
    
    #include <windows.h>
    #include "module.h"
    
    /*
     * We define just basic interface to the flight simulator so it will be
     * able to load the module.
     */
    DLLEXPORT MODULE_IMPORT ImportTable = {
    	{0x00000000, NULL},
    	{0x00000000, NULL}
    };
    
    void FSAPI module_init(void) {}
    void FSAPI module_deinit(void) {}
    
    DLLEXPORT MODULE_LINKAGE Linkage = {
    	0x00000000,
    	module_init,
    	module_deinit,
    	0,
    	0,
    	0x0900,	// FS2004 version (use 0x0800 for FS2002)
    	NULL
    };
    
    // 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
    
    /**
     * Main window procedure that is called by the flight simulator to process
     * incoming window messages.
     */
    LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	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");
    					// 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) == ID_MY_MENUITEM) {
    				// Add your code here
    				MessageBox(hwnd, "It works!", "HURA", MB_OK | MB_ICONEXCLAMATION);
    				return 0;
    			}
    			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;
    }
    module.h

    Code:
    /* Microsoft Flight Simulator 2004 Module Example.
     *
     * Copyright (c) 2004, Cyril Hruscak.
     * You may freely redistribute and/or modify this code provided this copyright
     * notice remains unchanged. Usage of the code is at your own risk. I accept
     * no liability for any possible damage using this code.
     *
     * It shows how to create a module dll ("Modules" directory of the main
     * FS directory) that can be loaded by the FS2004. It also shows how to add
     * a new menu entry to the main flight simulator menu.
     */
    
    #ifndef	__FS_MODULE_H__
    #define	__FS_MODULE_H__
    
    #define	DLLEXPORT	__declspec(dllexport)
    #define	FSAPI	__stdcall
    
    /**
     * This is the module's import table definition.
     */
    typedef struct _MODULE_IMPORT {
    	struct {
    		int fnID;
    		PVOID fnptr;
    	} IMPORTSentry;
    	struct {
    		int fnID;
    		PVOID fnptr;
    	} nullentry;
    } MODULE_IMPORT;
    
    /**
     * This is the module's export table definition
     */
    typedef struct _MODULE_LINKAGE {
    	int ModuleID;
    	void (FSAPI *ModuleInit)(void);
    	void (FSAPI *ModuleDeinit)(void);
    	UINT32 ModuleFlags;
    	UINT32 ModulePriority;
    	UINT32 ModuleVersion;
    	PVOID ModuleTable;
    } MODULE_LINKAGE;
    
    #endif	/* __FS_MODULE_H__ */

    here is the build log

    1>main.obj : error LNK2019: unresolved external symbol __imp__CallWindowProcW@20 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__AppendMenuW@16 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__CreateMenu@0 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__GetMenuStringW@20 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__GetMenuItemCount@4 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__GetMenu@4 referenced in function _FSimWindowProc@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__SetWindowLongW@12 referenced in function _DllMain@12
    1>main.obj : error LNK2019: unresolved external symbol __imp__FindWindowW@8 referenced in function _DllMain@12

    Thanks for your help :)

    Livai
  2. livai

    livai

    Joined:
    9/5/06
    Messages:
    11
    Country:
    canada
    Lol It's solved for these error

    I forgot this step

    "One more step is needed to make the Win32 template work in Visual C++ Express. You need to edit the corewin_express.vsprops file (found in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults) and

    Change the string that reads:

    AdditionalDependencies="kernel32.lib" to

    AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"


    BUT nothing is showing in FS9

    Can anyone help me?
    Last edited: 31/5/07
  3. livai

    livai

    Joined:
    9/5/06
    Messages:
    11
    Country:
    canada
    UP , any idee?
  4. lordofwings

    lordofwings

    Joined:
    5/11/06
    Messages:
    559
    Country:
    panama
    RE: modules tutorial

    It has been a long time since I wrote a C/C++ loadable module. But since I am very interested in writing FS modules could you perhaps point me to this "tutorial" ?
  5. rhumbaflappy

    rhumbaflappy Moderator Staff Member Resource contributor

    Joined:
    2/6/04
    Messages:
    2,621
    Country:
    us-wisconsin
  6. livai

    livai

    Joined:
    9/5/06
    Messages:
    11
    Country:
    canada
    Hi,

    It's solved with that

    compile in multi-byte and not unicode (charactere set)
    put detect 64 bit portability issues to NO

    It's not really clean but that work

    Bye

Share This Page