News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Undefined symbols etc.

Started by Magnum, November 08, 2011, 01:54:36 PM

Previous topic - Next topic

dedndave

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

dedndave


ragdog

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

Magnum

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
Have a great day,
                         Andy

dedndave

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

dedndave

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

Magnum

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
Have a great day,
                         Andy

dedndave

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

dedndave

MediaInfo is defined as a member of GET_MEDIA_TYPES
it is the name of a DEVICE_MEDIA_INFO structure (union)

dedndave

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

Magnum

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.

Have a great day,
                         Andy

dedndave

ok, Andy
i may play with it some more tomorrow

dedndave

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

Magnum

My CD drive is F.

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



Have a great day,
                         Andy

dedndave

did you put a CD in it - one that has some files ?
i may have messed up with the messages   :P
check my work