Page 7 of 10
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 8:16 pm
by Antonio Linares
Dave,
Have you included this in your EXE PRG ?
DLL FUNCTION HBDLLSTRING2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LPSTR PASCAL LIB "dll2test.dll"
Is Test1() still working ?
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 9:01 pm
by Dave Zowasky
Antonio,
Yes to both questions. My last maindll.c posted is correct my prior one may have had a problem.
I am making sure test1 is good as a control. Let me know if you need me to post any of my code.
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 9:05 pm
by Dave Zowasky
Antonio,
I did and impdef on the dll
Code: Select all | Expand
LIBRARY DLL2TEST.DLL
EXPORTS
DllEntryPoint @1 ; DllEntryPoint
HBDLLENTRY @2 ; HBDLLENTRY
HBDLLENTRY1 @3 ; HBDLLENTRY1
HBDLLENTRY2 @4 ; HBDLLENTRY2
__DbgWndProc @6 ; __DbgWndProc
__WndProc @5 ; __WndProc
___CPPdebugHook @7 ; ___CPPdebugHook
No hbdllstring
Here is what i have in the buildhd,bat
%bcdir%\bin\bcc32 -c -I%hdir%\include;%bcdir%\include -L%bcdir%\..\lib maindll.c
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 9:53 pm
by Antonio Linares
Dave,
HBDLLSTRING2 should be in the DEF file.
I guess maindll.obj is wrong. Or you have not properly rebuilt the DLL.
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 10:18 pm
by Dave Zowasky
Antonio,
Added _export after PASCAL now appears in def and displays message in dll.
Still no return value.
current code in maindll.c
Code: Select all | Expand
HB_EXPORT char * PASCAL _export HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
MessageBox( 0, "Inside ", "1", 0 );
hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );
MessageBox( 0, hb_parc( -1 ), "2", 0 );
return hb_parc( -1 );
}
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 10:25 pm
by Antonio Linares
Dave,
Is this msg properly showing the text ?
MessageBox( 0, hb_parc( -1 ), "2", 0 );
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 10:33 pm
by Dave Zowasky
Antonio,
No, the box 2 appears empty.
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 11:01 pm
by Antonio Linares
Dave,
Is this MsgInfo() showing properly ?
Code: Select all | Expand
function Test2( cMsg1, cMsg2 )
local cr:=chr(13)
cMsg1:=cMsg1+cr+"This is being added on in the DLL."
cMsg1:=cMsg1+cr+" So Far so good."
cMsg1:=cMsg1+cr+"Time to send this message"
cMsg1:=cMsg1+cr+"back the TESTDLL.EXE."
MsgInfo( cMsg1, cMsg2 )
return (cMsg1)
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 11:08 pm
by Dave Zowasky
Antonio,
Yes since I added the _export after PASCAL.
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 11:23 pm
by Antonio Linares
Dave,
Please try it this way:
Code: Select all | Expand
HB_EXPORT char * PASCAL _export HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
{
PHB_ITEM pResult;
MessageBox( 0, "Inside ", "1", 0 );
pResult = hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );
MessageBox( 0, hb_itemGetC( pResult ), "2", 0 );
return hb_itemGetC( pResult );
}
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 11:29 pm
by Dave Zowasky
Antonio,
That works
Thanks
Re: Creating a LIB or DLL
Posted: Thu Apr 02, 2009 11:40 pm
by Antonio Linares
very good
Re: Creating a LIB or DLL
Posted: Fri Apr 03, 2009 3:13 pm
by Dave Zowasky
Antonio,
Thank you very much for all your help.
My project is going very well and I very happy with what we have been able to do so far.
I would like to ask your advice on how best to apply the next changes to the program.
I am trying to have the DoSum return the value from the dll to the exe
In the EXE I will have:
function test3 in the testdll.prg
Code: Select all | Expand
************************** Test 3 DoSum
function test3(x,y)
local cr:=chr(13)
local hItem1 := ItemNew( x )
local hItem2 := ItemNew( y )
local rtnval :=0
rtnval:=HbDLLDoSum2( "DoSum", hItem1, hItem2 )
ItemRelease( hItem1 )
ItemRelease( hItem2 )
MsgInfo( str(rtnval)+"=Total"+cr+"OK! We are back to the EXE." )
return nil
Call to DLL
Code: Select all | Expand
DLL FUNCTION HBDLLDoSUM2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LPSTR PASCAL LIB "dll2test.dll"
In the maindll.c
Code: Select all | Expand
HB_EXPORT char * PASCAL _export HBDLLDOSUM2( char * cProcName, LONG pItem1, LONG pItem2 )
{
PHB_ITEM pResult;
pResult = hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );
return hb_itemGetC( pResult );
}
In the dll2test.prg:
Thanks
Re: Creating a LIB or DLL
Posted: Fri Apr 03, 2009 3:35 pm
by Antonio Linares
Dave,
This time you are going to generate a number (LONG). In case you plan to use decimals, then a different code is needed. Please review Harbour\source\vm\itemapi.c functions:
Code: Select all | Expand
DLL FUNCTION HBDLLDoSUM2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB "dll2test.dll"
In the maindll.c
Code: Select all | Expand
HB_EXPORT LONG PASCAL _export HBDLLDOSUM2( char * cProcName, LONG pItem1, LONG pItem2 )
{
PHB_ITEM pResult;
pResult = hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );
return hb_itemGetNL( pResult );
}
Re: Creating a LIB or DLL
Posted: Fri Apr 03, 2009 10:12 pm
by Dave Zowasky
Antonio,
I applied changes cannot get to MessageBox Point 2
I get a GPF send to microsoft crash.
code in maindll.c
Code: Select all | Expand
HB_EXPORT LONG PASCAL _export HBDLLDOSUM2( char * cProcName, LONG pItem1, LONG pItem2 )
{
PHB_ITEM pResult;
MessageBox( 0, "Point 1", "1", 0 );
pResult = hb_itemDoC( cProcName, 2, ( PHB_ITEM ) pItem1, ( PHB_ITEM ) pItem2, 0 );
MessageBox( 0, "Point 2", "2", 0 );
return hb_itemGetNL( pResult );
}
code in exe
Code: Select all | Expand
DLL FUNCTION HBDLLDOSUM2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB "dll2test.dll"
Code in dll
Thanks