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,

The code seems to be ok
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 am still having problem with test3 (dosum).

To see if it would help me, I decided to move on to my next test which is to send text message to the dll and have the DLL return a numeric value.

Here is the start of my test.

In my testdll.prg

Code: Select all

function test4()
   local cr:=chr(13)
   local hItem1 := ItemNew( "The Message is : Test to return a numeric value" )
   local hItem2 := ItemNew( "This is the Title for the Harbour DLL" )
  

   ?HbDLLstring3( "TEST4", hItem1, hItem2 )

   ItemRelease( hItem1 )
   ItemRelease( hItem2 )

   MsgInfo( "OK! We are back to the EXE." )

return nil
 

in the maindll.c

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING3( 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 my dll2test.prg

Code: Select all

function Test4( cMsg1, cMsg2 )
local z:=99


   MsgInfo( cMsg1, cMsg2 )

return (z)
 
When I run it, it returns blank.

I noticed hb_itemGetNL( pResult ); in test3 however it causes error in compile when used in test4

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,

> I noticed hb_itemGetNL( pResult ); in test3 however it causes error in compile when used in test4

What error do you get ?
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,

Error E2349 maindll.c 130: Nonportable pointer conversion in function HBDLLSTRING3

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,

> Error E2349 maindll.c 130: Nonportable pointer conversion in function HBDLLSTRING3

Please copy line 130 of your maindll.c here, thanks
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,

When I change this

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING3( 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 );
}

 
to this

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING3( 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 );
}

 
I get the error
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,

When you write:

HB_EXPORT char * PASCAL ...

it means that the C function is going to return a char * (pointer to a char), that is a string, and hb_itemGetC( pResult ) returns a char *, so they match.

But when you use hb_itemGetNL( pResult ) then you return a number (LONG) and the compiler complains as there is no match with the specified returned value.

So if you use hb_itemGetNL( pResult ) then you need to declare the function this way:

HB_EXPORT LONG PASCAL ...
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 have started to build the DLL into our production system and I am running my older
FWH along side my newer versions I have a zharbor and zfwh folders going for the
new versions I am building my DLL with all new versions, and my test panel exe using my
older version

I modified how I call dll to be like this:

Code: Select all

************************** Test 5 Hello World Back
function test5()
********
   local cr:=chr(13)
   local hItem1 :="test"
   local hItem2 :="test2"
   local dllhan:=loadlibrary("dll2test.dll")
   local rtnitem:="Return Value not set yet." 
   local zzz
********

   zzz:=getprocaddress(dllhan,"HBDLLSTRING2",.t.,4,4,9,9)
   rtnitem=calldll(zzz,1,"testa","testa")


   MsgInfo( rtnitem+cr+"OK! We are back to the EXE." )

return nil
 
I get a GPF.

Also I was looking at a writing a C example of how to call dll2test.dll test2.

Do I need to include in my C code?
#include <hbapi.h>
#include <hbapiitm.h>



This may explain my GPF in that I would need
to include this in my code for the EXE?

Code: Select all

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>

HB_FUNC( ITEMNEW )
{
   hb_retnl( ( ULONG ) hb_itemNew( hb_param( 1, HB_IT_ANY ) ) );
}

HB_FUNC( ITEMRELEASE )
{
   hb_retl( hb_itemRelease( ( PHB_ITEM ) hb_parnl( 1 ) ) );
}
#pragma ENDDUMP  

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 to use:

DLL FUNCTION ...

instead of:

zzz:=getprocaddress(dllhan,"HBDLLSTRING2",.t.,4,4,9,9)
rtnitem=calldll(zzz,1,"testa","testa")

to be sure that you are using the right params
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 was looking at Visual C++ to replace my BCC55

http://www.microsoft.com/express/download/#webInstall

Is it possible and will I need a new version of Harbour?

I saw buildhm.bat. Wil that compile be compatibel with Visual C++ 2008?

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,

I won't recommend you to switch now to MSVC, in the middle of your DLL development.

First you should complete your development using your current tools and once it is working as expected, then it would be fine to migrate to MSVC.

Just my advise. Obviously you are free to do as you want :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
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,

You have not answered my question regarding:

zzz:=getprocaddress(dllhan,"HBDLLSTRING2",.t.,4,4,9,9)
rtnitem=calldll(zzz,1,"testa","testa")

What DLL FUNCTION ... sentence were you using ? Why aren't you using it now ?
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,

Regarding the MSVC your advice to stay focused on the current development is most graciously appreciated. :)

I was looking at what all the MS Visual Studio Express Editions and got excited.

My main reason in the shift in my code was because we have many calls like that in our production systems. Also I was
using my old FWH compiles to build my exe, add there is not support for
ItemNew() and ItemRelease( ) in the older version.

This was a production/update/implementation issue to us here.

To get back on track, I will update the batch file that I am using to make my test panel exe so that it is on the
latest version of FWH and using the DLL FUNCTION.

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,

As I mentioned I would like to produce an example of calls to the test2 hbdllstring2 in another
language like BCC55.

That way I will be able to show that the DLL will work outside of harbour.


Here is my first attempt at my c code. It is very incomplete and compiles with the expected errors of cProcname, pitem1, and pitem2
Parameter is never used in function HBDLLSTRING2.

Code: Select all

#include <windows.h>
#include <stdio.h>


int __declspec(dllimport) WINAPI HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 );


int main()
  {
  char xdata;
  char ydata;
  printf("Test2 HBDLLString2\n");
  printf("The sum of 4 + 7 is %d\n", HBDLLSTRING2("test4",xdata,ydata));
  return 0;
  }        

#pragma argsused
BOOL WINAPI DllEntryPoint(HINSTANCE h, DWORD d, LPVOID p)
  {
  return TRUE;
  }

int __declspec(dllexport) WINAPI HBDLLSTRING2( char * cProcName, LONG pItem1, LONG pItem2 )
  {
  char xdata;
  return (xdata);
  }

 

My make file:

Code: Select all

.autodepend

testdll.exe : testdll.c
  bcc32 -WCR -Ih:\bcc55\include -Lh:\bcc55\lib testdll.c
 
Still working on it, any advice is appreciated.

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,

Now we have an EXE and the DLL. From the EXE we use hb_itemNew() and hb_itemRelease() but other languages will not have these functions :-)

So the next step is to move those functions from the EXE to the DLL:

Code: Select all

LONG PASCAL HBDLLENTRY2( char * cProcName, char * cText1, char * cText2 )
{
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );

   hb_itemDoC( cProcName, 2, pItem1, pItem2, 0 );

   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 ); 

   return 0;
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply