Appel d'une DLL Delphi en C#
Bonjour,
J'ai travaillé sur l'appel d'une dll Delphi en C#.
J'arrive à faire quelques manipulations (afficher un texte, écrire dans un fichier, ....).
Mon souci est le suivant :
Je n'arrive pas à ouvrir une base de données depuis la dll.
J'appelle la même dll depuis un exe Delphi ca marche....
Voici l'appel en C#
Code:
1 2 3 4 5 6 7 8
|
[DllImport("YMsSqlDbUpdate.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
static extern int yConnectedDatabase();
static public void MainUpdate()
{
yConnectedDatabase();
} |
Et voilà le code en Delphi 7
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
procedure yConnectedDatabase; StdCall;
begin
fMsSqlDbUpdate.yConnectedByDLL;
end;
procedure TfMsSqlDbUpdate.yConnectedByDLL;
var
cnx : TYSqlConnection;
begin
try
cnx := TYSqlConnection.Create(nil);
cnx.Connected := false;
cnx.ConnectionName := 'SQLServerConnection';
cnx.DriverName := 'SQLServer';
cnx.GetDriverFunc := 'getSQLDriverSQLServer';
cnx.KeepConnection := true;
cnx.LoginPrompt := false;
cnx.LibraryName := 'dbexpsda.dll';
cnx.VendorLib := 'sqloledb.dll';
cnx.Params.Values['DriverName'] := 'SQLServer';
cnx.Params.Values['HostName'] := 'MyServer';
cnx.Params.Values['DataBase'] := 'MyBDD';
cnx.Params.Values['User_Name'] := 'USER';
cnx.Params.Values['Password'] := '1';
cnx.Params.Values['BlobSize'] := '-1';
cnx.Params.Values['LongStrings'] := 'True';
cnx.Params.Values['EnableBCD'] := 'False';
cnx.Params.Values['FetchAll'] := 'True';
try
cnx.Connected := true;
except
on e:Exception do
DebugSource('c:\tltl.txt', e.Message);
end;
finally
DetruitObjet(cnx);
end;
end; |
Voila, merci pour votre aide.