DirectuX
22-10-2018, 16:20
Hi,
until now I've thought about two methods to get the GUIDs :
method 1: Capturing mountvol.exe output
Adapting this : https://www.thinbasic.com/community/showthread.php?8357-Capturing-OS_ShellExecute-Output
'---Load Console Module
Uses "Console"
USES "File"
uses "Console"
uses "OS"
Dim sTempFile as string 'complete path to the temporary file that will contain the output of the command
dim sCommande as string 'command to send to shell
dim sBuffer as string 'this will contain the output of the command read from the temporary file
sTempFile = OS_GetTempDir & "test1.txt"
sCommande = OS_ENVIRON("COMSPEC") & " /C " & " mountvol.exe > " & sTempFile
msgboxw 0,sCommande 'check what will be send to shell
'RunOnce: set console font for thinBasic and cdm.exe
'
'uses "registry"
'Registry_SetValue("HKEYCU", "Console\O:_thinBasic_thinBasic.exe", "FaceName", "Lucida Console")
'Registry_SetValue("HKEYCU", "Console\C:_Windows_System32_cmd.exe", "FaceName", "Lucida Console")
'/!\01 Doesn't behave as whished, had to manually change font setting in console's property panel. Rebooting doesn't help.
Console_SetOutputCP(65001)'Set output codepage to UTF-8
Console_Writeline("Test Console App: éùçàëØ€")'Test console output
'Display is ok after manual console-font change, this is not convenient for final user
OS_Shell(sCommande, %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
sBuffer += file_load(sTempFile)
' /!\02 File contains many commas where accentuated characters have to be
msgboxw 0, sBuffer
' /!\03 Text displayed contains many `?` where accentuated characters have to be
PrintL "Press a key to end program"
'---Wait for a key press
WaitKey
method 2: Calling kernel32.dll functions (Prefered as no file is written, no change to system's console configuration)
https://docs.microsoft.com/fr-fr/windows/desktop/FileIO/volume-management-functions
Adapting this : https://www.thinbasic.com/community/showthread.php?8199-declare-function-from-handle
Uses "OS"
Uses "console"
'---
'---Standard API functions to get a function address. Those functions are used to simulate Petr SomeDirtyAPIToTellMeHandle function
'---
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (lpLibFileName As ASCIIZ) As Long
Declare Function GetProcAddress Lib "KERNEL32.DLL" Alias "GetProcAddress" (ByVal hModule As DWORD, lpProcName As ASCIIZ) As Long
'---
'---Standard API functions to Data Access and Storage. https://docs.microsoft.com/fr-fr/windows/desktop/api/fileapi/
' (Memo, this may help too: https://www.codeproject.com/Articles/27355/Inside-Mountvol-exe)
'---
Declare Function FindFirstVolume (byref lpszVolumeName As Long, cchBufferLength as dword) As Long
Declare Function FindNextVolume (byref hFindVolume as long,byref lpszVolumeName as long,byref cchBufferLength as Dword) as boolean
Declare Function FindVolumeClose (byref hFindVolume AS long) as boolean
'/!\ 01 Can't find in thinBasic's documentation any correspondance table with https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types , best guess:
'BOOL -> Boolean
'Handle -> Long
'LPWSTR -> Long
'DWORD -> Dword
'TCHAR -> ? (8 or 16-bit Unicode character)
'---OK, here we start simulating the assigment of the procedure address
Dim hLib As Long
Dim hProc As Long
Dim hProc2 As Long
dim hProc3 as Long
'---First we need to load the library from where we want the address of the function
hLib = LoadLibrary("KERNEL32.DLL")
'---If return value is NOT zero all is ok
If hLib <> 0 Then
'---Now we try to get the address of the prodecure inside the library
hProc = GetProcAddress(hLib, "FindFirstVolumeW")
hProc2 = GetProcAddress(hLib, "FindNextVolumeW")
hProc3 = GetProcAddress(hLib, "FindVolumeClose")
'---If return value is NOT zero all is ok
If hProc <> 0 and hproc2 <> 0 and hproc3 <> 0 Then
'---
'---Here the new thinBasic functionality. It assign a process address to a generic previously declared function allowing subsequent calling
Declare Set ADDRESS FindFirstVolume, hProc
Declare Set ADDRESS FindNextVolume, hProc2
Declare Set ADDRESS FindVolumeClose, hProc3
'---Now we try to use the functionality
dim VolumeName As String ' will contain the current VolumeName found
Dim Display as String ' will contain the concatened string to display
dim lpszVolumeName as long ' pointer to VolumeName
lpszVolumeName = STRPTR (VolumeName) '
Dim cchBufferLength as dword
cchBufferLength = 200
'/!\02 how long ? is it arbitrary ?
dim hFindVolume as long
dim isClosedVolume as boolean
isClosedVolume = false
hFindVolume = FindFirstVolume(lpszVolumeName, cchBufferLength)
'/!\03 This has not populated `VolumeName`
Display += VolumeName & $CRLF
do while not isClosedVolume
DoEvents
if FindNextVolume(hFindVolume,lpszVolumeName,cchBufferLength) then
'/!\04 This has returned `0` (false)
Display += VolumeName & $CRLF
else
isClosedVolume = FindVolumeClose(hFindVolume)
endif
loop
MSGBOXw 0, Display
Else
MSGBOX 0, "It was not possible to get the procedure address"
End If
Else
MSGBOX 0, "It was not possible to load library"
End If
WaitKey
Method 1 may work but is inconvenient (notice the /!\ in code comments). I can't get method 2 (prefered) to work and examples/discussions found in the forum didn't bring me further than what is above. What didn't I understand about declarations or usage ?
'ThinAir 1.10.5.0 on Win 8.1 x64
until now I've thought about two methods to get the GUIDs :
method 1: Capturing mountvol.exe output
Adapting this : https://www.thinbasic.com/community/showthread.php?8357-Capturing-OS_ShellExecute-Output
'---Load Console Module
Uses "Console"
USES "File"
uses "Console"
uses "OS"
Dim sTempFile as string 'complete path to the temporary file that will contain the output of the command
dim sCommande as string 'command to send to shell
dim sBuffer as string 'this will contain the output of the command read from the temporary file
sTempFile = OS_GetTempDir & "test1.txt"
sCommande = OS_ENVIRON("COMSPEC") & " /C " & " mountvol.exe > " & sTempFile
msgboxw 0,sCommande 'check what will be send to shell
'RunOnce: set console font for thinBasic and cdm.exe
'
'uses "registry"
'Registry_SetValue("HKEYCU", "Console\O:_thinBasic_thinBasic.exe", "FaceName", "Lucida Console")
'Registry_SetValue("HKEYCU", "Console\C:_Windows_System32_cmd.exe", "FaceName", "Lucida Console")
'/!\01 Doesn't behave as whished, had to manually change font setting in console's property panel. Rebooting doesn't help.
Console_SetOutputCP(65001)'Set output codepage to UTF-8
Console_Writeline("Test Console App: éùçàëØ€")'Test console output
'Display is ok after manual console-font change, this is not convenient for final user
OS_Shell(sCommande, %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
sBuffer += file_load(sTempFile)
' /!\02 File contains many commas where accentuated characters have to be
msgboxw 0, sBuffer
' /!\03 Text displayed contains many `?` where accentuated characters have to be
PrintL "Press a key to end program"
'---Wait for a key press
WaitKey
method 2: Calling kernel32.dll functions (Prefered as no file is written, no change to system's console configuration)
https://docs.microsoft.com/fr-fr/windows/desktop/FileIO/volume-management-functions
Adapting this : https://www.thinbasic.com/community/showthread.php?8199-declare-function-from-handle
Uses "OS"
Uses "console"
'---
'---Standard API functions to get a function address. Those functions are used to simulate Petr SomeDirtyAPIToTellMeHandle function
'---
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (lpLibFileName As ASCIIZ) As Long
Declare Function GetProcAddress Lib "KERNEL32.DLL" Alias "GetProcAddress" (ByVal hModule As DWORD, lpProcName As ASCIIZ) As Long
'---
'---Standard API functions to Data Access and Storage. https://docs.microsoft.com/fr-fr/windows/desktop/api/fileapi/
' (Memo, this may help too: https://www.codeproject.com/Articles/27355/Inside-Mountvol-exe)
'---
Declare Function FindFirstVolume (byref lpszVolumeName As Long, cchBufferLength as dword) As Long
Declare Function FindNextVolume (byref hFindVolume as long,byref lpszVolumeName as long,byref cchBufferLength as Dword) as boolean
Declare Function FindVolumeClose (byref hFindVolume AS long) as boolean
'/!\ 01 Can't find in thinBasic's documentation any correspondance table with https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types , best guess:
'BOOL -> Boolean
'Handle -> Long
'LPWSTR -> Long
'DWORD -> Dword
'TCHAR -> ? (8 or 16-bit Unicode character)
'---OK, here we start simulating the assigment of the procedure address
Dim hLib As Long
Dim hProc As Long
Dim hProc2 As Long
dim hProc3 as Long
'---First we need to load the library from where we want the address of the function
hLib = LoadLibrary("KERNEL32.DLL")
'---If return value is NOT zero all is ok
If hLib <> 0 Then
'---Now we try to get the address of the prodecure inside the library
hProc = GetProcAddress(hLib, "FindFirstVolumeW")
hProc2 = GetProcAddress(hLib, "FindNextVolumeW")
hProc3 = GetProcAddress(hLib, "FindVolumeClose")
'---If return value is NOT zero all is ok
If hProc <> 0 and hproc2 <> 0 and hproc3 <> 0 Then
'---
'---Here the new thinBasic functionality. It assign a process address to a generic previously declared function allowing subsequent calling
Declare Set ADDRESS FindFirstVolume, hProc
Declare Set ADDRESS FindNextVolume, hProc2
Declare Set ADDRESS FindVolumeClose, hProc3
'---Now we try to use the functionality
dim VolumeName As String ' will contain the current VolumeName found
Dim Display as String ' will contain the concatened string to display
dim lpszVolumeName as long ' pointer to VolumeName
lpszVolumeName = STRPTR (VolumeName) '
Dim cchBufferLength as dword
cchBufferLength = 200
'/!\02 how long ? is it arbitrary ?
dim hFindVolume as long
dim isClosedVolume as boolean
isClosedVolume = false
hFindVolume = FindFirstVolume(lpszVolumeName, cchBufferLength)
'/!\03 This has not populated `VolumeName`
Display += VolumeName & $CRLF
do while not isClosedVolume
DoEvents
if FindNextVolume(hFindVolume,lpszVolumeName,cchBufferLength) then
'/!\04 This has returned `0` (false)
Display += VolumeName & $CRLF
else
isClosedVolume = FindVolumeClose(hFindVolume)
endif
loop
MSGBOXw 0, Display
Else
MSGBOX 0, "It was not possible to get the procedure address"
End If
Else
MSGBOX 0, "It was not possible to load library"
End If
WaitKey
Method 1 may work but is inconvenient (notice the /!\ in code comments). I can't get method 2 (prefered) to work and examples/discussions found in the forum didn't bring me further than what is above. What didn't I understand about declarations or usage ?
'ThinAir 1.10.5.0 on Win 8.1 x64