Dll : C/C++ // Delphi : incompatibilité ? (avec code)

Résolu
GLBX Messages postés 6 Date d'inscription mardi 31 août 2004 Statut Membre Dernière intervention 5 juin 2014 - 4 juin 2014 à 15:19
solilog Messages postés 273 Date d'inscription samedi 13 juin 2009 Statut Membre Dernière intervention 18 avril 2015 - 5 juin 2014 à 17:22
Bonjour,

Bonjour,
Je dispose d'une dll (écrite en C/C++) mise à disposition sur le Web et utilisée worldwide dans des programmes autres que Delphi {:<0 - Je ne parviens pas à la faire tourner dans un programme Delphi.
Sans doute, erreur d'appel et/ou erreur dans la définition des varaibles à utiliser ?.


RecDealPBN = packed record
//------------------------------------------------------------------------------
(***
struct deal {
int trump; /* I.e. which suit that is trump or if contract is NT, Spades=0, Hearts=1, Diamonds=2, Clubs=3, NT=4 */
int first; /* 0-3, 0=North, 1=East, 2=South, 3=West , Leading hand for the trick.*/
int currentTrickSuit[3]; /* 0-2 for up to 3 cards in the order played */
int currentTrickRank[3]; /* 2-14 for up to 3 cards */
char remainCards[80]; /* First character identifies the hand having the cards given first
in the string, then the cards of the other hands are given in a
clock-wise order, see example above. Null characters fill out
the character array at the end. */
}
***)
Trump,First : integer;
CurrentTrickSuit, CurrentTrickRank : array[0..2] of integer;
RemainCards : array[0..79] of char;
end;

PtrRecFutureTricks = ^RecFutureTricks;
RecFutureTricks = packed record
//------------------------------------------------------------------------------
(***
struct futureTricks { /* The DLL provides the score (number of tricks) that can be won by the card to play defined by its suit and rank. Array of all alternative cards. */
int nodes; /* Number of searched nodes */
int cards; /* No of alternative cards */
int suit[13]; /* 0=Spades, 1=Hearts, 2=Diamonds, 3=Clubs */
int rank[13]; /* 2-14 for 2 through Ace */
int equals[13]; /* Bitstring of ranks for equivalent lower rank cards. The decimal value range between 4 (=2) and 8192 (King=rank 13). When there are several "equals", the value is the sum of each "equal". */
int score[13]; /* -1 indicates that target was not reached, otherwise target or max numbe of tricks */
} ;
***)
nodes, cards : integer;
suit : array[0..12] of integer;
rank : array[0..12] of integer;
equals : array[0..12] of integer;
score : array[0..12] of integer;
end;
//------------------------------------------------------------------------------

TW_dll_PBN = class(TForm)
Button1 : TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;

var
W_dll_PBN: TW_dll_PBN;

Futp : PtrRecFutureTricks;
DealPbn : RecDealPBN;

procedure InitStart(x,y:integer); external 'DDS.dll' // No entry point in DDS.dll !!!!!!!!!!!!!!!!
function SolveBoardPBN(dealPBN:RecDealPBN;target,solutions,mode:integer;futp:PtrRecFutureTricks;threatIndex:integer):integer; external 'DDS.dll'




StrPCopy(DealPBN.RemainCards,'W:T5.K4.652.A98542 K6.QJT976.QT7.Q6 432.A.AKJ93.JT73 AQJ987.8532.84.K');
try
try
new(Futp);
fillchar(futp,sizeof(RecFutureTricks),0);
succes:=SolveBoardPBN(DealPBN, -1, 1, 1, futp, 1);//, deal.first=1, i.e. East leads.
if succes <>0 then showmessage('Error '+inttostr(succes));
except
//on e:exception do showmessage('Error ' + e.Message);
showmessage('Unsuccessfull');
end;
finally
dispose(futp);
end; //EXAMPLE : SolveBoardPBN(RemainCards, -1, 1, 1, &fut, 0); deal.first=1, i.e. East leads.

Si quelqu'un peut m'aider,

Merci d'avance

3 réponses

solilog Messages postés 273 Date d'inscription samedi 13 juin 2009 Statut Membre Dernière intervention 18 avril 2015 10
4 juin 2014 à 20:43
Salut,
A première vue, tes déclarations de records semblent correspondre mais pas pour les 2 functions des DLLs car "en general" les dll faites en C/C++ doivent être déclarées stdcall ainsi:

procedure InitStart(x,y:integer); external 'DDS.dll' stdcall;

et l'autre aussi.
Regarde la doc sur les proc/funct stdcall, pascal, ...
Ca devrait marcher.

Bon courage.

solilog
1
GLBX Messages postés 6 Date d'inscription mardi 31 août 2004 Statut Membre Dernière intervention 5 juin 2014
4 juin 2014 à 23:20
Super !!
Je risque de devenir un fan des dll (car multiples routines réutilisées dans mes divers programmes...)
Pour les puristes :
Ajouter stdcall permettait au programme de ne plus crasher mais toujours avec un code d'erreur !
En fait, dans l'initialisation de RecFutureTricks
 (fillchat(futp,sizeof(....,
j'avais "oublié" de déréférencer le pointeur !!!
donc

fillchar(futp^, sizeof(.....
Après cette correction, la fonction renvoie des résultats corrects !

Un tout grand merci à Solilog : Efficacité/temps de réponse := efficience +++ !!!
0
solilog Messages postés 273 Date d'inscription samedi 13 juin 2009 Statut Membre Dernière intervention 18 avril 2015 10
5 juin 2014 à 17:22
Salut,
Tu n'as plus qu'à fermer ton post.
solilog
0
Rejoignez-nous