Creating a LIB or DLL

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

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

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post 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
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
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

I did and impdef on the dll

Code: Select all

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

Re: Creating a LIB or DLL

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

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post 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

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

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Is this msg properly showing the text ?

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

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

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

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Is this MsgInfo() showing properly ?

Code: Select all

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
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

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

Re: Creating a LIB or DLL

Post by Antonio Linares »

Dave,

Please try it this way:

Code: Select all

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
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post by Dave Zowasky »

Antonio,

That works :)

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Creating a LIB or DLL

Post by Antonio Linares »

very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post 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

************************** 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

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

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

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

Re: Creating a LIB or DLL

Post 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

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

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
Dave Zowasky
Posts: 125
Joined: Wed Oct 19, 2005 2:28 pm
Location: Hudson Ohio
Contact:

Re: Creating a LIB or DLL

Post 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

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

  ?HbDLLDoSum2( "TEST3",3, 2 )
 

Code: Select all

DLL FUNCTION HBDLLDOSUM2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB "dll2test.dll"
Code in dll

Code: Select all

  
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
Post Reply