Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi C++ Plugin-Code in Delphi (DLL) (https://www.delphipraxis.net/123029-c-plugin-code-delphi-dll.html)

Uwe Raabe 26. Okt 2008 10:43

Re: C++ Plugin-Code in Delphi (DLL)
 
Vielleicht stehe ich ja auf dem gleichen Schlauch wie du, aber ich sehe in den meisten Antworten lediglich Hinweise, wie man die exportierten Methoden einer DLL aufruft. Wenn ich dich richtig verstanden habe, willst du ein Plugin für Garena schreiben, also selbst eine DLL erstellen, die als Plugin von Garena erkannt wird. Dann geht es nicht darum, einen Wrapper für eine DLL zu bekommen, sondern eine Implementation für die Klassen zu schreiben, die in den C++-Headern deklariert sind. In C++ ist das relativ straight forward, aber in Delphi kenne ich bislang keine Möglichkeit, C++-Klassen zu implementieren. Ich lasse mich da gerne aufklären. Also:

Delphi-Quellcode:
if Me_not_standing_on_hose then
  Give_information_on(how_to_implement_C_classes_in_Delphi);

napsterxx 26. Okt 2008 10:48

Re: C++ Plugin-Code in Delphi (DLL)
 
Genau, ein eigenes Plugin welches richtig erkannt werden soll.

Der C++ Wrapper Quelltext:
Delphi-Quellcode:
#ifndef _GARENA_H_
#define _GARENA_H_

#pragma comment(lib, "Garena.lib")

struct ExportUserInfo_t
{
    int Id;             /* user id */
    WCHAR Name[16];     /* user name */
    WCHAR Password[50]; /* user hashed password */
};

struct ExportRoomInfo_t
{
    int GameId; /* game type id */
    int RoomId; /* room id */
    int AreaId; /* area id */
};

struct RoomMsg_t
{
    int FromId;    /* id of user who sent the message */
    WCHAR * pMsg;  /* message string */
};

struct PrivateChat_t
{
    CHARFORMAT cf; /* defined in richedit.h. Display format in RichEdit,
                       check MSDN for details */
    int FromId;    /* id of user who sent the message */
    WCHAR * pMsg;  /* message string */
};

/* for CanAccess() */
#define ROOM_ANNOUNCEMENT_BROADCAST 0x2
#define ADMIN_UNBAN_ID 0x4
#define KICK_USER_FROM_ROOM 0x8
#define BAN_ROOM_CHAT 0x1000
#define ADD_CHANNEL_ADMIN 0x2000
#define BAN_ID_PERMANENT 0x4000
#define SYSTEM_BROADCAST 0x8000

/* for GetRoomType() */
#define ROOMTYPE_PUBLIC 1
#define ROOMTYPE_LADDER 2
#define ROOMTYPE_LEAGUE 4

#ifdef __cplusplus
extern "C"
{
#endif
void WINAPI RegisterUIEvent(const wchar_t *szEvent, LPTHREAD_START_ROUTINE pProc);
void WINAPI CurrentRoomDisplaySystemInfo(const wchar_t * pMsg);
bool WINAPI GetGamePathByGameId(int gameId, wchar_t * szPath, wchar_t * szParam);
HWND WINAPI GetWnd(const char * szName);
bool WINAPI CanAccess(int nRight);
bool WINAPI GetMyInfo(ExportUserInfo_t *pInfo);
bool WINAPI GetCurrentRoomInfo(ExportRoomInfo_t * pInfo);
bool WINAPI SendToUser(int nToUserId, const char * pData, int nLen);
bool WINAPI NotifyTrayMsg(const wchar_t * szName);
#ifdef __cplusplus
};
#endif

#endif // _GARENA_H_

Hier der "automatisch" übersetzte Code in Delphi (viele Fehler):
Delphi-Quellcode:
unit Garena_h;

interface

uses   Windows, Messages, SysUtils, Classes;


#ifndef _GARENA_H_
const _GARENA_H_ =;

//pragma comment(lib, 'Garena.lib')

struct ExportUserInfo_t
begin
    integer Id;             (* user id *)
     Name: array[0..16-1] of WCHAR;     (* user name *)
     Password: array[0..50-1] of WCHAR; (* user hashed password *)
);

struct ExportRoomInfo_t
begin
    integer GameId; (* game type id *)
    integer RoomId; (* room id *)
    integer AreaId; (* area id *)
);

struct RoomMsg_t
begin
    integer FromId;    (* id of user who sent the message *)
    WCHAR * pMsg;  (* message string *)
);

struct PrivateChat_t
begin
    CHARFORMAT cf; (* defined in richedit.h. Display format in RichEdit,
                       check MSDN for details *)
    integer FromId;    (* id of user who sent the message *)
    WCHAR * pMsg;  (* message string *)
);

(* for CanAccess() *)
const ROOM_ANNOUNCEMENT_BROADCAST = $2;
const ADMIN_UNBAN_ID = $4;
const KICK_USER_FROM_ROOM = $8;
const BAN_ROOM_CHAT = $1000;
const ADD_CHANNEL_ADMIN = $2000;
const BAN_ID_PERMANENT = $4000;
const SYSTEM_BROADCAST = $8000;

(* for GetRoomType() *)
const ROOMTYPE_PUBLIC = 1;
const ROOMTYPE_LADDER = 2;
const ROOMTYPE_LEAGUE = 4;

#ifdef __cplusplus
 'C'
begin
//endif
procedure WINAPI RegisterUIEvent(szEvent: PChar; pProc: LPTHREAD_START_ROUTINE);
procedure WINAPI CurrentRoomDisplaySystemInfo(pMsg: PChar);
function WINAPI GetGamePathByGameId(gameId: integer; szPath: PChar; szParam: PChar): bool;
function WINAPI GetWnd(szName: PChar): HWND;
function WINAPI CanAccess(nRight: integer): bool;
function WINAPI GetMyInfo(var pInfo: ExportUserInfo_t): bool;
function WINAPI GetCurrentRoomInfo(var pInfo: ExportRoomInfo_t): bool;
function WINAPI SendToUser(nToUserId: integer; pData: PChar; nLen: integer): bool;
function WINAPI NotifyTrayMsg(szName: PChar): bool;
#ifdef __cplusplus
);
//endif

//endif // _GARENA_H_ 

implementation


end.
Soweit ich jetzt alles verstanden habe ist dieser Wrapper eigentlich überflüssig, denn man braucht nur dein Einsprungspunkt für die Funktionen. Diese Adresse kann man doch über GetProcAddress herrausfinden und dann da wir die Parameter und alles kennen können wir die Funktion aufrufen? Wobei ich nicht erkennen kann wo diese Funktionen stehen sollen (ich nehme an in der Garena.exe). Außerdem was für Klassen??

napsterxx 26. Okt 2008 12:24

Re: C++ Plugin-Code in Delphi (DLL)
 
Für alle Interessenten:
http://eCon-Projects.com/TestPlugin.rar

Ich verstehe da nichts, das komische ist aber das keine der darin beschriebenen Dateien erstellt wird.

napsterxx 26. Okt 2008 19:54

Re: C++ Plugin-Code in Delphi (DLL)
 
Delphi-Quellcode:
extern "C" __declspec(dllexport) ITestPlugin * CreatePlugin(void)

   static ITestPlugin _plugin;
   return &_plugin;
}

Das ist C++ Code. Er wird auch ausgeführt, aber wie sieht das in Delphi aus?

SO?
Delphi-Quellcode:
library Project1

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

procedure CreatePlugin(); stdcall;
begin
  ShowMessage('Create');
end;

exports
CreatePlugin;

begin
  ShowMessage('Start');
end.

DGL-luke 26. Okt 2008 20:42

Re: C++ Plugin-Code in Delphi (DLL)
 
Hmm, da bin ich ja schon ganz schön eingerostet.

Delphi-Quellcode:
//extern "C" __declspec(dllexport) ITestPlugin * CreatePlugin(void)
function CreatePlugin: ITestPlugin; stdcall; export;
begin
 ...
end;
So in der Art denke ich. Du musst es oben im Interface-Teil auch noch deklarieren, damit es wirklich exportiert wird.

napsterxx 26. Okt 2008 22:20

Re: C++ Plugin-Code in Delphi (DLL)
 
Also meine Methode wie ich Sie gepostet habe wird von Garena erkannt und ausgeführt, d.h. ich bekomme die Msg: Create
Aber jetzt weis ich nicht wie es weiter geht :D
Kann nicht ein C-ler helfen :D


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:00 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz