Intercambiando datos con DLL Pascal

Intercambiando datos con DLL Pascal

Postby AngelSalom » Thu Nov 23, 2017 9:14 am

Buenas amigos, estoy haciendo pinitos en Delphi para crear algunas funciones y he creado una DLL muy simple para acceder desde Harbour/FW.

Code: Select all  Expand view
library ejemplolibreria;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

procedure pruebaMensaje (mensaje : string); stdcall;
begin
  ShowMessage (mensaje) ;
end;

exports pruebaMensaje;

begin
end.


La llamada desde Harbour/FW

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
  pruebaMensaje ('hola')
Return (nil)

DLL32 FUNCTION pruebaMensaje ( mensaje AS PTR)  AS WORD PASCAL LIB "ejemplolibreria.dll"
 


Hace la llamada correctamente y muestra el cuadro de mensaje pero en blanco, como si no le pasara el parámetro.
¿Qué estoy haciendo mal?

Gracias!
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Intercambiando datos con DLL Pascal

Postby cnavarro » Thu Nov 23, 2017 9:58 am

Prueba con

AS LPSTR
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Intercambiando datos con DLL Pascal

Postby AngelSalom » Thu Nov 23, 2017 10:06 am

Cristóbal con LPSTR ni siquiera muestra el cuadro.

Si hago
Code: Select all  Expand view
library ejemplolibreria;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

procedure pruebaMensaje (mensaje : Integer; mensaje2 : string ); stdcall;
begin
  ShowMessage (inttostr (mensaje)) ;
  ShowMessage (mensaje2) ;
end;

exports pruebaMensaje;

begin
end.


y ...

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
  pruebaMensaje (123,"123")

Return (nil)

DLL FUNCTION pruebaMensaje ( mensaje AS _INT, mensaje2 AS PTR ) AS WORD PASCAL LIB "ejemplolibreria.dll"
 


El primer mensaje (pasado por _INT) se muestra pero el segundo , probado como STRING, PTR o LPSTR no muestra nada. Si lo pruebo como STRING o PTR muestra el mensaje vacío, si lo pruebo como LPSTR ni siquiera muestra el mensaje ...
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Intercambiando datos con DLL Pascal

Postby AngelSalom » Fri Nov 24, 2017 8:18 am

Vuelvo ...

Codigo Pascal ..

Code: Select all  Expand view
library ejemplolibreria;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

procedure pruebaMensaje (mensaje : Integer; mensaje2 : Integer ) ; stdcall;
begin
  ShowMessage (inttostr (mensaje)) ;
  mensaje2 := 999 ;
end;

exports pruebaMensaje;

begin
end.


Código harbour ...
Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
Local nNumero:=0

  pruebaMensaje (123,@nNumero)
 
  msginfo (nNumero)

Return (nil)

DLL FUNCTION pruebaMensaje ( mensaje AS _INT, mensaje2 AS _INT ) AS WORD PASCAL LIB "ejemplolibreria.dll"


Además de que no consigo pasarle una cadena, el nNumero pasado por referencia tampoco actualiza los valores. ¿Estoy intentando hacer algo imposible? ¿Debería hacerlo en C++ en vez de en Delphi?
¿Alguna idea?

Gracias!
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Intercambiando datos con DLL Pascal

Postby Busmatic_wpb » Sun Nov 26, 2017 4:54 am

Estimado A mi me toco lo mismo de echo es complicado desde FW para un string, yo desarrolle una dll en delphi y para poder pasaler parametros en string tuve que utilizar un ini. Pero logre pasar paremetros de esta manera @Largo cuando es un string..

function incios...

OCAL cDllName:="SCLib.DLL"
Local fHandle:=0
Local ACR120libHandle := LoadLibrary( cDllName)

HaveTag :=space(150)
SerialNum :=space(110)
Largo :=0
TagType :=space(50)
RTag :=0
RSn :=space(7)


fRetCode := ACR120_Select(fHandle, @HaveTag, @Largo, @SerialNum)

if ACR120libHandle <> 0
FreeLibrary(ACR120libHandle)
ENDIF


return

DLL FUNCTION ACR120_Select(fHandle AS LONG , @HaveTag AS PTR , @Largo AS PTR, @SerialNum AS PTR) AS LONG PASCAL FROM "ACR120_Select" LIB "acr120u.DLL"
Regards.
S.I.T.U.
Sistemas Inteligentes de transporte urbano
http://www.situcr.com
oscarchacon@Situcr.com
Desarrollos BA4/B4j androide
User avatar
Busmatic_wpb
 
Posts: 162
Joined: Wed Feb 22, 2017 2:19 am

Re: Intercambiando datos con DLL Pascal

Postby AngelSalom » Mon Nov 27, 2017 8:33 am

Gracias, haré las pruebas como indicas.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 16 guests