Calling LHA32.DLL

Post Reply
MichaelMo
Posts: 55
Joined: Thu Feb 15, 2007 1:35 am

Calling LHA32.DLL

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Calling LHA32.DLL

Post 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 "@"
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
kim yong woo
Posts: 55
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea
Contact:

Re: Calling LHA32.DLL

Post 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
User avatar
kim yong woo
Posts: 55
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea
Contact:

Re: Calling LHA32.DLL

Post 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?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Calling LHA32.DLL

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply