Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Bpl en RAD Studio 10.3 consumido en Delphi 2010 (https://www.clubdelphi.com/foros/showthread.php?t=97368)

Nano Ramírez 28-03-2025 16:38:28

Bpl en RAD Studio 10.3 consumido en Delphi 2010
 
Buen día a todos. Tengo el siguiente bpl creado en RAD Studio 10.3:

Código Delphi [-]
unit unitConsumo; interface uses
System.SysUtils, System.Classes,Vcl.Dialogs, IdHTTP, IdSSLOpenSSLHeaders, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdServerIOHandler, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
function pruebaString():string; stdcall; procedure prueba(); implementation procedure prueba(); begin ShowMessage('yes'); end; function pruebaString():string; stdcall; begin Result:='a ver si ya'; end; exports prueba, pruebaString ;



Dicho BPL lo consumo desde delphi 2010:

Código Delphi [-]
program pConsumoBplConsola; {$INCLUDE FastMM4Options.inc} {$APPTYPE CONSOLE} uses FastMM4 in 'FastMM4.pas', FastMM4LockFreeStack in 'FastMM4LockFreeStack.pas', FastMM4Messages in 'FastMM4Messages.pas', SysUtils, Windows; var token: WideString; H: THandle; obtenerToken: function(urlToken, grantType, clienteId, clienteSecreto, resource: string): WideString;stdcall; obtenerString : function(): string; stdcall; obtenerprueba : procedure(); begin ReportMemoryLeaksOnShutdown := true; FullDebugModeScanMemoryPoolBeforeEveryOperation := true; try ScanMemoryPoolForCorruptions; token := 'hola'; H := 0; obtenerToken := nil; obtenerprueba := nil; obtenerString := nil; try H := LoadPackage('ConsumoD365.bpl'); if H <> 0 then begin @obtenerString := GetProcAddress(H, 'pruebaString'); // @obtenerToken:=GetProcAddress(H,'getToken'); // @obtenerprueba:=GetProcAddress(H,'prueba'); if Assigned(obtenerString) then begin token := obtenerString(); { token:=obtenerToken( 'urlToken', 'grant_type', 'clienteId', 'clienteSecreto', 'resource'); } Writeln('*******************************'); Writeln(token); Writeln('*******************************'); end else begin Writeln('No se cargó la función'); end; end else begin Writeln('No se cargó el bpl'); end; except on E: Exception do Writeln('Error dentro;', E.ClassName, ': ', E.Message); end; finally if H <> 0 then begin FreeLibrary(H); end; end; Readln; end.



El problema es el siguiente:
Cuando consumo el BPL y utilizo el procedure funciona sin problema. Pero cuando utilizo una función del BPL me arroja errores de memoria.
El objetivo (como pueden ver en la variable comentada "{token:=obtenerToken(...}") es consumir una api que me retorne un token de acceso y sí lo hace correctamente pero el problema es el mismo, aparecen errores de memoria.
Pensé que sería un problema por los dcp que utiliza mi BPL para hacer la conexión, por lo que hice este ejemplo en donde la función retorne solamente un valor String y también lo regresa de forma correcta, pero persiste el problema de fuga de memoria.

He utilizado la herramienta FastMM4 y me arroja este reporte:


--------------------------------2025/3/27 18:06:48--------------------------------
FastMM has detected an error during a FreeMem operation. The block header has been corrupted.

The current thread ID is 0x358C, and the stack trace (return addresses) leading to this error is:
00403C56 [System.pas][System][FreeMem][3030]
00405D26 [System.pas][System][LStrArrayClr][13726]
00416394
77B1FCC9 [BaseThreadInitThunk]
77E67CBE [RtlGetAppContainerNamedObjectPath]
77E67C8E [RtlGetAppContainerNamedObjectPath]

Current memory dump of 256 bytes starting at pointer address 2AA8508:
B0 04 02 00 00 00 00 00 0B 00 00 00 61 00 20 00 76 00 65 00 72 00 20 00 73 00 69 00 20 00 79 00
61 00 00 00 01 00 00 00 B0 04 02 00 00 00 00 00 0B 00 00 00 74 00 70 00 65 00 72 00 73 00 69 00
73 00 74 00 65 00 6E 00 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
° . . . . . . . . . . . a . . v . e . r . . s . i . . y .
a . . . . . . . ° . . . . . . . . . . . t . p . e . r . s . i .
s . t . e . n . t . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Estos son los dcp usados por mi BPL:

bindcomp.dcp
bienengine.dcp
IndyCore.dcp
IndyProtocols.dcp
IndySystem.dcp
rtl.dcp
vcl.dcp
Agradezco de antemano la atención y ojalá alguien pueda apoyarme.
PD: soy nuevo el Delphi :p

Neftali [Germán.Estévez] 01-04-2025 13:21:46

En mi caso he realizado una prueba rápida cargando la BPL y ejecutando ambas llamadas (primero el procedure y después la función) y me ha funcionado sin problemas (con Delphi 10.3).
Con el mismo código que has puesto.



Lo que sí hemos comentado otras veces, que a las DLLs y por extensión a las BPLs no les gustan mucho el tipo string. Cambia el string de retorno de la función por un PChar o un PAnsiChar y vuelve a probar.

Nano Ramírez 12-04-2025 20:17:36

Excelente Neftali. Desconocía que era mejor trabajarlo con punteros. Muchas gracias!!


La franja horaria es GMT +2. Ahora son las 13:24:39.

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