1. [Win32Lib] trying to wrap GetDriveType

I'm trying to wrap GetDriveType API, and don't really know what I'm doing;
here's what I tried, and the result is error: "Couldn't link to C function
'GetDriveType'"

Can someone show me how to do it right??

(Below the following code is what I found about "GetDriveType")

Dan Moyer

include win32lib.ew
integer dummy

constant xGetDriveType = registerw32Function(kernel32,"GetDriveType",
{C_POINTER},C_LONG  )

 if w32Func(xGetDriveType, "C:\\")= 2 then  -- FAILS HERE, I THINK?
      puts(1, " REMOVABLE DRIVE")
  else
      puts(1, "non removable drive")
  end if
          
dummy = wait_key()



GetDriveType Function

Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or
network drive.

To determine whether a drive is a USB-type drive, call
SetupDiGetDeviceRegistryProperty and specify the SPDRP_REMOVAL_POLICY property.


UINT WINAPI GetDriveType(
  __in_opt  LPCTSTR lpRootPathName
);

Parameters
lpRootPathName 
The root directory for the drive. 

A trailing backslash is required. If this parameter is NULL, the function uses
the root of the current directory.

Return Value
The return value specifies the type of drive, which can be one of the following
values.

Return code/value Description 
DRIVE_UNKNOWN
0
 The drive type cannot be determined.
 
DRIVE_NO_ROOT_DIR
1
The root path is invalid; for example, there is no volume is mounted at the
 path.
 
DRIVE_REMOVABLE
2
The drive has removable media; for example, a floppy drive, thumb drive, or
 flash card reader.
 
DRIVE_FIXED
3
 The drive has fixed media; for example, a hard drive or flash drive.
 
DRIVE_REMOTE
4
 The drive is a remote (network) drive.
 
DRIVE_CDROM
5
 The drive is a CD-ROM drive.
 
DRIVE_RAMDISK
6
 The drive is a RAM disk.
 

Requirements
Client Requires Windows Vista, Windows XP, or Windows 2000 Professional. 
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000
Server.
Header Declared in WinBase.h; include Windows.h.
 
Library Use Kernel32.lib.
 
DLL Requires Kernel32.dll.
 
Unicode Implemented as GetDriveTypeW (Unicode) and GetDriveTypeA (ANSI).

new topic     » topic index » view message » categorize

2. Re: [Win32Lib] trying to wrap GetDriveType

Dan Moyer wrote:
> 
> I'm trying to wrap GetDriveType API, and don't really know what I'm doing;
> here's what I tried, and the result is error: "Couldn't link to C function
> 'GetDriveType'"
> 
> Can someone show me how to do it right??
> 
> (Below the following code is what I found about "GetDriveType")
> 
> Dan Moyer
> 
> }}}
<eucode>
> 
> include win32lib.ew
> integer dummy
> 
> constant xGetDriveType = registerw32Function(kernel32,"GetDriveType",
                                                                     ^^^^

Usinge DEMO\Win32^dsearch.exw, you'd see that the API name is "GetDriveTypeA".
Add that 'A', which stands for ANSI, and everything will be fine.
On say a Middle/Far Eastern build of Windows, you'd use 'W' instead (Unicode
build of the dll).

CChris

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

3. Re: [Win32Lib] trying to wrap GetDriveType

Here's your answer right here:

> Unicode Implemented as GetDriveTypeW (Unicode) and GetDriveTypeA (ANSI).

All Win32 API functions that deal with strings use 8-bit characters (ANSI) or
16-bit characters (Unicode). Euphoria doesn't natively support Unicode (yet?) so
just use the ANSI function. You need to define it like this.

constant xGetDriveType = registerw32Function(kernel32,"GetDriveTypeA",
{C_POINTER}, C_UINT  )


(Also, the return type appears to be C_UINT, not C_LONG.)


-Greg

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

4. Re: [Win32Lib] trying to wrap GetDriveType

CChris wrote:
> 
> Dan Moyer wrote:
> > 
> > I'm trying to wrap GetDriveType API, and don't really know what I'm doing;
> > here's what I tried, and the result is error: "Couldn't link to C function
> > 'GetDriveType'"
> > 
> > Can someone show me how to do it right??
> > 
> > (Below the following code is what I found about "GetDriveType")
> > 
> > Dan Moyer
> > 
> > }}}
<eucode>
> > 
> > include win32lib.ew
> > integer dummy
> > 
> > constant xGetDriveType = registerw32Function(kernel32,"GetDriveType",
>                                                                      ^^^^
> 
> Usinge DEMO\Win32^dsearch.exw, you'd see that the API name is "GetDriveTypeA".
> Add that 'A',
> which stands for ANSI, and everything will be fine.
> On say a Middle/Far Eastern build of Windows, you'd use 'W' instead (Unicode
> build of the dll).
> 
> CChris

And Greg wrote:


>>Here's your answer right here:

> Unicode Implemented as GetDriveTypeW (Unicode) and GetDriveTypeA (ANSI).

>>All Win32 API functions that deal with strings use 8-bit characters (ANSI) or
>>16-bit characters (Unicode). Euphoria doesn't natively support Unicode (yet?)
>>so just use the ANSI function. You need to define it like this.


>>constant xGetDriveType =
>>registerw32Function(kernel32,"GetDriveTypeA",{C_POINTER}, C_UINT  )


>>(Also, the return type appears to be C_UINT, not C_LONG.)


>>-Greg

Thanks guys, that makes sense, but when I make those two corrections, I get
another error:

"w32dll.ew:212 in function w32Func() 
C routine GetDriveTypeA() needs 1 argument, not 3"

include win32lib.ew
integer dummy

constant xGetDriveType = registerw32Function(kernel32,"GetDriveTypeA",
{C_POINTER},C_UINT  )

 if w32Func(xGetDriveType, "C:\\") = 2 then
      puts(1, " REMOVABLE DRIVE")
  else
      puts(1, "non removable drive")
  end if
          
dummy = wait_key()


Dan

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

5. Re: [Win32Lib] trying to wrap GetDriveType

uh, never mind, the drive just needs to be...a sequence:  {"c:\\"}

sigh.

Thanks again guys.

Dan

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

Search



Quick Links

User menu

Not signed in.

Misc Menu