• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

what is the equivalent of PB Winapi.inc in WinFBX

Started by Chris Chancellor, July 27, 2018, 08:04:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello Jose

Your PB includes has a Winapi.inc  ,  what is the equivalent  in WinFBX ?

i have tried using the below includes but not sucessful

#include "Cwindows.inc"
#include "windows.bi" 

i'm converting a PB program to FB  and it uses a winapi function  GetVolumeInformation()




José Roca

#1
Most of the Windows API headers are provided with the compiler and have a ".bi" extension. To access GetVolumeInformation, you need to use #include once "windows.bi".

If you want to include CWindow.inc (not CWindows.inc) you have to use #include once "Afx/CWindow.inc".

This in te case that you're using the WinFBE editor. If you're using another editor or compiling from the command prompt you will have to follow the instructions of the other editor and/or the FreeBasic help file.

BTW "i have tried using the below includes but not sucessful" is of no help. You have to provide more information, such error messages.

Chris Chancellor

Thanxx Jose

Here's the PB code i was trying to translate to FB




' #INCLUDE "C:\FreeBasic\WinFBE_Suite\FreeBASIC-1.06.0-win64\inc\Afx\CWindow.inc"
#include once "windows.bi"
' This prog does NOT get give the Manufacturer HDD serial # but
' Microsoft assigned HDD serial (done during HDD formating )
' you need to use the program  Real HDD Serial.bas to get this manufacturer HDD serial


'==========================================
' Obtain the Hard Drive Serial number
declare FUNCTION DriveSerialNumber(Drive AS STRING) AS STRING
dim  AS long  hWord
dim AS long LWord
dim as string Volname 'AS ASCIIZ * 16
dim as string VolBuffer 'AS ASCIIZ * 255
dim AS LONG lpVolumeSerialNumber

dim AS LONG lpMaximumComponentLength
dim AS LONG lpFileSystemFlags
dim as string FileSysBuffer 'AS ASCIIZ * 255

IF GetVolumeInformation ( bycopy Drive, VolBuffer, SIZEOF(VolBuffer), lpVolumeSerialNumber , lpMaximumComponentLength, _
lpFileSystemFlags , FilesysBuffer, SIZEOF(FilesysBuffer)) <> 0 THEN
    HWord = HIWRD(lpVolumeSerialNumber)
    LWord = LOWRD(lpVolumeSerialNumber)
    FUNCTION = RIGHT$("0000000"+HEX$(HWord), 4)  + RIGHT$("0000000"+HEX$(LWord), 4)
ELSE
    FUNCTION = "Cannot Read Drive.."
END IF

END FUNCTION



'============================
FUNCTION myMAIN () AS LONG
     dim AS STRING Drsn = "" 
     dim AS STRING dDrive =""
     dDrive = "c:\"
     Drsn = DriveSerialNumber(dDrive)
     ? " MS assigned HDD serial # " + Drsn

END FUNCTION




and here's the error codes



FreeBASIC Compiler - Version 1.06.0 (07-03-2018), built for win32 (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
standalone
target:       win32, 486, 32bit
compiling:    C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas -o C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.asm (main module)
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(24) error 42: Variable not declared, bycopy in 'IF GetVolumeInformation ( bycopy Drive, VolBuffer, SIZEOF(VolBuffer), lpVolumeSerialNumber , lpMaximumComponentLength, _'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(26) error 42: Variable not declared, HIWRD in 'HWord = HIWRD(lpVolumeSerialNumber)'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(27) error 42: Variable not declared, LOWRD in 'LWord = LOWRD(lpVolumeSerialNumber)'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(28) error 254: Illegal outside a FUNCTION block, found 'FUNCTION' in 'FUNCTION = RIGHT$("0000000"+HEX$(HWord), 4)  + RIGHT$("0000000"+HEX$(LWord), 4)'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(30) error 254: Illegal outside a FUNCTION block, found 'FUNCTION' in 'FUNCTION = "Cannot Read Drive.."'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(33) error 112: END SUB or FUNCTION without SUB or FUNCTION, found 'END' in 'END FUNCTION'
C:\FreeBasic\WinFBE_Suite\PB\Git HDD sn\Git HDD sn.bas(45) warning 13(0): Function result was not explicitly set



looks to me that the PB's bycopy command cannot be translated to FB ?


José Roca

#3
> looks to me that the PB's bycopy command cannot be translated to FB ?

Right... and HIWRD must be HIWORD, and LOWRD must be LOWORD, and DECLARE is for declares not for functions, and your'e using STRING instead of ZSTRING, and suffixes like "$" aren't used, and, above all, FreeBasic is not PowerBasic. Also, it looks like you have very little knowledge of using the Windows API.


'#CONSOLE ON
#include once "windows.bi"

'==========================================
' Obtain the Hard Drive Serial number
FUNCTION DriveSerialNumber(BYREF Drive AS STRING) AS STRING

   DIM VolBuffer AS ZSTRING * MAX_PATH
   DIM dwVolumeSerialNumber AS DWORD
   DIM dwMaximumComponentLength AS DWORD
   DIM dwFileSystemFlags AS DWORD
   DIM FileSysBuffer AS ZSTRING * MAX_PATH

   IF GetVolumeInformation(Drive, @VolBuffer, SIZEOF(VolBuffer), @dwVolumeSerialNumber, @dwMaximumComponentLength, _
      @dwFileSystemFlags, @FilesysBuffer, SIZEOF(FilesysBuffer)) <> 0 THEN
      FUNCTION = HEX(HIWORD(dwVolumeSerialNumber), 4) & HEX(LOWORD(dwVolumeSerialNumber), 4)
   ELSE
      FUNCTION = "Cannot Read Drive.."
   END IF

END FUNCTION

DIM Drsn AS STRING
DIM dDrive AS STRING
dDrive = "c:\"
Drsn = DriveSerialNumber(dDrive)
print " MS assigned HDD serial # " + Drsn
     
print
print "Press any key..."
sleep


Chris Chancellor

Thanxx a lot Jose

yes, i'm just a beginner programmer and i learnt a lot about conversion from PB to FB today
from you