Jump to content
The simFlight Network Forums

Mohamed Sayed

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by Mohamed Sayed

  1. Not I, I'm afraid. I don't know VB6 at all. However, if you enable ipc write logging, as I suggested, then run your program, I can look at the log for you.

     

    Pete

     

    As nobody were here with VB6 experience to help me, I switched back to my trying on C++, so maybe you help me..

     

    I used this code ...

    #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,					\
    	GAUGE_HEADER_VERSION_FS900, {0}
    	};
    
    // The standard window procedure used by the flight simulator
    WNDPROC oldWndProc;
    
    // Flight simulator main window handle
    HWND hFSimWindow;
    
    #define	MENU_ENTRY	"Airline"
    #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, "Launch Flight");
                                            AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "Fuel Price");
                                            AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "Airport Codes");
                                            AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "&About");;
    					// add the created menu to the main menu
    					AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);
    
    				    AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "Zaki");
                                      // 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!", "Mohamed", 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;
    }
    

    But when I debug or try to build .dll file, I get this error :

     

     

    --------------------Configuration: FSdll - Win32 Debug--------------------

    Compiling...

    DodoDLL.cpp

    c:\program files\microsoft visual studio\myprojects\dododll\dododll.cpp(2) : fatal error C1083: Cannot open include file: 'gauges.h': No such file or directory

    Error executing cl.exe.

    FSdll.dll - 1 error(s), 0 warning(s)

     

    I'm sure that I have included gauges.h as a header which I have downloaded from the SDK, here you're a screenshot ..

    untitled.png

  2. Dear Pete .. Yes, I'm not that professional at programming, but I'm developing my skills already.

    we learn from trials and fails..

     

    Well, after a long search and thinking, I guess I'm now about to get a final successful result.. The error I mentioned above didn't occur anymore; at the end right now, I have no errors. but still cannot have a final result ..

     

     

    If you Pete can revise my codes, or anybody else who is good at VB6 -- these are the codes I use..

     

    ** First , this code to connect to FSUIPC

    Private Sub Command1_Click()
    Dim Version As Long
    Dim FS As String
    Dim dwResult As Long
      
    Call FSUIPC_Initialization
    
        If FSUIPC_Open(SIM_ANY, dwResult) Then
            Version = FSUIPC_FS_Version
            Select Case Version
            Case 0
            FS = "Unknown"
            Case 1
            FS = "FS98"
            Case 2
            FS = "FS2000"
            Case 3
            FS = "CFS1"
            Case 4
            FS = "CFS2"
            Case 5
            FS = "FLY 5"
            Case 6
            FS = "FS2002"
            Case 7
            FS = "FS2004"
            End Select
          
            LblFSUIPCcon = "Connected to  " & FS
        Else
           
            LblFSUIPCcon = "Disconnected"
        End If
    End Sub
    

    ** By click on Command2 button, the procedure CreateFS_MenuEntry search for a free slot and writes the text and the "x0000FFFF" to the offset..

    Private Sub Command2_Click()
    Call CreateFS_MenuEntry
    End Sub
    
    Public Sub CreateFS_MenuEntry()
    Dim MenuIdx As Variant
    Dim dwResult As Long
    Dim tmpLng As Long
    Dim tmpLng2 As Long
    
    Dim gavHotkeyAddr_Menu() As Byte
    
        If giMenuCnt = 0 Then Exit Sub
    
        gavHotkeyAddr_Menu(0) = GetFreeHotkeySpot(MenuIdx)       
        gavHotkeyAddr_Menu(1) = MenuIdx
        gavHotkeyAddr_Menu(2) = "Checklist" & vbNullChar
    
        tmpLng = &HFFFF
        tmpLng2 = &H0
        
        Write_UIPC CLng(gavHotkeyAddr_Menu(0)), 2, tmpLng
        Write_UIPC CLng(gavHotkeyAddr_Menu(0)) + 2, 2, tmpLng2
        Write_UIPC &H2FE0, 1, CLng(gavHotkeyAddr_Menu(1))
        WriteS_UIPC &H2FE0, CLng(gavHotkeyAddr_Menu(2)), False
        
        frmMain.TimerFSmenuHotkey.Enabled = True
    End Sub
    

    ** This codes to search for a free slot

    Public Function GetFreeHotkeySpot(Optional Idx As Variant) As Long
    Dim n As Integer
    Dim gvRetVal As Byte
    
        For n = 0 To 55
     
           gvRetVal = FSUIPC_Read(CLng(&H3210) + (4 * n), 1, VarPtr(Idx), 1)
            If gvRetVal = 0 Then
                GetFreeHotkeySpot = &H3210 + (4 * n)
                If Not IsMissing(Idx) Then Idx = n
                Exit Function
            End If
        Next n
    End Function
    

    ** FSUIPC Writing

    Public Function Write_UIPC(lOffset As Long, lLen As Long, lValue As Long) As Boolean
    Dim dwResult As Long
    
        If FSUIPC_Write(lOffset, lLen, VarPtr(lValue), dwResult) Then
            If FSUIPC_Process(dwResult) Then
                Write_UIPC = True
            End If
        End If
    End Function
    
    
    Public Function WriteS_UIPC(lOffset As Long, lLen As Long, lValue As Long) As Boolean
    Dim dwResult As Long
    
        If FSUIPC_WriteS(lOffset, lLen, VarPtr(lValue), dwResult) Then
            If FSUIPC_Process(dwResult) Then
                Write_UIPC = True
            End If
        End If
    End Function
    

    ** The timer is set to interval of 500, It's job to detect if the menu pressed to launch the form of "frmKneeBoard" ..
     

    Private Sub TimerFSmenuHotkey_Timer()
    Dim dwResult As Long
    Dim iBingo As Integer
    Dim tmpStr As String
    Dim tmpSng As Single
    Dim pos As Integer
    
        If FSUIPC_Read(CLng(gavHotkeyAddr_Menu(0)) + 3, 1, VarPtr(iBingo), dwResult) Then 
    
            If FSUIPC_Process(dwResult) And iBingo = 1 Then                 
                frmKneeboard.Show
                
                Write_UIPC CLng(gavHotkeyAddr_Menu(0)) + 3, 1, 0            
            End If
        End If
        
        DoEvents
    End Sub
    
  3. Writing is identical to reading but the other way around. There is no "data type" as far as the reads and writes are concerned, it is all just bytes. The data type is by interpretation, not by definition. What "error" do you get when writing?

     

    I'm afraid I don't know VB6 at all. Sorry. Code "ideas" are by the examples in the SDK.

     

    Pete

     

    The error is Run-time '13' Type mismatch ..

     

    That's how I tried to do the task :

     

    1- I connect to FSUIPC.

    2- I get a free slot by the "GetFreeHotkeySpot" function mentioned above & put it into a string.. it always be "0" !

    3- I write "0x0000FFFF" to the slot simply.

    4- I write "0My_Menu" to offset 0x2FE0 to give a name to the element.

     

    ** But at all, No thing happens and I cannot figure where is the problem !..

     

    Where I can find the SDK examples ( I don't want to be hasty & ask you the codes of C++ as I have to search by myself till the last effort I can do ) ..

    Last question please, how FS2004 reads dll files in modules folder which reserves a name on menu .. any programmatic idea can help .

     

  4. Mr.Pete Thank you so much for your reply..

     

    You are right, dwOffset = CLng(&H3210) + (4 * n) should be inside the loop, I corrected the code .. Thanks for your sharp notice.

     

    I tried FSUIPC_Write, but I have error when using this procedure .. maybe I have alerted a wrong data type for the size of the offest .. I will check out "Paul Henty's DLL" ..

     

    But further if I couldn't use VB6 for the task, I have a little experience with C++ .. Could you please provide me with the code idea ? - your help is highly appreciated ..

    Thanks Sir..

  5. Dear all..

     

    I'm trying to add a caption in FS2004 menu to run externally .exe file using VB6 .. I have read FSUIPC or Programmers.pdf, and I just could get the free hot key slot by the below code :
     

    Public Function GetFreeHotkeySpot(Optional Idx As Variant) As Long
    Dim n As Integer
    Dim gvRetVal As Byte
    Dim dwOffset As Long
     dwOffset = CLng(&H3210) + (4 * n)
        For n = 1 To 55
         
            gvRetVal = FSUIPC_Read(dwOffset, 1, VarPtr(Text1.Text), 1)
            If gvRetVal = 0 Then
                GetFreeHotkeySpot = &H3210 + (4 * n)
            If Not IsMissing(Idx) Then Idx = n
                Exit Function
            End If
        Next n
    End Function
    

    I couldn't write 0x0000FFFF to the slot ..

     

    How can I reserve a location for my program into FS2004 menu .. I need help please to understand the idea ..

     

×
×
  • 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.