Page 1 of 1

Calling LHA32.DLL

Posted: Sat Jun 27, 2009 1:32 am
by MichaelMo
I"m trying to figure out how to access the unlha function of the LHA32.DLL file from Fivewin/Harbour. In C#, the code below works just fine to access the unlha function of the library. I'm wondering if someone could help me out with the call in Harbour in terms of the way the function assigns the variables.

[DllImport("UNLHA32", CharSet = CharSet.Ansi)]
public static extern long Unlha(IntPtr hwnd, string szCmdLine, StringBuilder SzOutput, int dwSize); /// <summary>

I defined the function below in Harbour but I've got something wrong and it does absolutely nothing. I'm not sure how to define an intPtr in harbour or an INT for that matter.

hUnLhaDll := loadlibrary(u_home_dir + "\UNLHA32.DLL")
DLL32 FUNCTION UnLha(hIntPtr AS LONG,szCmdLine as LPSTR,szOutPut as LPSTR,dwSize as LONG) AS LONG PASCAL LIB "UNLHA32.DLL"

When I call the function it doesn't complain, it simply doesn't do anything at all. I'm guessing it's the use of a LONG but I'm not sure how that translates into harbour.

Re: Calling LHA32.DLL

Posted: Sat Jun 27, 2009 5:59 am
by Antonio Linares
Michael,

Try it this way:

DLL32 FUNCTION UnLha( hIntPtr AS LONG, szCmdLine as LPSTR, @szOutPut as LPSTR, dwSize as LONG ) AS LONG PASCAL LIB "UNLHA32.DLL"

Please notice that szOutPut must be passed by reference "@"

Re: Calling LHA32.DLL

Posted: Thu Jul 23, 2015 8:48 am
by kim yong woo
Dear Mr.Antonio Linares,

I am facing similar situation, and just by imitation, I've tested "MyTest.prg" to make following C# sample.

Code: Select all

[DllImport("SKB_OpenAPI_PAS.dll")]
public static extern int PAS_Init(string strAppKey);
 

I've tested as following..

Code: Select all

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

local hDLL := LoadLibrary( "SKB_OpenAPI_PAS.dll" )
LOCAL nCN

Ncn := PAS_INIT("TESTE")

MSGSTOP(NCN)

FreeLibrary( hDLL )

return nil

//----------------------------------------------------------------------------//

DLL32 FUNCTION PAS_Init( strAppKey as LPSTR) AS LONG PASCAL LIB "SKB_OpenAPI_PAS.dll"
 
The answer was "0"..

Based on manual, the answer should be "0x081B"...

when I wrote in following way,
DLL32 FUNCTION PAS_Init( strAppKey as LPSTR) AS INT PASCAL LIB "SKB_OpenAPI_PAS.dll"

The error message was
Called from: ab.prg => PAS_INIT( 20 )
Called from: ab.prg => MAIN( 10 )

Please give me advice...

Thanks..

Y.W.Kim

Re: Calling LHA32.DLL

Posted: Thu Jul 23, 2015 8:59 am
by kim yong woo
I've corrected one mistake, and corrected as followings..

DLL32 FUNCTION PAS_Init( strAppKey as LPSTR) AS _INT PASCAL LIB "SKB_OpenAPI_PAS.dll"

INT-> _INT
but, the answer was still, "0", , not "0x081B"...

Where is another mistake?

Re: Calling LHA32.DLL

Posted: Thu Jul 23, 2015 10:10 am
by Antonio Linares
Kim,

If the DLL SKB_OpenAPI_PAS.dll is developed in .NET (C#, etc) then you can not directly use it
from Harbour, as Harbour is developed with C code and you can not use .NET from standard C.

The only way to manage .NET from Harbour and FWH is as I implemented here:

https://code.google.com/p/fivenet/wiki/architecture