Creating a LIB or DLL

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,

Some progress. I am able to get to entry point 1
My msginfo from test1 in the dll is displayed, however there is no data being displayed in it.

Code: Select all

************************** Test 5 Hello World 2
function test5()
   local cr:=chr(13)
   HbDLLEntry3( "TEST1", "TESTA", "testb" )
   MsgInfo( "OK! We are back to the EXE." )
return nil
 
In my maindll.c

Code: Select all

LONG PASCAL _export HBDLLENTRY3( char * cProcName, char * cText1, char * cText2 )
{
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );
   MessageBox( 0, "Point 1", "1", 0 );
   hb_itemDoC( cProcName, 2, pItem1, pItem2, 0 );

   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 );

   return 0;
}

Code in dll2test.prg

Code: Select all

function Test1( cMsg1, cMsg2 )

   MsgInfo( cMsg1, cMsg2 )

return nil
 
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,

Have you declared HBDLLENTRY3() this way ?

DLL FUNCTION HBDLLENTRY3( cProc AS LPSTR, cText1 AS LPSTR, cText2 AS LPSTR ) AS LPSTR PASCAL LIB "dll2test.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,

I had tried it that way and must have had it wrong. I cut and paste yours and it works great :)

I have been on to next the step.

I am having a problem with my dll compile with this code

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING4( char * cProcName, char cText1, char cText2 )
{
   PHB_ITEM pResult;  
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );
   pResult = hb_itemDoC( cProcName, 2, pItem1, pItem2, 0 );
   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 );
   return hb_itemGetC( pResult );
}

 
I get error

Code: Select all

Error E2342 maindll.c 149: Type mismatch in parameter 'szText' (wanted 'const signed char *', got 'int') in function HBDLLSTRING4
Error E2342 maindll.c 150: Type mismatch in parameter 'szText' (wanted 'const signed char *', got 'int') in function HBDLLSTRING4
Warning W8057 maindll.c 155: Parameter 'cText1' is never used in function HBDLLSTRING4
Warning W8057 maindll.c 155: Parameter 'cText2' is never used in function HBDLLSTRING4
*** 2 errors in Compile ***
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,

You missed two "*" here:

HB_EXPORT char * PASCAL _export HBDLLSTRING4( char * cProcName, char * cText1, char * cText2 )
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,

Works Great 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 started testing my dll and I have had some success with other programs. I am able to get calls to the DLL working using mg.
In my test to return data to the calling program I am getting nothing back to the mg program, however calling DLL `works very good.

I am trying to run some tests using VB and I am running into problems. Should I be able to call my DLL from VB at this point?

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,

> Should I be able to call my DLL from VB at this point?

yes, you should be able to do it.

We don't know anything about mg, sorry.
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 my C++ DLL calls working very well :)

Question is this possible?

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING3( char * cProcName, char * cText1, char * cText2, char * cText3 )
{
   PHB_ITEM pResult;  
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );
   PHB_ITEM pItem3 = hb_itemPutC( NULL, cText3 );

** if possible what here?
   pResult = hb_itemDoC( cProcName, 2, pItem1, pItem2, 0 );


   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 );
   hb_itemRelease( pItem3 );
      return hb_itemGetC( pResult );
}
 
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 have my C++ DLL calls working very well

very good :-)

pResult = hb_itemDoC( cProcName, 3, pItem1, pItem2, pItem3, 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,

I still have a problem when I go to three parameters.

When I call the dll from the exe, the parm data for all three fields is blank

return value is good

Code: Select all

HB_EXPORT char * PASCAL _export HBDLLSTRING5( char * cProcName, char * cText1, char * cText2, char * cText3  )
{
   PHB_ITEM pResult;  
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );
   PHB_ITEM pItem3 = hb_itemPutC( NULL, cText3 );
   MessageBox( 0, "Point  in hbdllstring5", "1", 0 );
   pResult = hb_itemDoC( cProcName, 3, pItem1, pItem2, pItem3, 0 );
   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 );
   hb_itemRelease( pItem3 );
   return hb_itemGetC( pResult );
}

 
in exe

Code: Select all

************************** Test 7 Hello World 3
function test7()
   local cr:=chr(13)

************************** for return string from dll
   local rtnitem:="Return Value not set yet." 
   local item1:="Here We are"
   local item2:="Top of Box"
   local item3:="TItem 3"
   rtnitem:=HbDLLstring5( "TEST5", Item1, Item2, Item3  )
   MsgInfo( rtnitem+cr+"OK! We are back to the EXE." )
return nil
 
in exe

Code: Select all

DLL FUNCTION HBDLLSTRING5( cProc AS LPSTR, cText1 AS LONG, cText2 AS LONG, cText3 AS LONG  ) AS LPSTR PASCAL LIB "dll2test.dll"

In dll

Code: Select all

********************************** Test 2 Hello World Back
function Test5( cMsg1, cMsg2, cMsg3 )
local cr:=chr(13)

   cMsg1:=cMsg1+"This is being added on in the DLL."
   cMsg1:=cMsg1+"     So Far so good."

   MsgInfo( cMsg1, cMsg2 )

   MsgInfo( cMsg3, "AAA" )



return (cMsg1)
 
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 is wrong:

Code: Select all

DLL FUNCTION HBDLLSTRING5( cProc AS LPSTR, cText1 AS LONG, cText2 AS LONG, cText3 AS LONG  ) AS LPSTR PASCAL LIB "dll2test.dll"
 
It has to be this way:

Code: Select all

DLL FUNCTION HBDLLSTRING5( cProc AS LPSTR, cText1 AS LPSTR, cText2 AS LPSTR, cText3 AS LPSTR  ) AS LPSTR PASCAL LIB "dll2test.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,

Works good, I see what to clean up.

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
asimoes
Posts: 5
Joined: Mon Sep 29, 2014 10:58 am

Re: Creating a LIB or DLL

Post by asimoes »

Amigos,
Con base en este ejemplo cómo pasar una variable por referencia, por ejemplo:

cMsg1: = ""
cMsg2: = ""
cMsg3: = ""

Test5(@cMsg1, @cMsg2, @cMsg3)

Hasta ahora no recibo éxito hasta llamar
disculpen mi español es el traductor de google

Code: Select all

hLib := hb_libLoad( "MinhaDll.dll" )
c:=""
x:=hb_DynCall( { "HBDLLSTRING5", hLib, hb_bitOr( HB_DYN_CTYPE_CHAR_PTR , HB_DYN_CALLCONV_STDCALL )  },"Test5", @c, "Top of Box", "Item 3" )
hb_libFree( hLib )
 

Code: Select all

function Test5( cMsg1, cMsg2, cMsg3 )
local cr:=chr(13)

   cMsg1:=cMsg1+"This is being added on in the DLL."
   cMsg1:=cMsg1+"     So Far so good."
   
   cMsg2:="Outro valor"
   cMsg3:="Outro valor"
   
   MsgInfo( cMsg1, cMsg2 )

   MsgInfo( cMsg3, "AAA" )



return (cMsg1)

HB_EXPORT char * PASCAL _export HBDLLSTRING5( char * cProcName, char * cText1, char * cText2, char * cText3  )
{
   PHB_ITEM pResult;  
   PHB_ITEM pItem1 = hb_itemPutC( NULL, cText1 );
   PHB_ITEM pItem2 = hb_itemPutC( NULL, cText2 );
   PHB_ITEM pItem3 = hb_itemPutC( NULL, cText3 );
   MessageBox( 0, "Point  in hbdllstring5", "1", 0 );
   pResult = hb_itemDoC( cProcName, 3, pItem1, pItem2, pItem3, 0 );
   hb_itemRelease( pItem1 );
   hb_itemRelease( pItem2 );
   hb_itemRelease( pItem3 );
   return hb_itemGetC( pResult );
}
 
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 »

regards, saludos

Antonio Linares
www.fivetechsoft.com
asimoes
Posts: 5
Joined: Mon Sep 29, 2014 10:58 am

Re: Creating a LIB or DLL

Post by asimoes »

Hola Antonio,
Gracias por el servicio rápido.
Yo no podía entender cómo aplicar el ejemplo del mensaje que publiqué el problema.
Post Reply