Code:
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" DECLARE FUNCTION SetVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "SetVolumeMountPointA" ( lpszVolumeMountPoint AS ASCIIZ, lpszVolumeName AS ASCIIZ ) AS DWORD DECLARE FUNCTION DeleteVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "DeleteVolumeMountPointA" ( lpszVolumeMountPoint AS ASCIIZ ) AS DWORD 'DECLARE FUNCTION GetVolumeNameForVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "GetVolumeNameForVolumeMountPointA" (lpszVolumeMountPoint AS ASCIIZ, byval lpszVolumeName AS ASCIIZ ptr, Byval cchBufferLength AS DWORD) AS LONG '---------------------------------------------------------------------- ' Function SystemErrorMessageText ' deliver a text message for a given API-error number ' in error code by GetLastError() ' out error text '---------------------------------------------------------------------- FUNCTION SystemErrorMessageText (BYVAL ECode AS LONG) AS STRING LOCAL Buffer AS ASCIIZ * 255 LOCAL sText AS STRING FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %Null, ECode, %Null, buffer, SIZEOF(buffer), BYVAL %Null sText = FORMAT$(ECode, "##### ") & Buffer FUNCTION = TRIM$( sText ) END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL Drv AS ASCIIZ * 30 LOCAL Path AS ASCIIZ * %Max_Path LOCAL buffer AS ASCIIZ * %Max_Path LOCAL lResult AS LONG LOCAL bufLen AS DWORD LOCAL lerr AS DWORD Drv = "C:\" Path= "K:\test\" buffer = STRING$(%Max_Path, " ") bufLen = SIZEOF(buffer) lResult = GetVolumeNameForVolumeMountPoint( Drv, buffer, bufLen ) lerr = GetLastError IF lResult <> 0 THEN lResult = SetVolumeMountPoint( Path, buffer ) lerr = GetLastError() IF lResult = 0 THEN MSGBOX "Buffer="+buffer+$CRLF+"SetVolumeMountPoint-Error "+SystemErrorMessageText(lerr) ELSE MSGBOX "Mount successful, look up in explorer!" MSGBOX "Dismount drive now: "+Drv lResult = DeleteVolumeMountPoint( Drv ) END IF ELSE MSGBOX "Received no volumename for mountpoint. Error:"+SystemErrorMessageText(lerr) END IF END FUNCTION
Code:
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" DECLARE FUNCTION SetVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "SetVolumeMountPointA" ( lpszVolumeMountPoint AS ASCIIZ, lpszVolumeName AS ASCIIZ ) AS DWORD DECLARE FUNCTION DeleteVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "DeleteVolumeMountPointA" ( lpszVolumeMountPoint AS ASCIIZ ) AS DWORD 'DECLARE FUNCTION GetVolumeNameForVolumeMountPoint LIB "KERNEL32.DLL" ALIAS "GetVolumeNameForVolumeMountPointA" (lpszVolumeMountPoint AS ASCIIZ, byval lpszVolumeName AS ASCIIZ ptr, Byval cchBufferLength AS DWORD) AS LONG '---------------------------------------------------------------------- ' Function SystemErrorMessageText ' deliver a text message for a given API-error number ' in error code by GetLastError() ' out error text '---------------------------------------------------------------------- FUNCTION SystemErrorMessageText (BYVAL ECode AS LONG) AS STRING LOCAL Buffer AS ASCIIZ * 255 LOCAL sText AS STRING FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %Null, ECode, %Null, buffer, SIZEOF(buffer), BYVAL %Null sText = FORMAT$(ECode, "##### ") & Buffer FUNCTION = TRIM$( sText ) END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL Drv AS ASCIIZ * 3 LOCAL Path AS ASCIIZ * 50 LOCAL lResult AS LONG LOCAL lerr AS DWORD Drv = "Y:" Path= "\DosDevices\C:\Windows" lResult = DefineDosDevice(%DDD_RAW_TARGET_PATH, Drv, Path ) lerr = GetLastError IF lResult = 0 THEN MSGBOX "DDD-error: "+SystemErrorMessageText(lerr) ELSE MSGBOX "success" lResult = DefineDosDevice( %DDD_REMOVE_DEFINITION, Drv, "") IF lResult <> 0 THEN MSGBOX "Drive "+Drv+" removed." ELSE MSGBOX "Could not remove drive "+Drv END IF END IF END FUNCTION
I will begin with this one: Developing Windows NT Device Drivers: A Programmer's Handbook (ISBN:0201695901) and with the MSDN DDK of course.
Leave a comment: