call DLL under FiveWin

call DLL under FiveWin

Postby Jimmy » Mon Aug 01, 2022 10:23 pm

hi,

under Xbase++ i use
Code: Select all  Expand view
  DllCall("User32.DLL", DLL_STDCALL,"GetWindowRect", obj:GetHWND(), @cBuffer)


under HMG
Code: Select all  Expand view
#xtranslate DllCall => HMG_CallDLL
   DllCall('User32.dll', DLL_OSAPI, 'GetWindowRect", obj:GetHWND(), @cBuffer)


how under FiveWin :?:
please do not answer ; use "C" Code ...
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1585
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: call DLL under FiveWin

Postby Antonio Linares » Mon Aug 01, 2022 11:37 pm

Dear Jimmy,

In FWH you have function GetWndRect( hWnd ) --> aRect :-)
regards, saludos

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

Re: call DLL under FiveWin

Postby Jimmy » Mon Aug 01, 2022 11:48 pm

hi Antonio,
Antonio Linares wrote:In FWH you have function GetWndRect( hWnd ) --> aRect :-)
Yes ... just a Sample for Xbase++ and HMG Syntax

i want to use "as much old Code" as possible so i like to know how under FiveWin, thx
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1585
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: call DLL under FiveWin

Postby carlos vargas » Tue Aug 02, 2022 2:06 am

harbour\contrib\hbxpp

just include the hbxpp lib and the dll.ch from harbour\contrib\hbxpp
Code: Select all  Expand view

/*
 * Xbase++ compatibility header
 *
 * Copyright 2010 Viktor Szakats (vszakats.net/harbour)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file LICENSE.txt.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA (or visit https://www.gnu.org/licenses/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour.  If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */


/* NOTE: This file is also used by C code. */

#ifndef _DLL_CH
#define _DLL_CH

#define DLL_CDECL                   0x08
#define DLL_STDCALL                 0x20
#define DLL_SYSTEM                  0x04
#if defined( __PLATFORM__WINDOWS )
#define DLL_OSAPI                   DLL_STDCALL
#elif defined( __PLATFORM__OS2 )
#define DLL_OSAPI                   DLL_SYSTEM
#else
#define DLL_OSAPI                   DLL_CDECL
#endif

/* Only for compatibility.
   Harbour always copies the string to a temporary buffer. */

#define DLL_CALLMODE_COPY           0
#define DLL_CALLMODE_NORMAL         DLL_CALLMODE_COPY

#endif /* _DLL_CH */

 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: call DLL under FiveWin

Postby carlos vargas » Tue Aug 02, 2022 2:07 am

Code: Select all  Expand view
/*
 * DLL call demonstration.
 *
 * Copyright 2008 Viktor Szakats (vszakats.net/harbour)
 *
 */


#require "hbxpp"

#include "simpleio.ch"

#include "dll.ch"

#define MAX_PATH                    260

#define MB_OK                       0x00000000
#define MB_OKCANCEL                 0x00000001
#define MB_ABORTRETRYIGNORE         0x00000002
#define MB_YESNOCANCEL              0x00000003
#define MB_YESNO                    0x00000004
#define MB_RETRYCANCEL              0x00000005
#define MB_CANCELTRYCONTINUE        0x00000006
#define MB_ICONHAND                 0x00000010
#define MB_ICONQUESTION             0x00000020
#define MB_ICONEXCLAMATION          0x00000030
#define MB_ICONASTERISK             0x00000040
#define MB_USERICON                 0x00000080
#define MB_DEFBUTTON2               0x00000100
#define MB_DEFBUTTON3               0x00000200
#define MB_DEFBUTTON4               0x00000300
#define MB_SYSTEMMODAL              0x00001000
#define MB_TASKMODAL                0x00002000
#define MB_HELP                     0x00004000
#define MB_NOFOCUS                  0x00008000
#define MB_SETFOREGROUND            0x00010000
#define MB_DEFAULT_DESKTOP_ONLY     0x00020000
#define MB_TOPMOST                  0x00040000
#define MB_RIGHT                    0x00080000
#define MB_RTLREADING               0x00100000

#define SPI_SETDRAGFULLWINDOWS      37

#define CSIDL_APPDATA               0x001a /* <username>\Application Data */
#define CSIDL_ADMINTOOLS            0x0030 /* <username>\Start Menu\Programs\Administrative Tools */

PROCEDURE Main()

   LOCAL hDLL
   LOCAL cData

#if defined( __PLATFORM__WINDOWS )

   IF hb_FileExists( "pscript.dll" )
      hDLL := DllLoad( "pscript.dll" )
      cData := Space( 24 )
      DllCall( hDll, DLL_OSAPI, "PSGetVersion", @cData )
      ? ">" + cData + "<"
      DllUnload( hDLL )

      // ; Testing failure 1
      hDLL := DllLoad( "pscript.dll" )
      cData := Space( 24 )
      DllCall( hDll, DLL_OSAPI, "PSGet__Version", @cData )
      ? ">" + cData + "<"
      DllUnload( hDLL )
   ENDIF

   // ; Testing failure 2
   hDLL := DllLoad( "nothere.dll" )
   cData := Space( 24 )
   DllCall( hDll, NIL, "PSGetVersion", @cData )
   ? cData
   DllUnload( hDLL )

   ? "MsgBox:", DllCall( "user32.dll", DLL_OSAPI, "MessageBoxA", 0, "Hello world!", "Harbour sez", hb_bitOr( MB_OKCANCEL, MB_ICONEXCLAMATION, MB_HELP ) )

   /* Force Windows not to show dragged windows contents */

   ? "Full content drag: OFF"
   ? DllCall( "user32.dll", DLL_OSAPI, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 0, 0, 0 )
   Inkey( 0 )

   ? "Full content drag: ON"
   ? DllCall( "user32.dll", DLL_OSAPI, "SystemParametersInfoA", SPI_SETDRAGFULLWINDOWS, 1, 0, 0 )
   Inkey( 0 )

   ? "DLLCALL"
   cData := Space( MAX_PATH )
   ? DllCall( "shell32.dll", DLL_OSAPI, "SHGetFolderPathA", 0, CSIDL_ADMINTOOLS, 0, 0, @cData )
   ? "REF:", cData

   ? "DLLCALL"
   cData := Space( MAX_PATH )
   ? DllCall( "shell32.dll", DLL_OSAPI, "SHGetFolderPathW", 0, CSIDL_ADMINTOOLS, 0, 0, @cData )
   ? "REF:", cData

#endif

   RETURN
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: call DLL under FiveWin

Postby hua » Tue Aug 02, 2022 2:13 am

Jimmy,
See Dll entry at fwh\manual\fwcmd.chm . We also use to have a wiki. I'm not sure of its latest url

Defining a external DLL function to be called at RunTime

DLL [STATIC] FUNCTION <FuncName> ( ;[ <Param1> AS <Type1> ] ;
[ <ParamN> AS <TypeN> ] ) ;
AS <return> [PASCAL] [ FROM <SymName> ] LIB <DllName>


To access a 32 bits DLL function
DLL32 [STATIC] FUNCTION <FuncName> ( ;[ <Param1> AS <Type1> ] ;
[ <ParamN> AS <TypeN> ] ) ;
AS <return> [PASCAL] [ FROM <SymName> ] LIB <DllName>


FiveWin lets you declare an external DLL function to be called at RunTime by its own name. See DllCall.prg example.
Code: Select all  Expand view

<FuncName>          The name of the DLL function. Remember Clipper only uses 10 characters maximum length.
<Param1>               Name of a parameter.
<Type>,<return>     BYTE, CHAR, WORD, BOOL, HANDLE, HWND, HDC, LONG, STRING, LPSTR, PTR, DOUBLE
<SymName>           The name of the DLL function to execute. By default the same DLL FUNCTION <name> is used.
<DllName>             Name of the DLL.
 



CLAUSES
Code: Select all  Expand view

FROM                    To specify a different DLL function name to access. Please review SOURCE\WINAPI\*.prg code samples.
 


We recommend to develop a C language based connection functions when you are going to develop an intensively work with some DLLs. See "using Windows API".

Example:
Calling SndPlaySound() at RunTime:
Code: Select all  Expand view

#include "FiveWin.ch"
function Main()
   SndPlaySound( "tada.wav", 0 )
return

DLL FUNCTION SndPlaySound( cFile AS LPSTR, nType AS WORD );
AS BOOL PASCAL LIB "MMSYSTEM.DLL"
 



Designing the same DLL connection using C language:
Code: Select all  Expand view


#include <WinTen.h>
#include <Windows.h>
#include <MMSystem.h>
#include <ClipApi.h>

CLIPPER SNDPLAYSOU()   // ND()
{
  _retl( sndPlaySound( _parc( 1 ), _parni( 2 ) ) );
}




In this situation it is necessary to use a specific LIB so the linker will know how the DLL connection must be done at RunTime.
Example:


TEST.DLL // Is a commercial DLL we are going to use
Code: Select all  Expand view

IMPDEF.EXE TEST.DEF TEST.DLL  // IMPDEF.EXE is a tool Microsoft and Borland provides
 



Now, edit TEST.DEF -which it is an ascii file- and rename the symbols with 10 characters or less with an underscore:
Code: Select all  Expand view

LESS10   --->   _LESS10


Then do:
Code: Select all  Expand view

IMPLIB.EXE TEST.LIB TEST.DEF  


When linking use that .LIB !



Review our \WinApi directory C -only registered users- source code to see a lot of examples of doing this.

Warning: SndPlaySound() is already built inside FiveWin.lib. It has been used just in this example for learning purposes.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: call DLL under FiveWin

Postby Jimmy » Tue Aug 02, 2022 6:27 am

hi,
carlos vargas wrote:
harbour\contrib\hbxpp

just include the hbxpp lib and the dll.ch from harbour\contrib\hbxpp

YES, i forgot that i also use it under HMG ...
Thx for remind me
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1585
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: call DLL under FiveWin

Postby Otto » Tue Aug 02, 2022 8:03 am

WOW, Jimmy, you are truly a universal Clipperian.


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 93 guests