Mohamed Sayed Posted February 16, 2014 Report Share Posted February 16, 2014 (edited) 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 .. Edited February 16, 2014 by Mohamed Sayed Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 3, 2014 Report Share Posted March 3, 2014 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 : I don't know VB6, but it seems to me that you have a fundamental error here: dwOffset = CLng(&H3210) + (4 * n) For n = 1 To 55 gvRetVal = FSUIPC_Read(dwOffset, 1, VarPtr(Text1.Text), 1) That "dwOffset = ..." line should surely be within the for loop, NOT before it. Otherwise no use is made of the value n in computing offset! Also, the loop should start with value 0 not 1 otherwise you are already missing testing the first slot. I couldn't write 0x0000FFFF to the slot .. Didn't you try using FSUIPC_Write? BTW, where is the FSUIPC process call needed to send the requests over to FSUIPC? For VB6 users I would think Paul Henty's DLL would make things easier -- please see the SubForum above for this. I can help directly with C/C++ but not easily with VB I'm afraid. Pete Link to comment Share on other sites More sharing options...
Mohamed Sayed Posted March 9, 2014 Author Report Share Posted March 9, 2014 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.. Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 9, 2014 Report Share Posted March 9, 2014 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 ... 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 Link to comment Share on other sites More sharing options...
Mohamed Sayed Posted March 9, 2014 Author Report Share Posted March 9, 2014 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 . Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 9, 2014 Report Share Posted March 9, 2014 The error is Run-time '13' Type mismatch .. Well that's some VB6 problem, nothing to do with FSUIPC. Sorry, you need to debug your VB6 code. Are you still learning VB6? 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 !.. Well if your program fails with an error I'm not surprised nothing happens. The free slot is only 0 because you aren't previous running programs which are also using this facility, so you cannot assume that. And you have an error in any case: the 0 in "0My_Menu" is a character 0 which is actualy 48. So you are trying to use slot 48, not 0. The first byte written MUST be the slot number, binary, not a character version of the number. If it were than no slots could be used past 9! Try using FSUIPC's IPC write logging to see what is actually getting into fSUIPC. That's what it is for. Where I can find the SDK examples In the FSUIPC SDK. Last question please, how FS2004 reads dll files in modules folder which reserves a name on menu .. any programmatic idea can help . It took a lot of hacking into FS code. You start by learning how to write C or C++. And you'll need some ASM as well. You'd need to learn to write Gauges first, then disassemble some parts of FS to find out how to hook into things. It takes months for each version of FS. Pete Link to comment Share on other sites More sharing options...
Mohamed Sayed Posted March 9, 2014 Author Report Share Posted March 9, 2014 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 Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 10, 2014 Report Share Posted March 10, 2014 If you Pete can revise my codes, or anybody else who is good at VB6 -- these are the codes I use.. 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 Link to comment Share on other sites More sharing options...
Mohamed Sayed Posted March 10, 2014 Author Report Share Posted March 10, 2014 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 .. Link to comment Share on other sites More sharing options...
Mohamed Sayed Posted March 10, 2014 Author Report Share Posted March 10, 2014 **SOLVED** Now, I got it successfully !! - Thanks to "Cyril Hruscak" Thank you Pete.. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now