The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Neil on January 12, 2009, 12:14:26 PM

Title: Get current drive number
Post by: Neil on January 12, 2009, 12:14:26 PM
Anyone know an API that returns the current hard drive number, the equivalent of the DOS function :-
                                                                          mov ah,19
                                                                          int 21
Title: Re: Get current drive number
Post by: MichaelW on January 12, 2009, 12:51:49 PM
You can get the current drive and directory for the current process with GetCurrentDirectory. I can find no references to a system-wide current drive or directory.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetCurrentDirectory, 0, 0
    mov ebx, eax
    mov edi, halloc(ebx)
    invoke GetCurrentDirectory, ebx, edi
    print edi,13,10
    hfree edi
    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

Title: Re: Get current drive number
Post by: jj2007 on January 12, 2009, 03:19:21 PM
From a DOS prompt, there is a current directory for each drive. This seems not to work with GetCurrentDirectory. Any ideas how to simulate this?

include \masm32\include\Masm32rt.inc

MyGetCurDir PROTO: DWORD

.data?
buffer db MAX_PATH dup(?)

.code
DirBuffer$ dd buffer

txC db "C:", 0
txC_Win db "C:\Windows", 0

txD db "D:", 0
txD_Masm db "D:\Masm32", 0

start:
invoke SetCurrentDirectory, addr txC_Win ; set C:\Windows
.if eax
invoke MyGetCurDir, 0
print DirBuffer$, 13,10
.else
print chr$("SetDir failed miserably", 13, 10)
.endif

invoke SetCurrentDirectory, addr txD_Masm ; set D:\Masm32
.if eax
invoke MyGetCurDir, 0
print DirBuffer$, 13,10
.else
print chr$("SetDir failed miserably", 13, 10)
.endif


invoke SetCurrentDirectory, addr txC ; set C:
.if eax
invoke MyGetCurDir, 0
print DirBuffer$, 13,10
.else
print chr$("SetDir failed miserably", 13, 10)
.endif

invoke SetCurrentDirectory, addr txD ; set D:
.if eax
invoke MyGetCurDir, 0
print DirBuffer$, 13,10
.else
print chr$("SetDir failed miserably", 13, 10)
.endif

getkey
exit

MyGetCurDir proc MbFlag:DWORD
    invoke GetCurrentDirectory, MAX_PATH, DirBuffer$
    ret
MyGetCurDir endp

end start
Title: Re: Get current drive number
Post by: Neil on January 12, 2009, 03:22:21 PM
Thanks Michael,
That's actually better than in DOS, saves using a lookup or xlat table to get the actual drive letter  :U