Autor Beitrag
Yasso
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35



BeitragVerfasst: Mi 26.04.06 10:03 
Hallo,

ich hoffe man kann mir weiterhelfen, ich versuche schon seit 4Tagen das Problem zu lösen. Leider bis jetzt kein Erfolg. und zwar.
ich habe eine Delphi-DLL. Diese enthält folgende Funktionen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function SetValues(w1, w2: WORD): Byte; stdcall;
function WriteBlock(b1 : Byte; data: pointer; Size: WORD): Byte; stdcall;
// data: pointer -> zeigt auf einen Array of Byte
// Size: WORD    -> Anzahl der Elemente in data
function Init(Var Pptr1, Pptr2 : Pointer) : Byte; stdcall;
// Pptr1 zeigt auf einen Array[0..511] of Byte. Array befindet sich in der DLL.
// Pptr2 wie Pptr1, aber andere Array -> Array[0..127] of Byte.

// Als Global Variables deklariere ich zwei Pointer, die dann später beim OnCreate intialisiert werden. z.B.

var ptr1, ptr2 : pointer;
...
Init(ptr1,ptr2);


und somit kann ich auf die Arrays in der DLL zugreifen.
In Delphi funktioniert auch alles.


Ich versuche das ganze in C++ Builder umzuschreiben:
In der Header-file wie folgt deklariert:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
class TForm1 : public TForm
{
__published:  // IDE-managed Components
        ...
  ...
private:  // User declarations
  typedef unsigned char (__stdcall *LPSETVALUES)(WORD, WORD);  //Funktionsvereinbarung
  typedef unsigned char (__stdcall *LPWRITEBLOCK)(unsigned char ,unsigned char*, WORD);
  typedef unsigned char (__stdcall *LPINIT)(unsigned char* ,unsigned char*);

  HINSTANCE hDll;
  LPSETVALUES     lpSetValues;  // Function pointer
  LPWRITEBLOCK  lpWriteBlock;
  LPINIT    lpInit;
  
  unsigned char *ptr1;  // ptr1 & ptr2 werden in der Funktion
  unsigned char *ptr2;  // lpInit initialiesiert.
        

public:    // User declarations
        __fastcall TForm1(TComponent* Owner);
};


Die Funktion "SetValues" funktioniert.
Die Funktion "Init" scheint nicht zu funktionieren.
Die beiden Pointer Ptr1 und Ptr2 bleiben nach wie vor NULL.

Was mache ich falsch bei der Deklaration??
Ist die Deklaration der Funktion "WriteBlock" richtig?


ich bitte um Hilfe

vielen Dank

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Moderiert von user profile iconraziel: C#-Tags hinzugefügt

_________________
Yasso
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 26.04.06 10:19 
Var-Parameter in Delphi sind Pointer auf den deklarierten Datentyp. Also bei einem Pointer per Var-Param nicht Pointer, sondern ^Pointer. Daher auch in Delphi manchmal bei Header-Übersetzungen eines C++-Pointers als Var-Param des zugehörigen Records (var R: TRect statt R: PRect).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.