News:

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

Printing Structure Question

Started by georgek01, March 17, 2011, 05:49:47 AM

Previous topic - Next topic

georgek01

Good day,

Kindly assist me with converting these C structures to ASM. I think I may have the first two down, but the last one is above me...

C - PRINTER_NOTIFY_OPTIONS

typedef struct _PRINTER_NOTIFY_OPTIONS { 
    DWORD  Version;
    DWORD  Flags;
    DWORD  Count;
    PPRINTER_NOTIFY_OPTIONS_TYPE  pTypes;
} PRINTER_NOTIFY_OPTIONS;


ASM - PRINTER_NOTIFY_OPTIONS

PRINTER_NOTIFY_OPTIONS struct

Version dword ?
Flags dword ?
Count dword ?
pTypes PPRINTER_NOTIFY_OPTIONS_TYPE <> 

PRINTER_NOTIFY_OPTIONS EndS


MSDN says that pTypes above "Points to an array of PRINTER_NOTIFY_OPTIONS_TYPE structures." Did I define this member correctly?

C - PRINTER_NOTIFY_OPTIONS_TYPE

typedef struct _PRINTER_NOTIFY_OPTIONS_TYPE { 
    WORD   Type;
    WORD   Reserved0;
    DWORD  Reserved1;
    DWORD  Reserved2;
    DWORD  Count;
    PWORD  pFields;
} PRINTER_NOTIFY_OPTIONS_TYPE;


ASM - PRINTER_NOTIFY_OPTIONS_TYPE

PPRINTER_NOTIFY_OPTIONS_TYPE struct

pType word ?
Reserved0 word ?
Reserved1 dword ?
Reserved2 dword ?
Count dword ?
pFields dword PRINTER_NOTIFY_INFO_DATA dup(<>)

PPRINTER_NOTIFY_OPTIONS_TYPE EndS


MSDN says that pFields above "Points to a 16-bit array of values." Did I define this member correctly?

This one I'm not sure about though.

C - PRINTER_NOTIFY_INFO_DATA

typedef struct _PRINTER_NOTIFY_INFO_DATA { 
    WORD   Type;
    WORD   Field;
    DWORD  Reserved;
    DWORD  Id;
    union {
        DWORD  adwData[2];
        struct {
            DWORD  cbBuf;
            LPVOID pBuf;
        } Data;
    } NotifyData;
} PRINTER_NOTIFY_INFO_DATA;


ASM - PRINTER_NOTIFY_INFO_DATA

PRINTER_NOTIFY_INFO_DATA struct
pType word ?
Field word ?
Reserved dword ?
Id dword ?
union
awdData dword 2 dup (?)
struct
cbBuf dword ?
pBuf dword ?
ends
ends
PRINTER_NOTIFY_INFO_DATA EndS


Your assistance will be greatly appreciated!



What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

drizz

http://www.japheth.de/h2incX.html

;--- include file created by h2incx v0.99.19 (copyright 2005-2006 japheth)

PRINTER_NOTIFY_OPTIONS struct
Version DWORD ?
Flags DWORD ?
Count DWORD ?
pTypes PPRINTER_NOTIFY_OPTIONS_TYPE ?
PRINTER_NOTIFY_OPTIONS ends

PRINTER_NOTIFY_OPTIONS_TYPE struct
Type_ WORD ?
Reserved0 WORD ?
Reserved1 DWORD ?
Reserved2 DWORD ?
Count DWORD ?
pFields PWORD ?
PRINTER_NOTIFY_OPTIONS_TYPE ends

PRINTER_NOTIFY_INFO_DATA struct
Type_ WORD ?
Field WORD ?
Reserved DWORD ?
Id DWORD ?
union NotifyData
adwData DWORD 2 dup (?)
struct Data
cbBuf DWORD ?
pBuf LPVOID ?
ends
ends
PRINTER_NOTIFY_INFO_DATA ends


;--- errors: 0
;--- end of file ---
The truth cannot be learned ... it can only be recognized.

georgek01

drizz, thank you!!

My code now works fine, but how do I access the Data strcuture in PRINTER_NOTIFY_INFO_DATA?

I access the print job ID successfully, but how do I get the job name (that's in the Data array)?


mov eax,pointer

assume eax: PTR PRINTER_NOTIFY_INFO

mov ecx,[eax].aData.Id ; print job ID

invoke wsprintf,addr szBuffer,addr szNum,ecx
invoke InsertListItem,hList,addr szBuffer,0,0,0,0

assume eax:nothing

What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

drizz

My advice to you would be to stop using masm32 includes and start using win32inc.

.686
.model flat,c
option casemap:none
include WINDOWS.INC ;; www.japheth.de/WinInc.html
include WINSPOOL.INC

.code
main proc argc,argv

assume esi:PPRINTER_NOTIFY_INFO, edi:PPRINTER_NOTIFY_INFO_DATA
xor ebx,ebx
lea edi,[esi].aData; or [esi].aData[ebx*sizeof PRINTER_NOTIFY_INFO_DATA]

.while ebx < [esi].Count

; id
mov edx,[edi].Id

; buffer and length
mov ecx,[edi].NotifyData.Data.cbBuf
mov eax,[edi].NotifyData.Data.pBuf

add edi, sizeof PRINTER_NOTIFY_INFO_DATA

inc ebx
.endw
assume esi:nothing, edi:nothing
ret
main endp

end

The truth cannot be learned ... it can only be recognized.

georgek01

drizz, thank you! My printer monitor is up and running and I can now report on print jobs going through the server.

The only problem I now have is that SAP print jobs does not for some reason report on the number of pages printed. Any reason why that is?

I use the following to get the number of pages for the print jobs. All types of documents works fine except for SAP related...


.elseif field == JOB_NOTIFY_FIELD_TOTAL_PAGES

mov eax,[edi].NotifyData.adwData[0]
.if eax != 0
invoke wsprintf,addr szBuffer,addr szNum,eax
invoke InsertListSubItem,hList,addr szBuffer,item,6
invoke InsertListSubItem,hList,addr szYes,item,7
.else
mov eax,[edi].NotifyData.adwData[1]
.if eax != 0
invoke wsprintf,addr szBuffer,addr szNum,eax
invoke InsertListSubItem,hList,addr szBuffer,item,6
invoke InsertListSubItem,hList,addr szYes,item,7
.else
invoke wsprintf,addr szBuffer,addr szNum,eax
invoke InsertListSubItem,hList,addr szBuffer,item,6
invoke InsertListSubItem,hList,addr szNo,item,7
.endif
.endif
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

drizz

Always remember that square brackets in asm DO NOT have the same meaning as [] in high level languages.

[anything inside evaluates to BYTE OFFSET]

mov eax,[edi].NotifyData.adwData[1]  ; This does not access the second dword but adwData+1 BYTE OFFSET

correct (choose one):
mov eax,[edi].NotifyData.adwData[1*DWORD]
mov ecx,[edi].NotifyData.adwData[1*SIZEOF DWORD]
mov ecx,[edi].NotifyData.adwData[1*TYPE [edi].NotifyData.adwData]


That's the only error I can find...
The truth cannot be learned ... it can only be recognized.

georgek01

What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)