AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Funktion aus DLL (in C++ geschrieben) nach Delphi importiere
Thema durchsuchen
Ansicht
Themen-Optionen

Funktion aus DLL (in C++ geschrieben) nach Delphi importiere

Ein Thema von STaRDoGGCHaMP · begonnen am 13. Dez 2009 · letzter Beitrag vom 17. Dez 2009
 
STaRDoGGCHaMP

Registriert seit: 1. Okt 2007
34 Beiträge
 
#11

Re: Funktion aus DLL (in C++ geschrieben) nach Delphi import

  Alt 15. Dez 2009, 15:35
Hallo erneut,
Erst einmal vielen Dank für die Antwort Astat, das mit dem Char array war wohl der entscheidende Punkt welcher für die Zugriffsverletzung sorgte. Wenn ich das Programm jetz so ausführe:
Delphi-Quellcode:
program TestpadConsole;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

type
  TPoint = packed record
    x: Integer;
    y: Integer;
  end;

type
  PMove = ^TMove;
  TMove = packed record
    nJumps : Integer;
    nNewPiece : Integer;
    nOldPiece : Integer;
    pfrom : TPoint;
    pto : TPoint;
    pPath : array [0..11] of TPoint;
    pdel : array [0..11] of TPoint;
    nDelPiece : array [0..11] of Integer;
  end;

  TBoard = array [0..7, 0..7] of Integer;
  TStr = array [0..1023] of Char;

const
  PGC_WHITE = 1;
  PGC_BLACK = 2;
  PGC_MAN = 4;
  PGC_KING = 8;

var hDll: THandle;
    nBoard: TBoard;
    playnow: Integer = 1;
    str: TStr;
    Move: TMove;
    GetMove: function(var Board: TBoard; color: Integer; maxtime: Double; str: TStr;
                      var playnow: Integer; info: Integer; unused: Integer;
                      move: PMove): Integer; stdcall;

begin
  try
    hDll := LoadLibrary('C:\..\cakeM32.dll');
    if hDll <> 0 then begin
      @GetMove := GetProcAddress(hDll, 'getmove');
      if Assigned(@GetMove) then begin
        nBoard[0, 0] := PGC_BLACK OR PGC_MAN;
        nBoard[0, 1] := 0;
        nBoard[0, 2] := PGC_BLACK OR PGC_MAN;
        nBoard[0, 3] := 0;
        nBoard[0, 4] := 0;
        nBoard[0, 5] := 0;
        nBoard[0, 6] := PGC_WHITE OR PGC_MAN;
        nBoard[0, 7] := 0;
        nBoard[1, 0] := 0;
        nBoard[1, 1] := PGC_BLACK OR PGC_MAN;
        nBoard[1, 2] := 0;
        nBoard[1, 3] := 0;
        nBoard[1, 4] := 0;
        nBoard[1, 5] := PGC_WHITE OR PGC_MAN;
        nBoard[1, 6] := 0;
        nBoard[1, 7] := PGC_WHITE OR PGC_MAN;
        nBoard[2, 0] := PGC_BLACK OR PGC_MAN;
        nBoard[2, 1] := 0;
        nBoard[2, 2] := PGC_BLACK OR PGC_MAN;
        nBoard[2, 3] := 0;
        nBoard[2, 4] := 0;
        nBoard[2, 5] := 0;
        nBoard[2, 6] := PGC_WHITE OR PGC_MAN;
        nBoard[2, 7] := 0;
        nBoard[3, 0] := 0;
        nBoard[3, 1] := PGC_BLACK OR PGC_MAN;
        nBoard[3, 2] := 0;
        nBoard[3, 3] := 0;
        nBoard[3, 4] := 0;
        nBoard[3, 5] := PGC_WHITE OR PGC_MAN;
        nBoard[3, 6] := 0;
        nBoard[3, 7] := PGC_WHITE OR PGC_MAN;
        nBoard[4, 0] := PGC_BLACK OR PGC_MAN;
        nBoard[4, 1] := 0;
        nBoard[4, 2] := PGC_BLACK OR PGC_MAN;
        nBoard[4, 3] := 0;
        nBoard[4, 4] := 0;
        nBoard[4, 5] := 0;
        nBoard[4, 6] := PGC_WHITE OR PGC_MAN;
        nBoard[4, 7] := 0;
        nBoard[5, 0] := 0;
        nBoard[5, 1] := PGC_BLACK OR PGC_MAN;
        nBoard[5, 2] := 0;
        nBoard[5, 3] := 0;
        nBoard[5, 4] := 0;
        nBoard[5, 5] := PGC_WHITE OR PGC_MAN;
        nBoard[5, 6] := 0;
        nBoard[5, 7] := PGC_WHITE OR PGC_MAN;
        nBoard[6, 0] := PGC_BLACK OR PGC_MAN;
        nBoard[6, 1] := 0;
        nBoard[6, 2] := PGC_BLACK OR PGC_MAN;
        nBoard[6, 3] := 0;
        nBoard[6, 4] := 0;
        nBoard[6, 5] := 0;
        nBoard[6, 6] := PGC_WHITE OR PGC_MAN;
        nBoard[6, 7] := 0;
        nBoard[7, 0] := 0;
        nBoard[7, 1] := PGC_BLACK OR PGC_MAN;
        nBoard[7, 2] := 0;
        nBoard[7, 3] := 0;
        nBoard[7, 4] := 0;
        nBoard[7, 5] := PGC_WHITE OR PGC_MAN;
        nBoard[7, 6] := 0;
        nBoard[7, 7] := PGC_WHITE OR PGC_MAN;
        GetMove(nBoard, PGC_BLACK, 5, str, playnow, 0, 0, @Move);
        Sleep(6000);
      end;
      FreeLibrary(hDll);
    end;
  except
    on E: Exception do begin
      Writeln(E.ClassName, ': ', E.Message);
      Sleep(5000);
    end;
  end;
end.
(Man entschuldige hierbei den großen Code wegen der aufwendigen Deklaration von nBoard, aber ich wollte einfach mal den kompletten Code reinhauen, damit man auch wirklich jede potentielle Fehlerquelle erkennen kann). Krieg ich als Fehler "Ungültige Gleitkommaoperation". Also anscheinend ein Problem in der Funktion selber. Trotzdem ist das sehr merkwürdig, weil dass als Open-Source vorhandene C++-Äquivalent fehlerfrei funktioniert:
Code:
#define WHITE 1
#define BLACK 2
#define MAN 4
#define KING 8
#include <iostream>
#include <windows.h>
using namespace std;

struct coor            
   {
   int x;
   int y;
   };

struct CBmove              
   {
   int jumps;            
   int newpiece;      
   int oldpiece;      
   struct coor from,to;
   struct coor path[12];
   struct coor del[12];
   int delpiece[12];  
   } GCBmove;

typedef INT (WINAPI* PROC1)(int *board, int color, double maxtime, char str[1024], int *playnow, int info, int unused, struct CBmove *move);


int main()
{
   PROC1 getmove1=0;
   HINSTANCE hinstLib1=0;
   char s[1024];
   int playnow = 1;
   int nBoard[8][8];
   struct CBmove LCBmove;
   int x, y;

   hinstLib1 = LoadLibraryA("C:\\..\\cakeM32.dll");
   getmove1 = (PROC1)GetProcAddress(hinstLib1, "getmove");
    nBoard[0][0] = BLACK | MAN;
   nBoard[0][1] = 0;
    nBoard[0][2] = BLACK | MAN;
    nBoard[0][3] = 0;
    nBoard[0][4] = 0;
    nBoard[0][5] = 0;
    nBoard[0][6] = WHITE | MAN;
    nBoard[0][7] = 0;
    nBoard[1][0] = 0;
    nBoard[1][1] = BLACK | MAN;
    nBoard[1][2] = 0;
    nBoard[1][3] = 0;
    nBoard[1][4] = 0;
    nBoard[1][5] = WHITE | MAN;
    nBoard[1][6] = 0;
    nBoard[1][7] = WHITE | MAN;
    nBoard[2][0] = BLACK | MAN;
    nBoard[2][1] = 0;
    nBoard[2][2] = BLACK | MAN;
    nBoard[2][3] = 0;
    nBoard[2][4] = 0;
    nBoard[2][5] = 0;
    nBoard[2][6] = WHITE | MAN;
    nBoard[2][7] = 0;
    nBoard[3][0] = 0;
    nBoard[3][1] = BLACK | MAN;
    nBoard[3][2] = 0;
    nBoard[3][3] = 0;
    nBoard[3][4] = 0;
    nBoard[3][5] = WHITE | MAN;
    nBoard[3][6] = 0;
    nBoard[3][7] = WHITE | MAN;
    nBoard[4][0] = BLACK | MAN;
    nBoard[4][1] = 0;
    nBoard[4][2] = BLACK | MAN;
    nBoard[4][3] = 0;
    nBoard[4][4] = 0;
    nBoard[4][5] = 0;
    nBoard[4][6] = WHITE | MAN;
    nBoard[4][7] = 0;
    nBoard[5][0] = 0;
    nBoard[5][1] = BLACK | MAN;
    nBoard[5][2] = 0;
    nBoard[5][3] = 0;
    nBoard[5][4] = 0;
    nBoard[5][5] = WHITE | MAN;
    nBoard[5][6] = 0;
    nBoard[5][7] = WHITE | MAN;
    nBoard[6][0] = BLACK | MAN;
    nBoard[6][1] = 0;
    nBoard[6][2] = BLACK | MAN;
    nBoard[6][3] = 0;
    nBoard[6][4] = 0;
    nBoard[6][5] = 0;
    nBoard[6][6] = WHITE | MAN;
    nBoard[6][7] = 0;
    nBoard[7][0] = 0;
    nBoard[7][1] = BLACK | MAN;
    nBoard[7][2] = 0;
    nBoard[7][3] = 0;
    nBoard[7][4] = 0;
    nBoard[7][5] = WHITE | MAN;
    nBoard[7][6] = 0;
    nBoard[7][7] = WHITE | MAN;
    (getmove1)((int*)nBoard,BLACK,5,s,&playnow,0,0,&LCBmove);
    for(y = 0; y <= 7; y++)
      for(x = 0; x <= 7; x++)
         cout << "nBoard[" << x << "][" << y << "] = " << nBoard[x][y] << endl;
   system("PAUSE");

   return 0;
}
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:18 Uhr.
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