1. Wrapping GetVolumeInfo: help required

Hi,

this is my first serious attempt to wrap an API call, namely GetVolumeInfo. I
get error code 24 which, if i'm right, means

ERROR_BAD_LENGTH: The program issued a command but the command length is
incorrect.

Can someone tell me what's wrong?

Henri Goffin

------<code starts here. Thanks to Al Getz for the 'getdrive.exw' inspiration
>---------------
include dll.e
include msgbox.e
include print.e
include get.e
include tk_mem.e

without warning
with trace
global atom	hKernel32_dll
			,GetLastError
			,hGetVolumeInfo
			,lpRootPathName
			,lpVolumeNameBuffer
			,nVolumeNameSize
			,lpVolumeSerialNumber
			,lpMaximumComponentLength
			,lpFileSystemFlags
			,lpFileSystemNameBuffer
			,nFileSystemNameSize
			,char
			,jk

sequence vol_name
atom mbretv, rc

hKernel32_dll=open_dll("kernel32.dll")

if hKernel32_dll=0 then
mbretv=message_box( "could not locate
    Kernel32.dll","GetVolumeInfo.exw",MB_ICONHAND+MB_TASKMODAL )
    abort(1)
end if

hGetVolumeInfo=
    define_c_func(hKernel32_dll, "GetVolumeInformationA", 
{C_POINTER, C_POINTER, C_DOUBLE, C_POINTER, C_POINTER, C_POINTER, C_POINTER,
    C_DOUBLE}, C_INT)
if hGetVolumeInfo<0 then
mbretv=message_box( "could not link to c function"& "\n" &
    "GetVolumeInformationA in Kernel32.dll","GetDrives.exw",MB_ICONHAND+MB_TASKMODAL)
    abort(1)
end if
GetLastError = define_c_func( hKernel32_dll, "GetLastError", {}, C_INT )
lpRootPathName = allocate_string("C:\\")
nVolumeNameSize = 24
lpVolumeNameBuffer = allocate_string(repeat(' ',nVolumeNameSize))
lpVolumeSerialNumber = allocate(8)
lpMaximumComponentLength = allocate(8)
lpFileSystemFlags = allocate(8)
nFileSystemNameSize = 16
lpFileSystemNameBuffer = allocate_string(repeat(' ',nFileSystemNameSize))

rc = c_func(hGetVolumeInfo,{	 
						lpRootPathName
						,lpVolumeNameBuffer
						,nVolumeNameSize
						,lpVolumeSerialNumber
						,lpMaximumComponentLength
						,lpFileSystemFlags
						,lpFileSystemNameBuffer
						,nFileSystemNameSize
						})
rc = c_func(GetLastError,{})
print(1,rc)
vol_name = peek_string(lpFileSystemNameBuffer)
puts(1,vol_name & '\n')
jk = wait_key()

-----<code ends here>---------

new topic     » topic index » view message » categorize

2. Re: Wrapping GetVolumeInfo: help required

You do this:
      allocate_string(repeat(' ',nVolumeNameSize))

I do this:
      lpVolumeNameBuffer = allocate(nVolumeNameSize)
      mem_set(lpVolumeNameBuffer,0,nVolumeNameSize)

Anyone care to share why I like typeing?

Euman
euman at bellsouth.net

----- Original Message -----
From: <Henri.Goffin at sbs.be>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, October 12, 2001 06:34
Subject: Wrapping GetVolumeInfo: help required


>
> Hi,
>
> this is my first serious attempt to wrap an API call, namely GetVolumeInfo. I
> get error code 24 which, if i'm right, means
>
> ERROR_BAD_LENGTH: The program issued a command but the command length is
> incorrect.
>
> Can someone tell me what's wrong?
>
> Henri Goffin
>
> ------<code starts here. Thanks to Al Getz for the 'getdrive.exw' inspiration
> >---------------
> include dll.e
> include msgbox.e
> include print.e
> include get.e
> include tk_mem.e
>
> without warning
> with trace
> global atom hKernel32_dll
> ,GetLastError
> ,hGetVolumeInfo
> ,lpRootPathName
> ,lpVolumeNameBuffer
> ,nVolumeNameSize
> ,lpVolumeSerialNumber
> ,lpMaximumComponentLength
> ,lpFileSystemFlags
> ,lpFileSystemNameBuffer
> ,nFileSystemNameSize
> ,char
> ,jk
>
> sequence vol_name
> atom mbretv, rc
>
> hKernel32_dll=open_dll("kernel32.dll")
>
> if hKernel32_dll=0 then
>     mbretv=message_box( "could not locate
>     Kernel32.dll","GetVolumeInfo.exw",MB_ICONHAND+MB_TASKMODAL )
>     abort(1)
> end if
>
> hGetVolumeInfo=
>     define_c_func(hKernel32_dll, "GetVolumeInformationA",
>     {C_POINTER, C_POINTER, C_DOUBLE, C_POINTER, C_POINTER, C_POINTER,
>     C_POINTER, C_DOUBLE}, C_INT)
> if hGetVolumeInfo<0 then
>     mbretv=message_box( "could not link to c function"& "\n" &
>     "GetVolumeInformationA in
Kernel32.dll","GetDrives.exw",MB_ICONHAND+MB_TASKMODAL)
>     abort(1)
> end if
> GetLastError = define_c_func( hKernel32_dll, "GetLastError", {}, C_INT )
> lpRootPathName = allocate_string("C:\\")
> nVolumeNameSize = 24
> lpVolumeNameBuffer = allocate_string(repeat(' ',nVolumeNameSize))
> lpVolumeSerialNumber = allocate(8)
> lpMaximumComponentLength = allocate(8)
> lpFileSystemFlags = allocate(8)
> nFileSystemNameSize = 16
> lpFileSystemNameBuffer = allocate_string(repeat(' ',nFileSystemNameSize))
>
> rc = c_func(hGetVolumeInfo,{
> lpRootPathName
> ,lpVolumeNameBuffer
> ,nVolumeNameSize
> ,lpVolumeSerialNumber
> ,lpMaximumComponentLength
> ,lpFileSystemFlags
> ,lpFileSystemNameBuffer
> ,nFileSystemNameSize
> })
> rc = c_func(GetLastError,{})
> print(1,rc)
> vol_name = peek_string(lpFileSystemNameBuffer)
> puts(1,vol_name & '\n')
> jk = wait_key()
>
> -----<code ends here>---------
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Wrapping GetVolumeInfo: help required

OOPs, guess I messed up some on that last one

+ 1
 
 You do this:
       allocate_string(repeat(' ',nVolumeNameSize))
 
 I do this:
       lpVolumeNameBuffer = allocate(nVolumeNameSize+1)
       mem_set(lpVolumeNameBuffer,0,nVolumeNameSize+1)
 
and the extension to the whole thing and the conclusion:

vol_name  = peek({lpVolumeNameBuffer,nVolumeNameSize})
free(lpVolumeNameBuffer)
 
 Euman
 euman at bellsouth.net

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu