Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   .NET (https://www.clubdelphi.com/foros/forumdisplay.php?f=17)
-   -   Importar DLL escrita en Delphi 7 (https://www.clubdelphi.com/foros/showthread.php?t=52130)

rcuevas 11-01-2008 09:41:13

Importar DLL escrita en Delphi 7
 
Buenos días,

Les escribo mi problema a ver si me muestran ustedes la luz.

Tengo una dll escrita en Delphi, muy simplona, con sólo 2 funciones:

Código PHP:

unit MainUnit;

interface  
function 
DesEncriptar(TextPChar):PCharStdCall;
function 
Encriptar(TextPChar):PCharStdCall;

implementation  
uses   IPSUFunc
,   Dialogs,   SysUtils;  
function 
DesEncriptar(TextPChar):PChar;
begin   result := PChar(DeCryptString(Text)); end;

function 
Encriptar(TextPChar):PChar;
begin   result := PChar(CryptString(Text)); end;

end

Aunque no he mostrado el código completo del proyecto, la dll compila correctamente, y nada me hace sospechar que haya un error.

Por otro lado, tengo un porgrama en C#.Net que utiliza esta dll. Para ser concreto, realizo la siguiente llamada para importar las funciones

Código:

[DllImport("IPSGraphUtils.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
        static extern string Encriptar(string Text);
        [DllImport("IPSGraphUtils.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
        static extern string DesEncriptar(string Text);

Y en algun lugar del código, utilñizo estas funciones como a continuación escribo:
Código:

UMiss.MissInfo(PerfilTemp.Password + " - " + DesEncriptar(PerfilTemp.Password));
            UMiss.MissInfo(PerfilTemp.Password + " - " + DesEncriptar(PerfilTemp.Password));
            UMiss.MissInfo(PerfilTemp.Password + " - " + DesEncriptar(PerfilTemp.Password));

(MissInfo tan sólo muestra una ventana con el texto que recibe por parámetro)

Y lo sorprendente biene ahora. En la primera llamada a MissInfo, obtengo, por ejemplo, el siguiente texto:
"daasdfasdfasdfsa - qwert@",
mientras que en las sucesivas, obtengo
"daasdfasdfasdfsa - qwerty"

Como bien podéis imaginar, la primera llamada no responde como era de esperar, y no sé porqué: creo que he fijado correctamente a PChar los strings en delphi, tb el CallingConvention y CharSet.

Como pista, diré que si el codigo delphi del siguiente modo el problema desaparece:

Código Delphi [-]
...
function FerVisible(Text: PChar):PChar;
begin
  result := PChar(Trim(DeCryptString(Text)));
end;

function FerInvisible(Text: PChar):PChar;
begin
  result := PChar(Trim(CryptString(Text)));
end;
...

Curioso, eh!!

donki 20-01-2008 17:55:54

Hombre rcuevas,

Ke tal? Este código me suena

Mañana nos vemos


La franja horaria es GMT +2. Ahora son las 19:34:32.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi