Creating a LIB or DLL

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 8:16 pm

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 9:01 pm

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
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 9:05 pm

Antonio,

I did and impdef on the dll

Code: Select all  Expand view
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
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 9:53 pm

Dave,

HBDLLSTRING2 should be in the DEF file.

I guess maindll.obj is wrong. Or you have not properly rebuilt the DLL.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 10:18 pm

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 view
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
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 10:25 pm

Dave,

Is this msg properly showing the text ?

MessageBox( 0, hb_parc( -1 ), "2", 0 );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 10:33 pm

Antonio,

No, the box 2 appears empty.

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 11:01 pm

Dave,

Is this MsgInfo() showing properly ?
Code: Select all  Expand view

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 11:08 pm

Antonio,

Yes since I added the _export after PASCAL.

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 11:23 pm

Dave,

Please try it this way:
Code: Select all  Expand view

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 );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Thu Apr 02, 2009 11:29 pm

Antonio,

That works :)

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Thu Apr 02, 2009 11:40 pm

very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Fri Apr 03, 2009 3:13 pm

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 view

************************** 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 view
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 view
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:
Code: Select all  Expand view
function Test3( x, y )
local z:=X+y
return (z)
 



Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

Re: Creating a LIB or DLL

Postby Antonio Linares » Fri Apr 03, 2009 3:35 pm

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 view
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 view
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 );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41323
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Creating a LIB or DLL

Postby Dave Zowasky » Fri Apr 03, 2009 10:12 pm

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 view
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 view
 ?HbDLLDoSum2( "TEST3",3, 2 )
 


Code: Select all  Expand view
DLL FUNCTION HBDLLDOSUM2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB "dll2test.dll"


Code in dll
Code: Select all  Expand view
 
function Test3( x, y )
local z:=X+y
return (z)
 


Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Dave Zowasky
 
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 10 guests