The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on November 08, 2011, 01:54:36 PM

Title: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 01:54:36 PM
I am getting errors with this. I read the masmguide but can't figure what I am doing wrong.



GetCdHandle PROTO :DWORD
VerifyMedia PROTO :DWORD

CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
ENDM

.const

IOCTL_STORAGE_CHECK_VERIFY  equ 002d4800h
IOCTL_STORAGE_CHECK_VERIFY2 equ 002d0800h

.data

hWnd          dd 0

.data?

hDevice     dw   ?

start:

ASSUME  FS:nothing

invoke GetCDHandle,CTEXT ("\\.\E:")
.if eax !=0

invoke VerifyMedia,hDevice

.if eax==TRUE

invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Found!")

.else
invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD Found!")
jmp @F

.endif

GetCDHandle  proc lpszDevice:DWORD
invoke CreateFile,lpszDevice,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
    .if eax != INVALID_HANDLE_VALUE
        mov  hDevice,eax
    .else
        mov eax,FALSE
    .endif     
ret
GetCDHandle endp

VerifyMedia Proc _hDevice:DWORD
LOCAL dwBytes:DWORD
invoke DeviceIoControl,_hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0,0, 0, addr dwBytes, 0
.if eax!=0
         mov eax,1
.else
         mov eax,0
      .endif
    ret
VerifyMedia endp

invoke ExitProcess,0

end start


Title: Re: Undefined symbols etc.
Post by: ToutEnMasm on November 08, 2011, 02:26:35 PM
there is a miising information :
Quote
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Microsoft (R) Macro Assembler Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: ecrase.asm
ecrase.asm(1) : error A2119:language type must be specified
ecrase.asm(11) : error A2013:.MODEL must precede this directive
ecrase.asm(16) : error A2013:.MODEL must precede this directive
ecrase.asm(18) : error A2034:must be in segment block
ecrase.asm(20) : error A2013:.MODEL must precede this directive
ecrase.asm(22) : error A2034:must be in segment block
ecrase.asm(24) : error A2034:must be in segment block
ecrase.asm(28) : error A2013:.MODEL must precede this directive
CTEXT(2): Macro Called From
  ecrase.asm(28): Main Line Code
ecrase.asm(28) : error A2034:must be in segment block
CTEXT(3): Macro Called From
  ecrase.asm(28): Main Line Code
ecrase.asm(28) : error A2013:.MODEL must precede this directive
CTEXT(4): Macro Called From
  ecrase.asm(28): Main Line Code
ecrase.asm(28) : error A2006:undefined symbol : GetCDHandle
ecrase.asm(29) : error A2034:must be in segment block
ecrase.asm(31) : error A2006:undefined symbol : hDevice
ecrase.asm(31) : error A2114:INVOKE argument type mismatch : argument : 1
ecrase.asm(31) : error A2034:must be in segment block
ecrase.asm(33) : error A2034:must be in segment block
ecrase.asm(35) : error A2013:.MODEL must precede this directive
CTEXT(2): Macro Called From
  ecrase.asm(35): Main Line Code
ecrase.asm(35) : error A2034:must be in segment block
CTEXT(3): Macro Called From
  ecrase.asm(35): Main Line Code
ecrase.asm(35) : error A2013:.MODEL must precede this directive
CTEXT(4): Macro Called From
  ecrase.asm(35): Main Line Code
ecrase.asm(35) : error A2006:undefined symbol : SetDlgItemText
ecrase.asm(37) : error A2034:must be in segment block
ecrase.asm(38) : error A2013:.MODEL must precede this directive
CTEXT(2): Macro Called From
  ecrase.asm(38): Main Line Code
ecrase.asm(38) : error A2034:must be in segment block
CTEXT(3): Macro Called From
  ecrase.asm(38): Main Line Code
ecrase.asm(38) : error A2013:.MODEL must precede this directive
CTEXT(4): Macro Called From
  ecrase.asm(38): Main Line Code
ecrase.asm(38) : error A2006:undefined symbol : SetDlgItemText
ecrase.asm(39) : error A2034:must be in segment block
ecrase.asm(41) : error A2034:must be in segment block
ecrase.asm(43) : error A2034:must be in segment block : GetCDHandle
ecrase.asm(44) : error A2006:undefined symbol : CreateFile
ecrase.asm(45) : error A2034:must be in segment block
ecrase.asm(46) : error A2034:must be in segment block
ecrase.asm(47) : error A2034:must be in segment block
ecrase.asm(48) : error A2034:must be in segment block
ecrase.asm(49) : error A2034:must be in segment block
ecrase.asm(50) : error A2034:must be in segment block
ecrase.asm(51) : fatal error A1010:unmatched block nesting : GetCDHandle

There has been an error while assembling this project.

Appuyez sur une touche pour continuer...
miss at least three lines
Quote
   .586            
   .model flat, stdcall      ;
   option casemap :none      ;   
               
Title: Re: Undefined symbols etc.
Post by: ToutEnMasm on November 08, 2011, 02:41:01 PM
Here a version without error at compile (surely not working)
Quote
   .586            ;
   .model flat, stdcall      ;
   option casemap :none      ;l ou majuscules               

VerifyMedia PROTO :DWORD

CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
ENDM
   include windows.inc      ;<<<<<<<<< include files
   include kernel32.inc
   include user32.inc

.const

IOCTL_STORAGE_CHECK_VERIFY  equ 002d4800h
IOCTL_STORAGE_CHECK_VERIFY2 equ 002d0800h
GetCDHandle proto :DWORD
VerifyMedia PROTO :DWORD        ;<<<<<<<<<<<<<<<<<<<<<
.data

hWnd          dd 0

.data?

hDevice     dd   ?              ;<<<<<<<<<<<<<<<<<< DWORD not dw
.code
start:
ASSUME  FS:nothing
invoke GetCDHandle,CTEXT ("\\.\E:")
   .if eax !=0
   invoke VerifyMedia,hDevice

      .if eax==TRUE
      invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Found!")
      .else
         invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD Found!")
         ;jmp @F
      .endif
   .endif ;<<<<<<<<<<<<<<<<<<<<<<<<< perhps here ??????????????????????????????????
   @@: ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< perhaps here ?????????????????????
   
invoke ExitProcess,0          ; <<<<<<<<< proc are always after


GetCDHandle  proc lpszDevice:DWORD
   invoke CreateFile,lpszDevice,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
    .if eax != INVALID_HANDLE_VALUE
        mov  hDevice,eax
    .else
        mov eax,FALSE
    .endif     
   ret
GetCDHandle endp

VerifyMedia Proc _hDevice:DWORD
LOCAL dwBytes:DWORD   
   invoke DeviceIoControl,_hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0,0, 0, addr dwBytes, 0
   .if eax!=0
         mov eax,1
   .else
         mov eax,0
      .endif
    ret
VerifyMedia endp


end start
Title: Re: Undefined symbols etc.
Post by: ragdog on November 08, 2011, 06:31:48 PM
Hi Magnum

This code its from me or??
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 06:41:18 PM
It might be.


.686                                     
.model flat, stdcall                     
option casemap :none                       

include \masm32\include\windows.inc   
include \masm32\include\masm32.inc     

include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\ole32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\winmm.inc
include \masm32\include\advapi32.inc

include \masm32\include\dialogs.inc   
include \masm32\macros\macros.asm     

includelib \masm32\lib\masm32.lib     

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\advapi32.inc

GetCdHandle PROTO :DWORD
VerifyMedia PROTO :DWORD

CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
ENDM

.const

IOCTL_STORAGE_CHECK_VERIFY  equ 002d4800h
IOCTL_STORAGE_CHECK_VERIFY2 equ 002d0800h

.data

hWnd          dd 0

.data?

hDevice     dw   ?

start:

ASSUME  FS:nothing

invoke GetCDHandle,CTEXT ("\\.\E:")
.if eax !=0

invoke VerifyMedia,hDevice

.if eax==TRUE

invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Found!")

.else
invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD Found!")
jmp @F

.endif

@@:

GetCDHandle  proc lpszDevice:DWORD
invoke CreateFile,lpszDevice,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
    .if eax != INVALID_HANDLE_VALUE
        mov  hDevice,eax
    .else
        mov eax,FALSE
    .endif     
ret
GetCDHandle endp

VerifyMedia Proc _hDevice:DWORD
LOCAL dwBytes:DWORD
invoke DeviceIoControl,_hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0,0, 0, addr dwBytes, 0
.if eax!=0
         mov eax,1
.else
         mov eax,0
      .endif
    ret
VerifyMedia endp

invoke ExitProcess,0

end start


Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 06:57:08 PM
GetCdHandle PROTO :DWORD
GetCDHandle  proc lpszDevice:DWORD
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:04:10 PM
hDevice     dw   ?

handles are dwords, or

hDevice HANDLE ?
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 07:05:10 PM
This works,  but needs some more refining.


start:

invoke GetDriveType,addr Drv_Path

; 0 The drive type cannot be determined.
; 1 The root directory does not exist.
; 2 DRIVE_REMOVABLE The drive can be removed from the drive.
; 3 DRIVE_FIXED The disk cannot be removed from the drive.
; 4 DRIVE_REMOTE The drive is a remote (network) drive.
; 5 DRIVE_CDROM The drive is a CD-ROM drive.
; 6 DRIVE_RAMDISK The drive is a RAM disk.

.IF (eax==5)
       
invoke  MessageBox, NULL, addr CD_Drive, addr AppName, MB_OK


.ENDIF



invoke ExitProcess,0


end start

Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:05:55 PM
.data?

hDevice     dd   ?

start:


start has to be in a .code section
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 07:07:44 PM
This is what I am getting on the other code.

I don't know what is up with GetCDHandle.  :(

Assembling: C:\masm32\SOURCE\Is_CD.asm
C:\masm32\SOURCE\Is_CD.asm(61) : error A2108:use of register assumed to ERROR
C:\masm32\SOURCE\Is_CD.asm(65) : error A2006:undefined symbol : GetCDHandle
C:\masm32\SOURCE\Is_CD.asm(106) : fatal error A1010:unmatched block nesting : .if-.repeat-.while
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:08:15 PM
you have an open .if/.endif block
invoke GetCDHandle,CTEXT ("\\.\E:")
.if eax !=0

invoke VerifyMedia,hDevice

.if eax==TRUE

invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Found!")

.else
invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD Found!")
jmp @F

.endif
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:08:57 PM
check my first post ;)
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 07:09:50 PM
Thanks Dave.

I feel like an idiot for forgetting about .code.

Down to 2 error messages.

C:\masm32\SOURCE\Is_CD.asm(67) : error A2006:undefined symbol : GetCDHandle
C:\masm32\SOURCE\Is_CD.asm(108) : fatal error A1010:unmatched block nesting : .if-.repeat-.while
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:10:26 PM
i made 4 changes and got it to assemble
all listed above
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 07:31:27 PM
It assembles.

Is this supposed to show anything on the screen ?

invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD Found!")
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:36:23 PM
well - it is not a complete program, as it is written
it references hWnd - a dialog window
but, i see no window created   :bg

to test it, you might just stick "print" in there where it uses SetDlgItemText and run it in the console
Title: Re: Undefined symbols etc.
Post by: dedndave on November 08, 2011, 07:39:40 PM
... or use MessageBox   :U
Title: Re: Undefined symbols etc.
Post by: ragdog on November 08, 2011, 07:49:48 PM
Hi magnum

This source is from me i have search my old project


GetAndCheckMedia PROTO  :HWND,:DWORD
GetCDHandle      PROTO  :DWORD
_GetDriveType    PROTO  :DWORD
GetMediaTyp      PROTO  :HWND,:DWORD
VerifyMedia      PROTO  :DWORD

CTEXT macro Text
    local szText
    .data
    szText byte Text, 0
    .code
    exitm <offset szText>   
endm

.const       

IDD_DIALOG   equ 1000
IDC_LIST          equ 1001
IDC_LISTDRIVE     equ 1002
;#########################################################################
.data
pPrevent    PREVENT_MEDIA_REMOVAL <>
cdd  CDROM_DISK_DATA <>
CDDRIVE_CDDVD db 0
.data?

hInstance   dd ?
hDevice           dd ?


.code
GetAndCheckMedia proc hWnd:HWND,pszDevice:DWORD

invoke GetCDHandle,pszDevice

.if eax !=0
invoke VerifyMedia,hDevice
.if eax==TRUE
invoke SetDlgItemText,hWnd,1003,CTEXT ("CD/DVD Found!")
.else
invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD/DVD Found!")
jmp @F
.endif

   invoke _GetDriveType,hDevice
    .if CDDRIVE_CDDVD==1
       invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Drive")

   .elseif CDDRIVE_CDDVD==2
         invoke SetDlgItemText,hWnd,1003,CTEXT ("DVD Drive")
      .else
           invoke SetDlgItemText,hWnd,1003,CTEXT ("Nothing found")
    .endif
.else
     invoke SetDlgItemText,hWnd,1003,CTEXT ("Cannot open drive ")
.endif

@@:

ret
GetAndCheckMedia endp


VerifyMedia Proc _hDevice:DWORD
LOCAL dwBytes:DWORD
invoke DeviceIoControl,_hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0,0, 0, addr dwBytes, 0
.if eax!=0
         mov eax,1
  .else
           mov eax,0
    .endif
    ret
VerifyMedia endp

_GetDriveType proc _hDevice:DWORD
LOCAL dwBytes:DWORD
LOCAL pMediaTypes[2048]:BYTE
    invoke DeviceIoControl,_hDevice,IOCTL_STORAGE_GET_MEDIA_TYPES_EX,NULL,0,addr pMediaTypes,2048,addr dwBytes,FALSE
    .if eax!=0
           lea edi,pMediaTypes
        assume edi: ptr GET_MEDIA_TYPES
        .if [edi].DeviceType==FILE_DEVICE_CD_ROM
            mov CDDRIVE_CDDVD,1
                     
        .elseif [edi].DeviceType==FILE_DEVICE_DVD
                mov CDDRIVE_CDDVD,2
        .endif
        assume edi: NOTHING
      .else
     
           mov eax,0
    .endif
    ret
_GetDriveType endp

GetCDHandle  proc lpszDevice:DWORD
invoke CreateFile,lpszDevice,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
;invoke CreateFile,lpszDevice,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0
    .if eax != INVALID_HANDLE_VALUE
        mov  hDevice,eax
      .else
        mov eax,FALSE
    .endif     
ret
GetCDHandle endp



SetDlgItemText print the text on a Dialog editcontrol  ::)

I hope it help you
Title: Re: Undefined symbols etc.
Post by: Magnum on November 08, 2011, 08:10:53 PM
Ragdog,

There are some things missing from your code.

C:\masm32\SOURCE\test.asm(62) : error A2008:syntax error : pPrevent
C:\masm32\SOURCE\test.asm(63) : error A2008:syntax error : cdd
C:\masm32\SOURCE\test.asm(122) : error A2006:undefined symbol : IOCTL_STORAGE_GET_MEDIA_TYPES
C:\masm32\SOURCE\test.asm(122) : error A2114:INVOKE argument type mismatch : argument : 2
C:\masm32\SOURCE\test.asm(126) : error A2006:undefined symbol : DeviceType
C:\masm32\SOURCE\test.asm(129) : error A2006:undefined symbol : DeviceType
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 12:54:30 AM
pPrevent    PREVENT_MEDIA_REMOVAL <>
cdd  CDROM_DISK_DATA <>


windows.inc is missing the PREVENT_MEDIA_REMOVAL and CDROM_DISK_DATA structure definitions
you'll have to add them (google finds them for you)

same with IOCTL_STORAGE_GET_MEDIA_TYPES, but it's an EQUate - looks like it's 2D0C00h

windows.inc is missing the GET_MEDIA_TYPES structure definition
LOCAL pMediaTypes[2048]:BYTE
    invoke DeviceIoControl,_hDevice,IOCTL_STORAGE_GET_MEDIA_TYPES_EX,NULL,0,addr pMediaTypes,2048,addr dwBytes,FALSE
    .if eax!=0
           lea edi,pMediaTypes
        assume edi: ptr GET_MEDIA_TYPES
        .if [edi].DeviceType==FILE_DEVICE_CD_ROM


pMediaTypes must be an array of GET_MEDIA_TYPES structures - not sure
at any rate, DeviceType is a member of the GET_MEDIA_TYPES structure
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 01:22:12 AM
ok - i found most of it
no luck with CDROM_DISK_DATA - might be ragdog's own structure definition
you should be able to leave that line out, as i do not see it referenced in the code   :P

the rest, i found in Japheth's WinInc include files

CTL_CODE macro DeviceType,Function,Method,Access
exitm <(((DeviceType) shl 16) or ((Access) shl 14) or ((Function) shl 2) or (Method))>
endm

FILE_DEVICE_MASS_STORAGE EQU 0000002dh
IOCTL_STORAGE_BASE       EQU <FILE_DEVICE_MASS_STORAGE>
METHOD_BUFFERED          EQU 0
FILE_ANY_ACCESS          EQU 0

IOCTL_STORAGE_GET_MEDIA_TYPES EQU <CTL_CODE(IOCTL_STORAGE_BASE,300h,METHOD_BUFFERED,FILE_ANY_ACCESS)>

PREVENT_MEDIA_REMOVAL struct
  PreventMediaRemoval   BOOLEAN ?
PREVENT_MEDIA_REMOVAL ends

STORAGE_MEDIA_TYPE typedef DWORD
STORAGE_BUS_TYPE typedef DWORD

DEVICE_MEDIA_INFO struct
union DeviceSpecific
struct DiskInfo
Cylinders LARGE_INTEGER <>
MediaType STORAGE_MEDIA_TYPE ?
TracksPerCylinder DWORD ?
SectorsPerTrack DWORD ?
BytesPerSector DWORD ?
NumberMediaSides DWORD ?
MediaCharacteristics DWORD ?
ends
struct RemovableDiskInfo
Cylinders LARGE_INTEGER <>
MediaType STORAGE_MEDIA_TYPE ?
TracksPerCylinder DWORD ?
SectorsPerTrack DWORD ?
BytesPerSector DWORD ?
NumberMediaSides DWORD ?
MediaCharacteristics DWORD ?
ends
struct TapeInfo
MediaType STORAGE_MEDIA_TYPE ?
MediaCharacteristics DWORD ?
CurrentBlockSize DWORD ?
BusType STORAGE_BUS_TYPE ?
union BusSpecificData
struct ScsiInformation
MediumType BYTE ?
DensityCode BYTE ?
ends
ends
ends
ends
DEVICE_MEDIA_INFO ends

GET_MEDIA_TYPES    struct
DeviceType    DWORD    ?
MediaInfoCount    DWORD    ?
MediaInfo    DEVICE_MEDIA_INFO 1 dup (<>)
GET_MEDIA_TYPES    ends
Title: Re: Undefined symbols etc.
Post by: Magnum on November 09, 2011, 01:49:14 AM
Down to one error using the code below.

C:\masm32\SOURCE\Check_If_CD.asm(56) : error A2008:syntax error : MediaInfo

If I want to add the structures to windows.inc, do I just add them to the end of file ?



; Check_If_CD.asm
;
.686                                     
.model flat, stdcall                     
option casemap :none                       

include \masm32\include\windows.inc   
include \masm32\include\masm32.inc     

include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\ole32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\winmm.inc
include \masm32\include\advapi32.inc

include \masm32\include\dialogs.inc   
include \masm32\macros\macros.asm     

includelib \masm32\lib\masm32.lib     

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\advapi32.lib

PREVENT_MEDIA_REMOVAL struct
  PreventMediaRemoval   BOOLEAN ?
PREVENT_MEDIA_REMOVAL ends

GET_MEDIA_TYPES    struct
DeviceType    DWORD    ?
MediaInfoCount    DWORD    ?
MediaInfo    DEVICE_MEDIA_INFO 1 dup (<>)
GET_MEDIA_TYPES    ends

GetAndCheckMedia PROTO  :HWND,:DWORD
GetCDHandle      PROTO  :DWORD
_GetDriveType    PROTO  :DWORD
GetMediaTyp      PROTO  :HWND,:DWORD
VerifyMedia      PROTO  :DWORD

CTEXT macro Text
    local szText
    .data
    szText byte Text, 0
    .code
    exitm <offset szText>   
endm

.const       

IDD_DIALOG                equ 1000
IDC_LIST                         equ 1001
IDC_LISTDRIVE                    equ 1002
IOCTL_STORAGE_CHECK_VERIFY       equ 002d4800h
IOCTL_STORAGE_CHECK_VERIFY2      equ 002d0800h
IOCTL_STORAGE_GET_MEDIA_TYPES_EX equ 2D0C00h

.data

pPrevent      PREVENT_MEDIA_REMOVAL <>
;cdd           CDROM_DISK_DATA       <>

CDDRIVE_CDDVD db                    0

.data?

hInstance   dd ?
hDevice             dd ?


.code

start:

GetAndCheckMedia proc hWnd:HWND,pszDevice:DWORD

invoke GetCDHandle,pszDevice

.if eax !=0
invoke VerifyMedia,hDevice
.if eax==TRUE
invoke SetDlgItemText,hWnd,1003,CTEXT ("CD/DVD Found!")
.else
invoke SetDlgItemText,hWnd,1003,CTEXT ("No CD/DVD Found!")
jmp @F
.endif

   invoke _GetDriveType,hDevice
    .if CDDRIVE_CDDVD==1
       invoke SetDlgItemText,hWnd,1003,CTEXT ("CD Drive")

   .elseif CDDRIVE_CDDVD==2
         invoke SetDlgItemText,hWnd,1003,CTEXT ("DVD Drive")
      .else
           invoke SetDlgItemText,hWnd,1003,CTEXT ("Nothing found")
    .endif
.else
     invoke SetDlgItemText,hWnd,1003,CTEXT ("Cannot open drive ")
.endif

@@:

ret
GetAndCheckMedia endp


VerifyMedia Proc _hDevice:DWORD
LOCAL dwBytes:DWORD
invoke DeviceIoControl,_hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0,0, 0, addr dwBytes, 0
.if eax!=0
         mov eax,1
  .else
           mov eax,0
    .endif
    ret
VerifyMedia endp

_GetDriveType proc _hDevice:DWORD
LOCAL dwBytes:DWORD
LOCAL pMediaTypes[2048]:BYTE
    invoke DeviceIoControl,_hDevice,IOCTL_STORAGE_GET_MEDIA_TYPES_EX,NULL,0,addr pMediaTypes,2048,addr dwBytes,FALSE
    .if eax!=0
           lea edi,pMediaTypes
        assume edi: ptr GET_MEDIA_TYPES
        .if [edi].DeviceType==FILE_DEVICE_CD_ROM ; ERROR
            mov CDDRIVE_CDDVD,1
                     
        .elseif [edi].DeviceType==FILE_DEVICE_DVD ; ERROR
                mov CDDRIVE_CDDVD,2
        .endif
        assume edi: NOTHING
      .else
     
           mov eax,0
    .endif
    ret
_GetDriveType endp

GetCDHandle  proc lpszDevice:DWORD
invoke CreateFile,lpszDevice,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
;invoke CreateFile,lpszDevice,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0
    .if eax != INVALID_HANDLE_VALUE
        mov  hDevice,eax
      .else
        mov eax,FALSE
    .endif     
ret
GetCDHandle endp

end start
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 02:03:38 AM
i would not add them to windows.inc
if you do, you will lose compatibility with the other forum members
instead, i would add them to the project include file
each one like this....
IFNDEF  FILE_DEVICE_MASS_STORAGE
FILE_DEVICE_MASS_STORAGE EQU 0000002dh
ENDIF


doing it that way, you maintain compatibility
and, if the masm32 package update defines the symbols, the program should still assemble correctly with no changes
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 02:06:58 AM
MediaInfo is defined as a member of GET_MEDIA_TYPES
it is the name of a DEVICE_MEDIA_INFO structure (union)
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 02:10:33 AM
these are all required   :P
STORAGE_MEDIA_TYPE typedef DWORD
STORAGE_BUS_TYPE typedef DWORD

DEVICE_MEDIA_INFO struct
union DeviceSpecific
struct DiskInfo
Cylinders LARGE_INTEGER <>
MediaType STORAGE_MEDIA_TYPE ?
TracksPerCylinder DWORD ?
SectorsPerTrack DWORD ?
BytesPerSector DWORD ?
NumberMediaSides DWORD ?
MediaCharacteristics DWORD ?
ends
struct RemovableDiskInfo
Cylinders LARGE_INTEGER <>
MediaType STORAGE_MEDIA_TYPE ?
TracksPerCylinder DWORD ?
SectorsPerTrack DWORD ?
BytesPerSector DWORD ?
NumberMediaSides DWORD ?
MediaCharacteristics DWORD ?
ends
struct TapeInfo
MediaType STORAGE_MEDIA_TYPE ?
MediaCharacteristics DWORD ?
CurrentBlockSize DWORD ?
BusType STORAGE_BUS_TYPE ?
union BusSpecificData
struct ScsiInformation
MediumType BYTE ?
DensityCode BYTE ?
ends
ends
ends
ends
DEVICE_MEDIA_INFO ends

GET_MEDIA_TYPES    struct
DeviceType    DWORD    ?
MediaInfoCount    DWORD    ?
MediaInfo    DEVICE_MEDIA_INFO 1 dup (<>)
GET_MEDIA_TYPES    ends
Title: Re: Undefined symbols etc.
Post by: Magnum on November 09, 2011, 02:25:36 AM
Dave,

Thanks for all your help.

It produces an .exe but when run it activates Ollydbg.

I will take a break.

I have a new posting on another subject.

Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 02:49:01 AM
ok, Andy
i may play with it some more tomorrow
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 03:23:56 PM
well - i got it to work, such as it is   :P

it identifies the drive type - not the media
i.e., if you have a CD in a DVD drive, it identifies it as a DVD

if you need to identify the media, let me know - i think i can figure out how to do it

there are a number of ways to improve on it
for example, you could make a single DeviceIOCtl PROC and pass the function
Title: Re: Undefined symbols etc.
Post by: Magnum on November 09, 2011, 03:35:31 PM
My CD drive is F.

I changed the source, but it reports "No CD/DVD Found"



Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 03:40:56 PM
did you put a CD in it - one that has some files ?
i may have messed up with the messages   :P
check my work
Title: Re: Undefined symbols etc.
Post by: Magnum on November 09, 2011, 03:44:04 PM
It worked with a CD in.

I will check your work.

Thanks.
Title: Re: Undefined symbols etc.
Post by: dedndave on November 09, 2011, 04:09:29 PM
yah - that's how it is written
if the media is not present, it does not check the drive type

i was thinking of writing a function that returns
EAX = drive status (i.e. valid/invalid drive letter)
ECX = media type/status
EDX = drive type

a lot depends on what you want to do with it
if you give me specific info about what you are trying to accomplish, we can make it do what you like
Title: Re: Undefined symbols etc.
Post by: Magnum on November 09, 2011, 04:55:53 PM
I use a batch file to backup files to various drives.

I run into problems when it tries to copy to a CD drive.

That is the reason for the program.

Title: Re: Undefined symbols etc.
Post by: ragdog on November 09, 2011, 07:04:37 PM
GET_MEDIA_TYPES is this

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363264%28v=vs.85%29.aspx


typedef struct _GET_MEDIA_TYPES {
  DWORD             DeviceType;
  DWORD             MediaInfoCount;
  DEVICE_MEDIA_INFO MediaInfo[1];
} GET_MEDIA_TYPES, *PGET_MEDIA_TYPES;


GET_MEDIA_TYPES struct
DeviceType DWORD ?
MediaInfoCount DWORD ?
MediaInfo DEVICE_MEDIA_INFO 1 dup (<>)
GET_MEDIA_TYPES ends

PGET_MEDIA_TYPES typedef ptr GET_MEDIA_TYPES



i have convert all used structur´s what i use in my code from Msdn or sdk  to masm32

But i cannot send my complete project this is not open source sorry
I can only post source snipped from it.

Sorry