FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour hb_DynCall or DllCall
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
hb_DynCall or DllCall
Posted: Tue Aug 05, 2025 07:41 PM
Hi,

I know this isn't the right forum but I'm busy with a Harbour program that have to read some data of a library.

ChatGPT helptedmeto write a wrapper, so I can make a static DLL. He also gave me a Harbour example to read it, but that doesn't work.

He gave me a sample with hb_DynCall , and one with DllCall.
Does anyone know how the read the data?

This project is not with FiveWin

First something like this
LOCAL hDLL, pReadFunc, pWriteFunc
   LOCAL cEndpoint := "opc.tcp://localhost:4840" + CHR(0)
   LOCAL cNodeId := "myNodeId" + CHR(0)
   LOCAL nTypeId := 3  // 1=string, 2=double, 3=int32, 4=bool
   LOCAL nValue := 0
   LOCAL ret

   // DLL laden
   hDLL := hb_LibLoad("opcwrap.dll")
   IF hDLL == 0
      ? "Kan DLL niet laden!"
      RETURN
   ENDIF

   // Functies ophalen
   pReadFunc := hb_DynCall("I:opcua_read_value_typed(C,C,I,*I)", hDLL)
   pWriteFunc := hb_DynCall("I:opcua_write_value_typed(C,C,I,*I)", hDLL)

   // Lezen
   ret := Eval(pReadFunc, cEndpoint, cNodeId, nTypeId, @nValue)
   IF ret == 0
      ? "Waarde gelezen:", nValue
   ELSE
      ? "Fout bij lezen! Code:", ret
   ENDIF
then
PROCEDURE Main()
   LOCAL cServer := "opc.tcp://esvtc7291-r520a:4840"
   LOCAL cNode := "ns=1;s=esvtc7291-r520f2770.daca.pv"
   LOCAL dVal := 0.0
   LOCAL nResult

   IF hb_LibLoad("opcua_wrapper.dll") == NIL
      ? "❌ DLL niet geladen"
      RETURN
   ENDIF

   nResult := DllCall("opcua_wrapper.dll", HB_DYN_CALL, "opcua_read_value_typed",;
                      HB_DYN_PTR, cServer,;
                      HB_DYN_PTR, cNode,;
                      HB_DYN_INT, 2,;
                      HB_DYN_PTR, @dVal)

   ? "Lezen:", nResult, "Waarde:", dVal
None of them works.
He gave me also a test cpp-file that should return 123.456
#include <windows.h>

extern "C" {

// Simuleer lezen: als dataType == 26 (double), zet waarde 123.456
__declspec(dllexport)
int __cdecl opcua_read_value_typed(const char* endpointUrl, const char* nodeIdStr, int dataType, void* pResult) {
    if(dataType == 26 && pResult != nullptr) {
        double* pd = (double*)pResult;
        *pd = 123.456;
        return 0;  // success
    }
    return -2; // type mismatch or error
}

}
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: hb_DynCall or DllCall
Posted: Wed Aug 06, 2025 06:48 PM
Puedes usar
DLL32 STATIC FUNCTION QRCode(cStr As STRING, cFile As STRING) AS LONG PASCAL ;
FROM "FastQRCode" LIB "QRCodelib.Dll"
RETURN NIL
Para llamar desde una dll externa
O
nHandler := CallDll32( "OpenComFiscal" , "WINFIS32.DLL" , nPort , 1 )
CallDll32( "InitFiscal" , "WINFIS32.DLL" , nHandler )
CallDll32 ( "UltimaRespuesta" , "WINFIS32.DLL" , nHandler, @s )
Llamando a una funcion dentro del ddl, con los para

Continue the discussion