Einzelnen Beitrag anzeigen

goose33

Registriert seit: 26. Okt 2004
Ort: Merseburg
49 Beiträge
 
#6

Re: Wiedermal C++ nach Delphi

  Alt 30. Jan 2005, 22:05
Hallöchen,

nachdem ich mir in einigen Foren und auch per Meil schon hab helfen lassen bin ich ein bischen weiter. Hier mal der jetzige code als überblick.

Code:
uses
  SysUtils, Classes;

type
    TIMPORTSentry = record
      fnID : LongInt;
      fnptr : pointer;
    end;
    Tnullentry = record
      fnID : LongInt;
      fnptr : pointer;
    end;

  MODULE_IMPORT = record
     IMPORTSentry : TIMPORTSentry;
     nullentry : Tnullentry;
  end;

  TModuleInit = procedure;stdcall;
  TModuleDeinit = procedure;stdcall;

  MODULE_LINKAGE = record
     ModuleID : LongInt;
     ModuleInit : ^TModuleInit;
     ModuleDeinit : ^TModuleDeinit;
     ModuleFlags : cardinal;
     ModulePriority : cardinal;
     ModuleVersion : cardinal;
     ModuleTable : pointer;
  end;



{$R *.res}

procedure ImportTable;stdcall;
var
  IMPORTSentry : TIMPORTSentry;
  nullentry : Tnullentry;
begin
  IMPORTSentry.fnID := 0;
  IMPORTSentry.fnptr := 0;

  nullentry.fnID := 0;
  nullentry.fnptr := 0;
end;

procedure Linkage;cdecl;
var
  TMODULE_LINKAGE:MODULE_LINKAGE;
  ModuleInit : TModuleInit;
  ModuleDeinit : TModuleDeinit;
begin
  TMODULE_LINKAGE.ModuleID := 0;
  TMODULE_LINKAGE.ModuleInit := @ModuleInit;
  TMODULE_LINKAGE.ModuleDeinit := @ModuleDeinit;
  TMODULE_LINKAGE.ModuleFlags := 0;
  TMODULE_LINKAGE.ModulePriority := 0;
  TMODULE_LINKAGE.ModuleVersion := $0900;
  TMODULE_LINKAGE.ModuleTable := 0;
end;

exports
  Linkage,ImportTable;

begin
end.
Allerdings meckert der Flugsimulator immer wenn ich die DLL verwenden will.

Hier mal noch die Mail von jemanden der auch ein Modul erstellt hat, allerdings eben auch nur in C++.:

Zitat:
Well, i dont know the Delphi language, as a result i cannt give you a source
code sample of the module. But for let the Flight simulator to read your
*.dll, you need to define two structures type:

MODULE_IMPORT and MODULE_LINKAGE

inside the MODULE_IMPORT, there must be two structures:

IMPORTSentry and nullentry

A) inside the IMPORTSentry structure, there must be two members:

1) a variable called "fnID" as "LONG" type
2) a pointer called "fnptr" as a pointer to any kind of data in memory
(void*)

B) inside the the nullentry structure, there must be two members:

1) a variable called "fnID" as "LONG" type
2) a pointer called "fnptr" as a pointer to any kind of data in memory
(void*)

inside the MODULE_LINKAGE, there must be 7 members:

A) a variable called "ModuleID" as "LONG" type
B) a pointer to a subroutine (with a _stdcall convention) called
"ModuleInit", that doesnt needs any parameter
C) a pointer to a subroutine (with a _stdcall convention) called
"ModuleDeinit", that doesnt needs any parameter
D) a variable called "ModuleFlags" as "UNSIGNED LONG" type
E) a variable called "ModulePriority" as "UNSIGNED LONG" type
F) a variable called "ModuleVersion" as "UNSIGNED LONG" type
G) a pointer called "ModuleTable" as a pointer to any kind of data in memory
(void*)

NOW after that, you need to add two subroutines (using the _stdcall
convention) in your main source code file, those subroutines must have the
names: "module_init" and the other "module_deinit", each one doesnt returns
obviously any value (so they are subroutines), and also both doesnt needs
any parameters to be passed to them.

in C language they are like:

void _stdcall module_init(void) {}
void _stdcall module_deinit(void) {}


NOW after adding those subroutines, you need to export two variables, and at
same time define theirs values:

1) one of them called "ImportTable" as "MODULE_IMPORT" type

this one must have the following values in each structure:

IMPORTSentry
---> fnID = 0
---> fnptr = 0 // NULL

nullentry
---> fnID = 0
---> fnptr = 0 // NULL

2) the another one called "Linkage" as "MODULE_LINKAGE" type

this one must have the following values for each member:

ModuleID = 0
module_init // (this is the subroutine we added before)
module_deinit // (this is the other subroutine)
ModuleFlags = 0
ModulePriority = 0
ModuleVersion = 0x0900 // FS2004 version (use 0x0800 for FS2002)
ModuleTable = 0 // NULL


NOW, you are DONE!, that's will allow the Flight Simulator to load your
module (*.dll), when the Flight Simulator loads your module (REMMEMBER, YOUR
MODULE'S ENTRY POINT FUNCTION...in C language it is commonly called
"DllMain"), you MUST hook your module to the main Flight Simulator's window
procedure, the classname of the main window is "FS98MAIN", find that window,
then using the "SetWindowLong" function define a new window procedure and
retrieve the HANDLE of the original FLIGHT SIMULATOR'S window procedure,
that should let you intercept the Flight Simulator's main window's message,
so then you can process each message before the Flight Simulator itself,
then AFTER YOUR NEW WINDOW PROCEDURE FUNCTION receives and process the
message, YOU MUST REDIRECT the window messages to the ORIGINAL FLIGHT
SIMULATOR's window procedure use the function "CallWindowProc"
Ich weiss nicht genau ob ich diese Zeilen richtig habe ?

module_init // (this is the subroutine we added before)
module_deinit // (this is the other subroutine)

Vielleicht kann ja doch nochmal jemand schauen ob das so hinhauen könnte ?

Vielen Dank
Matthias
  Mit Zitat antworten Zitat