DLLCALL under Fivewin

DLLCALL under Fivewin

Postby Jimmy » Thu Dec 01, 2022 2:11 pm

hi,

i seems to get another DLLCALL Problem again ... :(

---

i do use
Code: Select all  Expand view
  DLLCALL( "Kernel32.dll", ...

but Result is 0 ...

as it look like the same Problem which i had with "Everything" i guess i need other Way under Fivewin
Code: Select all  Expand view
  hDll = LoadLibrary( "Kernel32.dll" )

so i "load" DLL once at Start and than use hDll Handle.

this work fine with "Everything" ... but i´m NOT allowed to "unload" as it fail when "load" again ... hm :?

so i like to ask if here is another Way to use DLL under Fivewin or what i´m doing wrong :?:

---

Sample is to "safe remove" USE-Stick but it fail with
Error : can not LockVolume() 0
Image
i guess CreateVolHandle() does not work correct under Fivewin

btw. i use UTF-8 or ANSI Function depend on hb_cdpSelect()
what does Fivewin need :?:
Code: Select all  Expand view
#include "FIVEWIN.ch"
#include "common.ch"
#include "EJECTDLL.CH"

#include "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

#define FILE_SHARE_READ                   0x00000001
#define FILE_SHARE_WRITE                  0x00000002
#define FILE_SHARE_DELETE                 0x00000004
#define FILE_SHARE_VALID_FLAGS            0x00000007

#define GENERIC_READ                      0x80000000
#define GENERIC_WRITE                     0x40000000
#define GENERIC_EXECUTE                   0x20000000
#define GENERIC_ALL                       0x10000000

#define OPEN_EXISTING                     3

#define DRIVE_UNKNOWN         0
#define DRIVE_NO_ROOT_DIR     1
#define DRIVE_REMOVABLE       2
#define DRIVE_FIXED           3
#define DRIVE_REMOTE          4
#define DRIVE_CDROM           5
#define DRIVE_RAMDISK         6

#define SW_SHOW               5

STATIC caItems := {}                                                  // for GRID
STATIC acImage := {}
STATIC cInfo   := ""
STATIC aDrives
STATIC hDLL

MEMVAR oFontDefault
MEMVAR BFcolor, BGcolor

*+--------------------------------------------------------------------
*+
*+    Procedure USBeject()
*+
*+    Called from ( dualgrid.prg )   1 - static procedure buildmainmenu()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE USBeject()
LOCAL oDlg, oListbox
LOCAL cDrive  := SPACE( 2 )
LOCAL cTitle  := "Please, select"
LOCAL aDrives := FillDriveArray()
// Codeblock not filled yet
LOCAL bSetGet
LOCAL bChange
LOCAL bValid
LOCAL bLDblClicked
LOCAL bWhen
LOCAL bDrawItem

   DEFINE DIALOG oDlg FROM 5, 10 TO 24, 55 TITLE cTitle COLOR BFcolor, BGcolor

      @  1, 2 LISTBOX oListbox VAR cDrive ITEMS aDrives[1] SIZE 145, 95 PIXEL FONT oFontDefault COLOR BFcolor, BGcolor OF oDlg
*      oListbox := TListBox() :New( 10, 20, bSetGet, aDrives[ 1 ], 145, 95, bChange, ;
*                             oDlg, bValid, BFcolor, BGcolor, .T., .F., ;
*                             bLDblClicked, oFontDefault, "", .T., bWhen, aDrives[ 2 ], ;
*                             bDrawItem, .F., .F. )

      oListbox:SetItems( aDrives[ 1 ], .T. )
      oListbox:SetBitmaps( aDrives[ 2 ] )
      IF !EMPTY( aDrives[ 3 ] )
         oListbox:Select( aDrives[ 3 ] )
      ENDIF

      @  7,  7 BUTTON "&OK" OF oDlg SIZE 40, 12 ;
              ACTION( EjectMedia( cDrive ), oDlg:End() ) DEFAULT

      @  7, 17 BUTTON "&Cancel" OF oDlg SIZE 40, 12 ;
              ACTION( cDrive := nil, oDlg:End() )

#IFDEF __HMG__
   END DIALOG
#ENDIF

   ACTIVATE DIALOG oDlg CENTERED

RETURN

*+--------------------------------------------------------------------
*+
*+    Function EjectMedia()
*+
*+    Called from ( hbeject.prg )   1 - procedure usbeject()
*+
*+--------------------------------------------------------------------
*+
FUNCTION EjectMedia( cDrive, UseCDdrives )

   // ***************************************************************
   //
   //  USBeject based on https://support.microsoft.com/en-us/kb/165721
   //
   //  will eject CD / DVD and "flush Buffer" if USB Drive
   //
   // ***************************************************************

LOCAL hVolRead  := - 1                                                // "CreateFileA"
LOCAL nLock     := 0                                                  // "DeviceIoControl",hVolRead, FSCTL_LOCK_VOLUME
LOCAL nDisMount := 0                                                  // "DeviceIoControl",hVolRead, FSCTL_DISMOUNT_VOLUME
LOCAL nEject    := 0                                                  // "DeviceIoControl",hVolRead, IOCTL_STORAGE_EJECT_MEDIA
LOCAL nAccess   := 0
LOCAL nType     := 0
LOCAL cMsg      := ""
LOCAL nRemove   := 0
LOCAL lRet      := .T.
LOCAL cAction   := GETENV( "SYSTEMROOT" ) + "\SYSTEM32\HOTPLUG.DLL"
LOCAL cRoot     := "RUNDLL32.EXE "
LOCAL cPath     := GETENV( "TEMP" ) + "\"

   DEFAULT UseCDdrives TO .F.

   IF PCOUNT() = 0
      MsgInfo( "
need Drive Letter" )
      RETURN .F.
   ENDIF
   IF EMPTY( cDrive )
      MsgInfo( "
Error no Drive Letter" )
      RETURN .F.
   ELSE
      cDrive := SUBSTR( cDrive, 1, 1 )
   ENDIF

   cAction += "
,HotPlugSafeRemovalDriveNotification "
   cAction += VOLUMENAME( cDrive + "
:\" )
   cAction += "
("
   cAction += cDrive + "
:)"

msginfo(cDrive)

   nType := DriveType( cDrive )
   DO CASE
      CASE nType = DRIVE_UNKNOWN
      CASE nType = DRIVE_NO_ROOT_DIR
      CASE nType = DRIVE_REMOVABLE                                    //  Floppy
         nAccess := GENERIC_READ + GENERIC_WRITE
      CASE nType = DRIVE_FIXED
      CASE nType = DRIVE_REMOTE
      CASE nType = DRIVE_CDROM
         IF UseCDdrives = .T.
            nAccess := GENERIC_READ
         ENDIF
      CASE nType = DRIVE_RAMDISK
      OTHERWISE
         MsgInfo( "
can not use Type " + STR( nType ) )
   ENDCASE

   IF EMPTY( nAccess )
      RETURN .F.
   ENDIF

   cInfo := "
"                                                        // reset STATIC for SayInfo()
   SayInfo( "
waiting for Drive " + cDrive + CRLF )
   hVolRead := CreateVolHandle( @cMsg, nType, nAccess, cDrive )

   IF hVolRead = - 1
      MsgInfo( "
Unable to open drive " + cDrive )
      lRet := .F.
   ELSE

      // *********************************************************
      //
      //  https://msdn.microsoft.com/en-us/library/Aa363216.aspx
      //
      //  BOOL WINAPI DeviceIoControl(
      //    _In_        HANDLE       hDevice,
      //    _In_        DWORD        dwIoControlCode,
      //    _In_opt_    LPVOID       lpInBuffer,
      //    _In_        DWORD        nInBufferSize,
      //    _Out_opt_   LPVOID       lpOutBuffer,
      //    _In_        DWORD        nOutBufferSize,
      //    _Out_opt_   LPDWORD      lpBytesReturned,
      //    _Inout_opt_ LPOVERLAPPED lpOverlapped
      //  );
      //
      // *********************************************************

      nLock := LockVolume( hVolRead )
      IF nLock <> 0
         cMsg := "
LockVolume()" + CRLF
         SayInfo( cMsg )

         nDisMount := DismountVolume( hVolRead )
         IF nDisMount <> 0
            cMsg := "
DismountVolume()" + CRLF
            SayInfo( cMsg )

            // nRemove := PreventRemovalOfVolume( hVolRead, .F. )
            nRemove := 1
            IF nRemove <> 0
               cMsg := "
PreventRemovalOfVolume()" + CRLF
               SayInfo( cMsg )

               nEject := AutoEjectVolume( hVolRead )
               //     IF nEject = 0
               cMsg := "
AutoEjectVolume()" + CRLF
               SayInfo( cMsg )

               //     ELSE
               //         cMsg := "
Error : can not AutoEjectVolume() "+VAR2CHAR(nEject))
               //         lRet := .F.
               //     ENDIF
            ELSE
               cMsg := "
Error : can not PreventRemovalOfVolume() " + VAR2CHAR( nRemove )
               lRet := .F.
               SayInfo( cMsg )
            ENDIF
         ELSE
            cMsg := "
Error : can not DismountVolume() " + VAR2CHAR( nDisMount )
            lRet := .F.
            SayInfo( cMsg )
         ENDIF
      ELSE
         cMsg := "
Error : can not LockVolume() " + VAR2CHAR( nLock )
         lRet := .F.
         SayInfo( cMsg )
      ENDIF
   ENDIF

   CloseVolume( hVolRead )

   IF lRet = .F.
      Msginfo( cMsg )
   ELSE
      SayInfo( "
remove your USE-Stick now" )
      hb_IdleSleep( 2.0 )
      IF nType <> DRIVE_CDROM                                         // will eject
         MEMOWRIT( cPath + "
ShowMsg.BAT", cRoot + cAction )
         ShellExecute( 0, "
runas", cPath + "ShowMsg.BAT",,, SW_SHOW )

         hb_IdleSleep( 2.0 )
         FERASE( cPath + "
ShowMsg.BAT" )
      ENDIF
   ENDIF

RETURN lRet

*+--------------------------------------------------------------------
*+
*+    Static Function CreateVolHandle()
*+
*+    Called from ( hbeject.prg )   1 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION CreateVolHandle( cMsg, nType, nAccess, cDrive )

LOCAL hVolWrite
LOCAL hVolRead
LOCAL nFlush    := 0                                                  // "
FlushFileBuffers"
LOCAL cPath     := "
"
LOCAL nShare    := FILE_SHARE_READ + FILE_SHARE_WRITE
LOCAL nDispo    := OPEN_EXISTING
LOCAL nAttrib   := 0                                                  // FILE_FLAG_OVERLAPPED + FILE_FLAG_BACKUP_SEMANTICS

   /**********************************************************
   *
   * https://msdn.microsoft.com/en-us/library/aa363858.aspx
   *
   * HANDLE WINAPI CreateFile(
   *   _In_     LPCTSTR               lpFileName,
   *   _In_     DWORD                 dwDesiredAccess,
   *   _In_     DWORD                 dwShareMode,
   *   _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
   *   _In_     DWORD                 dwCreationDisposition,
   *   _In_     DWORD                 dwFlagsAndAttributes,
   *   _In_opt_ HANDLE                hTemplateFile
   * );
   *
   **********************************************************/

   cPath := "
\\.\"
   cPath += cDrive
   cPath += "
:"

   // Kernel32
   IF hb_cdpSelect() = "
UTF8"
      hVolWrite := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CreateFileW", cPath, ;                                                              // lpFileName
                            nAccess, ;                                // dwDesiredAccess
                            nShare, ;                                 // dwShareMode
                            NULL, ;                                   // lpSecurityAttributes
                            nDispo, ;                                 // dwCreationDisposition
                            nAttrib, ;                                // dwFlagsAndAttributes
                            NULL )                                    // hTemplateFile
   ELSE
      hVolWrite := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CreateFile", cPath, ;                                                               // lpFileName
                            nAccess, ;                                // dwDesiredAccess
                            nShare, ;                                 // dwShareMode
                            NULL, ;                                   // lpSecurityAttributes
                            nDispo, ;                                 // dwCreationDisposition
                            nAttrib, ;                                // dwFlagsAndAttributes
                            NULL )                                    // hTemplateFile
   ENDIF

   IF hVolWrite = - 1
      RETURN hVolWrite
   ELSE
      // flush buffer
      //
      IF nType <> DRIVE_CDROM
         // Kernel32
         nFlush := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "FlushFileBuffers", hVolWrite )
         cMsg := "
FlushFile()" + CRLF
      ENDIF
   ENDIF

   // Kernel32
   DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CloseHandle", hVolWrite )

   // open again RO
   //
   nAccess := GENERIC_READ

   // Kernel32
   IF hb_cdpSelect() = "
UTF8"
      hVolRead := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CreateFileW", cPath, ;                                                               // lpFileName
                           nAccess, ;                                 // dwDesiredAccess
                           nShare, ;                                  // dwShareMode
                           NULL, ;                                    // lpSecurityAttributes
                           nDispo, ;                                  // dwCreationDisposition
                           nAttrib, ;                                 // dwFlagsAndAttributes
                           NULL )                                     // hTemplateFile
   ELSE
      hVolRead := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CreateFile", cPath, ;                                                                // lpFileName
                           nAccess, ;                                 // dwDesiredAccess
                           nShare, ;                                  // dwShareMode
                           NULL, ;                                    // lpSecurityAttributes
                           nDispo, ;                                  // dwCreationDisposition
                           nAttrib, ;                                 // dwFlagsAndAttributes
                           NULL )                                     // hTemplateFile
   ENDIF

RETURN hVolRead

*+--------------------------------------------------------------------
*+
*+    Static Function LockVolume()
*+
*+    Called from ( hbeject.prg )   1 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION LockVolume( hVolRead )

LOCAL nBytes := 0
LOCAL nLock

   // Kernel32
   nLock := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "DeviceIoControl", hVolRead, ;
                     FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, @nBytes, NULL )

RETURN nLock

*+--------------------------------------------------------------------
*+
*+    Static Function DismountVolume()
*+
*+    Called from ( hbeject.prg )   1 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION DismountVolume( hVolRead )

LOCAL nBytes    := 0
LOCAL nDisMount

   // Kernel32
   nDisMount := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "DeviceIoControl", hVolRead, ;
                         FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, @nBytes, NULL )

RETURN nDisMount

*+--------------------------------------------------------------------
*+
*+    Static Function AutoEjectVolume()
*+
*+    Called from ( hbeject.prg )   1 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION AutoEjectVolume( hVolRead )

LOCAL nBytes := 0
LOCAL nEject

   // Kernel32
   nEject := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "DeviceIoControl", hVolRead, ;
                      IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, @nBytes, NULL )

RETURN nEject

*+--------------------------------------------------------------------
*+
*+    Static Function UnlockVolume()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION UnlockVolume( hVolRead )

LOCAL nBytes  := 0
LOCAL nUnlock

   // Kernel32
   nUnlock := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "DeviceIoControl", hVolRead, ;
                       FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, @nBytes, NULL )

RETURN nUnlock

*+--------------------------------------------------------------------
*+
*+    Static Function CloseVolume()
*+
*+    Called from ( hbeject.prg )   1 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION CloseVolume( hVolRead )

LOCAL lClose
   // Kernel32
   IF hb_cdpSelect() = "
UTF8"
      lClose := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CloseHandleW", hVolRead )
   ELSE
      lClose := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "CloseHandleA", hVolRead )
   ENDIF
RETURN lClose

*+--------------------------------------------------------------------
*+
*+    Static Function PreventRemovalOfVolume()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION PreventRemovalOfVolume( hVolRead, fPreventRemoval )

LOCAL nBytes  := 0
LOCAL nRemove
LOCAL pmr     := 1                                                    // PREVENT_MEDIA_REMOVAL():New()
LOCAL nSize   := pmr:_sizeof_()

   pmr:PreventMediaRemoval := fPreventRemoval
   nSize := 1
   // Kernel32
   nRemove := DLLCALL( "
Kernel32.dll", DLL_OSAPI, "DeviceIoControl", hVolRead, ;
                       IOCTL_STORAGE_MEDIA_REMOVAL, @pmr, nSize, NULL, 0, @nBytes, NULL )

RETURN nRemove

*+--------------------------------------------------------------------
*+
*+    Procedure SayInfo()
*+
*+    Called from ( hbeject.prg )   9 - function ejectmedia()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE SayInfo( cText )

RETURN

*+ EOF: HBEJECT.PRG


"EJECTDLL.CH"
Code: Select all  Expand view
#define VERSION_XP                  5.0
#define VERSION_VISTA               6.0
#define VERSION_WIN7                6.01
#define VERSION_WIN8                6.02
#define VERSION_WIN81               6.03
#define VERSION_WIN10              10.0
#define VERSION_WIN10OLD            6.04

#define NULL                        0
#define MAX_PATH                    200
#define MIN_PATH                    10
#define FORMAT_MESSAGE_FROM_SYSTEM  0x00001000

#define GUID_DEVINTERFACE_VOLUME     "{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}"
#define GUID_DEVINTERFACE_DISK       "{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"
#define GUID_DEVINTERFACE_FLOPPY     "{53f56311-b6bf-11d0-94f2-00a0c91efb8b}"
#define GUID_DEVINTERFACE_CDROM      "{53f56308-b6bf-11d0-94f2-00a0c91efb8b}"
#define GUID_DEVINTERFACE_USB_DEVICE "{A5DCBF10-6530-11D2-901F-00C04FB951ED}"

//
// Configuration Manager CONFIGRET return status codes
//
#define CR_SUCCESS                  (0x00000000)
#define CR_DEFAULT                  (0x00000001)
#define CR_OUT_OF_MEMORY            (0x00000002)

//
// Flags for CM_Query_And_Remove_SubTree
//
#define CM_REMOVE_UI_OK             0x00000000
#define CM_REMOVE_UI_NOT_OK         0x00000001
#define CM_REMOVE_NO_RESTART        0x00000002
#define CM_REMOVE_BITS              0x00000003

// Flags controlling what is included in the device information set built
// by SetupDiGetClassDevs
//
#define DIGCF_DEFAULT               0x00000001  // only valid with DIGCF_DEVICEINTERFACE
#define DIGCF_PRESENT               0x00000002
#define DIGCF_ALLCLASSES            0x00000004
#define DIGCF_PROFILE               0x00000008
#define DIGCF_DEVICEINTERFACE       0x00000010

//
// Flags for SP_DEVICE_INTERFACE_DATA.Flags field.
//
#define SPINT_ACTIVE                0x00000001
#define SPINT_DEFAULT               0x00000002
#define SPINT_REMOVED               0x00000004

#define METHOD_BUFFERED             0
#define METHOD_IN_DIRECT            1
#define METHOD_OUT_DIRECT           2
#define METHOD_NEITHER              3

#define FILE_ANY_ACCESS             0
#define FILE_SPECIAL_ACCESS         (FILE_ANY_ACCESS)
#define FILE_READ_ACCESS            ( 0x0001 )    // file & pipe
#define FILE_WRITE_ACCESS           ( 0x0002 )    // file & pipe

#define FILE_DEVICE_MASS_STORAGE    0x0000002d
#define IOCTL_STORAGE_BASE          FILE_DEVICE_MASS_STORAGE

#xtranslate CTL_CODE( <dt> , <fn> , <mtd> , <acc> ) =>;
nOr( nLShift(<dt>,16) , nLShift(<acc>,14) , nLShift(<fn>,2) , <mtd> )

#define IOCTL_STORAGE_GET_DEVICE_NUMBER  CTL_CODE(IOCTL_STORAGE_BASE, 0x0420, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define FILE_FLAG_BACKUP_SEMANTICS     0x02000000
#define FILE_FLAG_OVERLAPPED           0x40000000

#define FSCTL_LOCK_VOLUME              0x00090018
#define FSCTL_UNLOCK_VOLUME            0x0009001C
#define FSCTL_DISMOUNT_VOLUME          0x00090020

#define IOCTL_STORAGE_EJECT_MEDIA      0x002D4808  // IOCTL_DISK_EJECT_MEDIA
#define IOCTL_STORAGE_MEDIA_REMOVAL    0x002D4804


#define SE_ERR_FNF                     2  // File not found.
#define SE_ERR_PNF                     3  // Path not found.
#define SE_ERR_ACCESSDENIED            5  // Access denied.
#define SE_ERR_OOM                     8  // Out of memory.
#define SE_ERR_SHARE                   26 // Cannot share an open file.
#define SE_ERR_ASSOCINCOMPLETE         27 // File association information not complete.
#define SE_ERR_DDETIMEOUT              28 // DDE operation timed out.
#define SE_ERR_DDEFAIL                 29 // DDE operation failed.
#define SE_ERR_DDEBUSY                 30 // DDE operation is busy.
#define SE_ERR_NOASSOC                 31 // File association not available.
#define SE_ERR_DLLNOTFOUND             32 // Dynamic-link library not found.
 
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Thu Dec 01, 2022 3:40 pm

Dear Jimmy,

FWH way to dinamically use DLL functions is:

DLL FUNCTION ...

DllCall() is a Harbour function.

Why don't you try to use the FWH DLL FUNCTION way ? :-)
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Thu Dec 01, 2022 3:56 pm

hi Antonio,
Antonio Linares wrote:Why don't you try to use the FWH DLL FUNCTION way ? :-)

i have to find out Parameter Type "as PASCAL" to use DLL Function ...

DllCall() is a Harbour function.

it work with same Syntax and Result under HMG and Xbase++ so why not with Fivewin :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Thu Dec 01, 2022 4:09 pm

To find if a function is PASCAL or not, simply use such clause or remove it and check if it works or not. Thats the simplest way

FWH should not affect Harbour's DllCall() behavior, so I guess that you are using wrong parameters with DllCall()

Does your same syntax work in xBase++ ? If so, then it means a Harbour's bug in such function
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Antonio Linares » Thu Dec 01, 2022 4:12 pm

If it works with HMG then it means there is a #define in FWH that is clashing with a Harbour #define or maybe HMG defines it in a different way

Please review this example to see how easily a new define can replace a previous one, and Harbour does not warn you:
Code: Select all  Expand view
#define TEST 123
#define TEST "Another"

function Main()

   ? TEST

return nil
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Thu Dec 01, 2022 4:57 pm

hi Antonio,
Antonio Linares wrote:Does your same syntax work in xBase++ ? If so, then it means a Harbour's bug in such function

first i made the CODE for Xbase++

when got to HMG i found out that i "only" have to write
Code: Select all  Expand view
#xtranslate DllCall       => HMG_CallDLL

to use "same" CODE

this is how HMG call DLL
Code: Select all  Expand view
//   HMG_CallDLL ( cLibName , [ nRetType ] , cFuncName , Arg1 , ... , ArgN ) ---> xRetValue
FUNCTION HMG_CallDLL( cLibName, nRetType, cFuncName, ... )
STATIC s_hDLL   := { => }
STATIC s_mutex  := hb_mutexCreate()
LOCAL nCallConv := HB_DYN_CALLCONV_STDCALL
LOCAL nEncoding := IIF( HMG_IsCurrentCodePageUnicode(), HB_DYN_ENC_UTF16, HB_DYN_ENC_ASCII )
LOCAL pLibrary

   IF HB_ISSTRING( cFuncName ) .AND. HB_ISSTRING( cLibName )
      hb_mutexLock( s_mutex )

      IF !( cLibName $ s_hDLL )
         s_hDLL[ cLibName ] := hb_libLoad( cLibName )
      ENDIF

      pLibrary := s_hDLL[ cLibName ]

      hb_mutexUnlock( s_mutex )

      IF .NOT. HB_ISNUMERIC( nRetType )
         nRetType := HB_DYN_CTYPE_DEFAULT
      ENDIF

      cFuncName := ALLTRIM( cFuncName )

      DO CASE
         CASE HMG_IsCurrentCodePageUnicode() == .T. .AND. HMG_IsFuncDLL( pLibrary, cFuncName + "W" )
            cFuncName := cFuncName + "W"
         CASE HMG_IsCurrentCodePageUnicode() == .F. .AND. HMG_IsFuncDLL( pLibrary, cFuncName + "A" )
            cFuncName := cFuncName + "A"
      ENDCASE

      RETURN hb_DynCall( { cFuncName, pLibrary, hb_bitOR( nCallConv, nRetType, nEncoding ) }, ... )
   ENDIF

RETURN NIL
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Thu Dec 01, 2022 5:16 pm

what nRetType value do you use ?
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Thu Dec 01, 2022 6:21 pm

hi Antonio,
Antonio Linares wrote:what nRetType value do you use ?

DLL_OSAPI -> DLL_STDCALL for "Kernel32.DLL"
Code: Select all  Expand view
#define DLL_STDCALL                 0x20
#if defined( __PLATFORM__WINDOWS )
#define DLL_OSAPI                   DLL_STDCALL
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Jimmy » Thu Dec 01, 2022 8:31 pm

hi Antonio,

it seem i can reduce it to 4 DLL (ANSI) Call but i have Problem with some "Type"
'LPSECURITY_ATTRIBUTES'
LPDWORD


---

i have use Name any Type from Microsoft Webpage (see Link)
Code: Select all  Expand view
* https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
DLL FUNCTION CreateFile(lpFileName            AS LPSTR ,;
                        dwDesiredAccess       AS DWORD ,;
                        dwShareMode           AS DWORD ,;
                        lpSecurityAttributes  AS LPSECURITY_ATTRIBUTES ,;
                        dwCreationDisposition AS DWORD ,;
                        dwFlagsAndAttributes  AS DWORD ,;
                        hTemplateFile         AS LONG ) AS LONG PASCAL FROM "CreateFile" LIB hDll


Code: Select all  Expand view
* https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers
DLL FUNCTION FlushFileBuffers(hVolWrite       AS LONG) AS LONG PASCAL FROM "FlushFileBuffers" LIB hDll


Code: Select all  Expand view
* https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
DLL FUNCTION CloseHandleA( hVolRead           AS LONG) AS LONG PASCAL FROM "CloseHandleA" LIB hDll


Code: Select all  Expand view
* https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-deviceiocontrol
DLL FUNCTION DeviceIoControl( hDevice         AS LONG ,;
                              dwIoControlCode AS DWORD ,;
                              lpInBuffer      AS VOID ,;
                              nInBufferSize   AS DWORD,;
                              lpOutBuffer     AS VOID ,;
                              nOutBufferSize  AS DWORD,;
                              lpBytesReturned AS LPDWORD,;
                              lpOverlapped    AS LPOVERLAPPED ) AS LONG PASCAL FROM "DeviceIoControl" LIB hDll

who can help me to find right Type
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Thu Dec 01, 2022 9:38 pm

Dear Jimmy,

You could use:

Code: Select all  Expand view

SECURITY_ATTRIBUTES sa;

HB_FUNC( LPSECURITY_ATTRIBUTES )
{
   sa.nLength = sizeof( sa );
   sa.lpSecurityDescriptor = NULL;
   sa.bInheritHandle = hb_parl( 1 );

   hb_retnll( ( LONGLONG ) &sa );
}
regards, saludos

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

Re: DLLCALL under Fivewin

Postby TimStone » Thu Dec 01, 2022 10:39 pm

Jimmy,

Instead of the FWH PDF method, I use an external one. Any time I do a print preview, and then want a PDF, I call this. Thus it is called many times each day.

Note these are PASCAL functions, and also note how I create the handle, and then release the .dll at the end. It never has a problem.

The code is built with FWH, Harbour, and MSVC ( Visual Studio Community 2022 ). Perhaps this sample can help you resolve your problem.

Code: Select all  Expand view

FUNCTION BuildPDF( aFiles )

    // Declare LOCAL variables
    LOCAL imageFilename := "   "
    LOCAL pdfFilename := cHome + "ASW_Report.pdf"
    LOCAL ix, iErr := 0, errorText := "  "
    PRIVATE hImLib

    // Load the image2PDF DLL library
    hImLib := LoadLibrary( "image2PDF.dll" )

    // Specify license and process meta file to pdf
    I2PLic( "IXX-XXXX-XXXX" )
    iErr := IPMeta( )
    iErr := IPSize( )
    FOR ix := 1 TO LEN( aFiles )
        imageFilename := aFiles[ix]
        iErr := IPAddImg(imageFilename)
    NEXT
    iErr := IPSetDPI(0)
    iErr := IPMakePDF(pdfFilename, 0, errorText, 40 )

    // Release the library
    FreeLib32( hImLib )

RETURN( pdfFilename )


/*  FUNCTION DLL32 for Image2PDF calls
      Description: Declare functions from Image2PDF.DLL
      Date updated: þ8/25/2007
*/


DLL32 STATIC FUNCTION COPYEMF( hEMF AS LONG, cEMF AS LPSTR ) AS LONG;
    PASCAL FROM "CopyEnhMetaFileA" LIB "gdi32.dll"

DLL32 STATIC FUNCTION WMF2EMF( cWMF AS LPSTR ) AS LONG ;
    PASCAL FROM "Wmf2Emf" LIB "emf.dll"

DLL32 STATIC FUNCTION DELETEEMF( hEMF AS LONG ) AS BOOL ;
    PASCAL FROM "DeleteEMF" LIB "emf.dll"

DLL32 STATIC FUNCTION I2PLic( cLicCode AS LPSTR) AS LONG;
    PASCAL FROM "I2PDF_License" LIB hImLib // "Image2PDF.dll"

DLL32 STATIC FUNCTION IPMeta( ) AS LONG;
    PASCAL FROM "I2PDF_MetaToNativePDF" LIB hImLib //"Image2PDF.dll"

DLL32 STATIC FUNCTION IPSize( ) AS LONG;
    PASCAL FROM "I2PDF_UseEMFDeviceSize" LIB hImLib // "Image2PDF.DLL"

//  static unsigned int I2PDF_AddImage(char *image);
DLL32 STATIC FUNCTION IPAddImg( cImage AS LPSTR ) AS LONG;
    PASCAL FROM "I2PDF_AddImage" LIB hImLib // "Image2PDF.dll"

// I2PDF_AddImageBookmark

//  static unsigned int I2PDF_SetDPI(unsigned int dpi);
DLL32 STATIC FUNCTION IPSetDpi( nDpi AS LONG ) AS LONG;
    PASCAL FROM "I2PDF_SetDPI" LIB hImLib // "Image2PDF.dll"

//   static unsigned int I2PDF_MakePDF(char *output, int options, char *errorText, unsigned int maxErrorTextSize);
DLL32 STATIC FUNCTION IPMakePDF( cOutFile AS LPSTR, nOptions AS LONG, cErrTxt AS LPSTR, nMaxESize AS LONG ) AS LONG;
    PASCAL FROM "I2PDF_MakePDF" LIB hImLib // "Image2PDF.dll"
 
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: DLLCALL under Fivewin

Postby Antonio Linares » Fri Dec 02, 2022 11:17 am

Dear Tim,

Many thanks fr sharing it

You can use DLL FUNCTION instead of DLL32 FUNCTION
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 02, 2022 12:13 pm

hi Antonio,
Antonio Linares wrote:You could use:

thx for HB_FUNC(LPSECURITY_ATTRIBUTES)

i have chage it to
Code: Select all  Expand view
DLL FUNCTION CreateFile(lpFileName            AS LPSTR ,;
                        dwDesiredAccess       AS DWORD ,;
                        dwShareMode           AS DWORD ,;
                        lpSecurityAttributes  AS LPSECURITY_ATTRIBUTES() ,;
                        dwCreationDisposition AS DWORD ,;
                        dwFlagsAndAttributes  AS DWORD ,;
                        hTemplateFile         AS LONG ) AS LONG PASCAL FROM "CreateFileA" LIB hDll

but it still crash :(
Application Internal Error - C:\fwh\0\LISTVIEW\DUALGRID.exe
Terminated at: 2022-12-02 11:46:42
Unrecoverable error 6005: Exception error:

Exception Code:C0000005 ACCESS_VIOLATION
Exception Address:000000DB
EAX:008DAE80 EBX:0014DF38 ECX:FFFFFFFF EDX:00000007
ESI:008DAE70 EDI:005DE520 EBP:004CA0C8
CS:EIP:001B:000000DB SS:ESP:0023:0014DF28
DS:0023 ES:0023 FS:003B GS:0000
Flags:00010206
Exception Parameters: 00000000 000000DB
CS:EIP:
SS:ESP: 00000008 009DD8D4 00000000 00000000 0014E04C 004C3ED2 00000008 005DE11E 00000000 008DAE70 00000020 0000000F 008DB1C4 00000002 00000000 00000011

C stack:
EIP: EBP: Frame: OldEBP, RetAddr, Params...

Modules:
00400000 005A0000 C:\fwh\0\LISTVIEW\DUALGRID.exe
77390000 0019F000 C:\WINDOWS\SYSTEM32\ntdll.dll
766F0000 0009B000 C:\WINDOWS\System32\KERNEL32.DLL
75540000 00219000 C:\WINDOWS\System32\KERNELBASE.dll
73360000 000A0000 C:\WINDOWS\SYSTEM32\apphelp.dll
76D70000 0007B000 C:\WINDOWS\System32\ADVAPI32.DLL
761E0000 000BF000 C:\WINDOWS\System32\msvcrt.dll
5EF70000 00167000 C:\WINDOWS\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.2251_none_d9513b1fe1046fc7\GDIPLUS.DLL
75A20000 00280000 C:\WINDOWS\System32\combase.dll
772C0000 00076000 C:\WINDOWS\System32\sechost.dll
75320000 00120000 C:\WINDOWS\System32\ucrtbase.dll
75F50000 000C5000 C:\WINDOWS\System32\RPCRT4.dll
76510000 0017A000 C:\WINDOWS\System32\USER32.dll
75D30000 000AF000 C:\WINDOWS\System32\COMDLG32.DLL
752C0000 0001D000 C:\WINDOWS\System32\win32u.dll
76430000 00023000 C:\WINDOWS\System32\GDI32.dll
77230000 00087000 C:\WINDOWS\System32\shcore.dll
75440000 000DE000 C:\WINDOWS\System32\gdi32full.dll
67C20000 00019000 C:\WINDOWS\SYSTEM32\MPR.DLL
77340000 00045000 C:\WINDOWS\System32\SHLWAPI.dll
759A0000 0007B000 C:\WINDOWS\System32\msvcp_win.dll
767B0000 005B6000 C:\WINDOWS\System32\SHELL32.dll
6A820000 00008000 C:\WINDOWS\SYSTEM32\VERSION.DLL
67310000 00073000 C:\WINDOWS\SYSTEM32\WINSPOOL.DRV
760F0000 000E3000 C:\WINDOWS\System32\OLE32.DLL
67FE0000 00210000 C:\WINDOWS\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1110_none_a8625c1886757984\COMCTL32.DLL
76470000 00096000 C:\WINDOWS\System32\OLEAUT32.DLL
5FC90000 00006000 C:\WINDOWS\SYSTEM32\MSIMG32.DLL
61200000 00028000 C:\WINDOWS\SYSTEM32\WINMM.DLL
67750000 0002C000 C:\WINDOWS\SYSTEM32\OLEDLG.DLL
763F0000 00027000 C:\WINDOWS\System32\IMM32.DLL
73480000 0007D000 C:\WINDOWS\system32\uxtheme.dll
762A0000 000D4000 C:\WINDOWS\System32\MSCTF.dll
10000000 00200000 c:\fwh\dll\freeimage.dll
6A090000 00094000 C:\WINDOWS\SYSTEM32\TextShaping.dll
73860000 0000F000 C:\WINDOWS\SYSTEM32\kernel.appcore.dll
758B0000 0005F000 C:\WINDOWS\System32\bcryptPrimitives.dll
6E870000 000B9000 C:\WINDOWS\SYSTEM32\textinputframework.dll
72EA0000 0027E000 C:\WINDOWS\System32\CoreUIComponents.dll
73130000 000B2000 C:\WINDOWS\System32\CoreMessaging.dll
76020000 00063000 C:\WINDOWS\System32\WS2_32.dll
746D0000 00029000 C:\WINDOWS\SYSTEM32\ntmarta.dll
72960000 000DB000 C:\WINDOWS\SYSTEM32\wintypes.dll
75CA0000 00083000 C:\WINDOWS\System32\clbcatq.dll
5F170000 00273000 C:\WINDOWS\SYSTEM32\uiautomationcore.dll
71BF0000 000C2000 C:\WINDOWS\SYSTEM32\PROPSYS.dll
74CE0000 0000A000 C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
5EF10000 00053000 C:\WINDOWS\SYSTEM32\OLEACC.dll
73A00000 0060C000 C:\WINDOWS\SYSTEM32\windows.storage.dll
74DD0000 00027000 C:\WINDOWS\SYSTEM32\Wldp.dll
752E0000 0003B000 C:\WINDOWS\System32\CFGMGR32.dll
6FA10000 00043000 C:\Windows\System32\dlnashext.dll
641E0000 0008B000 C:\WINDOWS\system32\wpdshext.dll
70360000 00171000 C:\WINDOWS\SYSTEM32\WindowsCodecs.dll
75520000 0001B000 C:\WINDOWS\System32\bcrypt.dll
75220000 00018000 C:\WINDOWS\SYSTEM32\profapi.dll
5EE10000 00048000 C:\Windows\System32\thumbcache.dll
5FD00000 00032000 C:\Windows\System32\EhStorShell.dll
76DF0000 00434000 C:\WINDOWS\System32\SETUPAPI.dll
57310000 0021F000 C:\Program Files\Microsoft Office\Office12\GrooveShellExtensions.dll
57210000 000F3000 C:\Program Files\Microsoft Office\Office12\GrooveUtil.DLL
5FCC0000 00007000 C:\Program Files\Microsoft Office\Office12\GrooveNew.DLL
67DB0000 0009B000 C:\WINDOWS\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.9672_none_d08f9da24428a513\MSVCR80.dll
5FCA0000 0001B000 C:\WINDOWS\WinSxS\x86_microsoft.vc80.atl_1fc8b3b9a1e18e3b_8.0.50727.762_none_11ecb0ab9b2caf3c\ATL80.DLL
757B0000 000FA000 C:\WINDOWS\System32\CRYPT32.dll
63230000 00456000 C:\WINDOWS\SYSTEM32\WININET.dll
74CF0000 00013000 C:\WINDOWS\SYSTEM32\CRYPTSP.dll
745F0000 0002F000 C:\WINDOWS\system32\rsaenh.dll
57120000 000AF000 C:\WINDOWS\System32\cscui.dll
61910000 0000B000 C:\WINDOWS\SYSTEM32\LINKINFO.dll
6AB60000 001A9000 C:\Windows\System32\urlmon.dll
6B440000 0022D000 C:\Windows\System32\iertutil.dll
6A990000 0001D000 C:\Windows\System32\srvcli.dll
749B0000 0000B000 C:\Windows\System32\netutils.dll
751B0000 00025000 C:\Windows\System32\SspiCli.dll
5B4D0000 00066000 C:\WINDOWS\System32\netshell.dll
748E0000 00032000 C:\WINDOWS\System32\IPHLPAPI.DLL
71A40000 00016000 C:\WINDOWS\System32\nlaapi.dll
686E0000 0001B000 C:\WINDOWS\System32\NetSetupApi.dll
6C340000 00008000 C:\WINDOWS\system32\IconCodecService.dll
6F050000 000BE000 C:\WINDOWS\SYSTEM32\MrmCoreR.dll
5AE90000 0063D000 C:\Windows\System32\ieframe.dll
751E0000 00025000 C:\Windows\System32\USERENV.dll
67590000 00014000 C:\Windows\System32\NETAPI32.dll
6FDC0000 000CB000 C:\Windows\System32\WINHTTP.dll
74700000 00011000 C:\Windows\System32\WKSCLI.DLL
5AE40000 00046000 C:\WINDOWS\SYSTEM32\msIso.dll
663F0000 0000A000 C:\WINDOWS\SYSTEM32\Secur32.dll
56400000 00034000 C:\WINDOWS\SYSTEM32\MLANG.dll
65820000 00093000 C:\Windows\System32\Windows.StateRepositoryPS.dll
71620000 00083000 C:\WINDOWS\SYSTEM32\policymanager.dll
74660000 00065000 C:\WINDOWS\SYSTEM32\msvcp110_win.dll
56440000 0015F000 C:\WINDOWS\SYSTEM32\DUI70.dll
7BB30000 00077000 C:\WINDOWS\SYSTEM32\DUser.dll
6AB40000 0001D000 C:\WINDOWS\SYSTEM32\CHARTV.dll
6EBF0000 003B9000 C:\Windows\System32\OneCoreUAPCommonProxyStub.dll
57030000 0000D000 C:\WINDOWS\SYSTEM32\atlthunk.dll
71D00000 0000F000 C:\WINDOWS\SYSTEM32\WTSAPI32.dll
74D80000 0004E000 C:\WINDOWS\SYSTEM32\WINSTA.dll
66670000 0003D000 C:\Windows\System32\OneCoreCommonProxyStub.dll
66360000 00049000 C:\Windows\System32\Windows.FileExplorer.Common.dll
64A20000 00013000 C:\WINDOWS\system32\mssprxy.dll
76380000 0005E000 C:\WINDOWS\System32\coml2.dll
65BF0000 0005C000 C:\WINDOWS\SYSTEM32\ntshrui.dll
66950000 0000E000 C:\WINDOWS\SYSTEM32\cscapi.dll

Called from FWCALLDLL(0)
Called from CREATEFILE(0) in .\HBEJECT.PRG
Called from CREATEVOLHANDLE(0) in .\HBEJECT.PRG
Called from EJECTMEDIA(0) in .\HBEJECT.PRG
Called from (b)USBEJECT(0) in .\HBEJECT.PRG
Called from TBUTTON:CLICK(181) in .\source\classes\BUTTON.PRG
Called from TBUTTON:HANDLEEVENT(1811) in .\source\classes\CONTROL.PRG
Called from _FWH(3681) in .\source\classes\WINDOW.PRG
Called from SENDMESSAGE(0)
Called from TDIALOG:COMMAND(504) in .\source\classes\DIALOG.PRG
Called from TWINDOW:HANDLEEVENT(0)
Called from TDIALOG:HANDLEEVENT(1220) in .\source\classes\DIALOG.PRG
Called from DIALOGBOXINDIRECTW(0)
Called from TDIALOG:ACTIVATE(307) in .\source\classes\DIALOG.PRG
Called from USBEJECT(0) in .\HBEJECT.PRG
Called from (b)BUILDMAINMENU(0) in .\DUALGRID.PRG
Called from TMENU:COMMAND(1557) in .\source\classes\MENU.PRG
Called from TWINDOW:COMMAND(1158) in .\source\classes\WINDOW.PRG
Called from TWINDOW:HANDLEEVENT(0)
Called from _FWH(3681) in .\source\classes\WINDOW.PRG
Called from WINRUN(0)
Called from TWINDOW:ACTIVATE(1114) in .\source\classes\WINDOW.PRG
Called from MAIN(0) in .\DUALGRID.PRG

so still some Parameter ware wrong ...

here is what Microsoft say
HANDLE CreateFileA(
[in] LPCSTR lpFileName,
[in] DWORD dwDesiredAccess,
[in] DWORD dwShareMode,
[in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes,
[in] DWORD dwCreationDisposition,
[in] DWORD dwFlagsAndAttributes,
[in, optional] HANDLE hTemplateFile
);


btw. what can i use for LPCWSTR ("W" Function) in harbour :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Fri Dec 02, 2022 2:47 pm

Dear Jimmy,

Please declare it this way:

lpSecurityAttributes AS LONG

or

lpSecurityAttributes AS LONGLONG // for 64 bits

When you call the function, that parameter will be LPSECURITY_ATTRIBUTES()

as such parameter is declared by Microsoft like this:

[in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes,

it may work also if you supply a zero as the parameter value

LPCWSTR can be declared as LPSTR as a wide string is also a string
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 02, 2022 3:12 pm

hi Antonio,

thx for Answer
i use same Parameter as they work under HMG and Xbase++

Code: Select all  Expand view
nAccess := GENERIC_READ + GENERIC_WRITE

STATIC FUNCTION CreateVolHandle( cMsg, nType, nAccess, cDrive )
LOCAL cPath     := ""
LOCAL nShare    := FILE_SHARE_READ + FILE_SHARE_WRITE
LOCAL nDispo    := OPEN_EXISTING
LOCAL nAttrib   := 0 // FILE_FLAG_OVERLAPPED + FILE_FLAG_BACKUP_SEMANTICS

   hVolWrite := CreateFile( cPath  , ; // lpFileName
                            nAccess, ; // dwDesiredAccess
                            nShare , ; // dwShareMode
                            NULL   , ; // lpSecurityAttributes
                            nDispo , ; // dwCreationDisposition
                            nAttrib, ; // dwFlagsAndAttributes
                            NULL )     // hTemplateFile
 

when change lpSecurityAttributes to LONG (LONGLONG)

Code: Select all  Expand view
DLL FUNCTION CreateFile(lpFileName            AS LPSTR ,;
                        dwDesiredAccess       AS DWORD ,;
                        dwShareMode           AS DWORD ,;
                        lpSecurityAttributes  AS LONG ,;
                        dwCreationDisposition AS DWORD ,;
                        dwFlagsAndAttributes  AS DWORD ,;
                        hTemplateFile         AS LONG ) AS LONG PASCAL FROM "CreateFileA" LIB hDll


i got
Error description: Error BASE/1099 Argument error: STR
Args:
[ 1] = U

Stack Calls
===========
Called from: => STR( 0 )
Called from: .\HBEJECT.PRG => CREATEFILE( 0 )
Called from: .\HBEJECT.PRG => CREATEVOLHANDLE( 0 )
Called from: .\HBEJECT.PRG => EJECTMEDIA( 0 )
Called from: .\HBEJECT.PRG => (b)USBEJECT( 0 )
Called from: .\source\classes\BUTTON.PRG => TBUTTO

same when use "W" Function :(
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests