Hello!
New in this assambler world, and i'm having some troubles callling the printer dialog. i'm making tests calling it from a button in a simple window, i have added the comdlg32.inc and lib, it solved me some troubles and it compiles fine, but when i execute it, the button does nothing.
This is the code i'm using, i apreciate any clue please.


.Const

.Data?

.Data

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

Local pd:PRINTDLG
.If uMsg == WM_CREATE

.ElseIf uMsg == WM_COMMAND

LoWord wParam
.If Eax == IDC_WINDOW1_PRNT
HiWord wParam
.ElseIf Ax == BN_CLICKED
Invoke PrintDlgEx, Addr pd ; here is the problem!!!!!

;Mov Ax, pd.nToPage
            ;Movzx Ecx, Ax
            ;Invoke dw2a, Ecx, Addr buffer1

.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE

Window1Procedure EndP




by the way, im working win easy code.

thanks
Posted on 2010-01-15 00:46:19 by smurillo9
smurillo9,

Without proper pd initialization (correct pd.lStructSize, for example) PrintDlgEx() probably fails (E_INVALIDARG status?).
Posted on 2010-01-15 14:35:49 by baldr
thanks baldr, i`ll chek and let you know...
Posted on 2010-01-18 14:29:24 by smurillo9
Hello again!
Well checking in some examples (Genesys text editor from the examples), I found what you told, so here is the new code, but it still doesn't work, like the other program, it compiles and executes fine, but my button does nothing  :mad:

.Const

.Data?
hInstance DD ?

.Data
cnt DD 0

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

Local pd:PRINTDLG
.If uMsg == WM_CREATE

.ElseIf uMsg == WM_COMMAND

LoWord wParam
.If Eax == IDC_WINDOW1_PRNT
HiWord wParam
.ElseIf Ax == BN_CLICKED

Mov cnt, 0
        Mov pd.lStructSize, SizeOf pd
        Mov Eax, hWnd
        Mov pd.hwndOwner, Eax
        Mov Eax, hInstance
        Mov pd.hInstance, Eax
        Mov pd.Flags, PD_RETURNDC

Invoke PrintDlg, Addr pd
Mov Ax, pd.nToPage

        Mov Eax, pd.Flags
        Mov Ebx, Eax
        And Ebx, 000000FFH

       

.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE

Window1Procedure EndP



but the button in that code doesn't work either...

thanks for your help
Posted on 2010-01-18 17:13:27 by smurillo9
smurillo9,

OK, you've initialized 4 members of pd How about the rest?

For example, non-NULL hDevMode should be valid handle for GlobalAlloc'd moveable memory that contains DEVMODE structure, the same for hDevNames/DEVNAMES; certain OS will fail if nFromPage is not in range [nMinPagenMaxPage] and so on. Check the Win32 reference.

Good practice is to zero-fill the structure beforehand (most members accept 0 as default/don't care value). It is allocated on stack and contains garbage.
Posted on 2010-01-18 17:52:17 by baldr
hello!

i check for some examples and th only members of the struct initialized are trhe ones i post in this version, compilation and execution runs, but the dialog doesn't apear. iv'e included comctl32, comdlg32 kernel32 shell32 and user32 libs and incs...

other thing is that hDC, HWND flags and struct size don't need to be initialized, but hinstance, an the other uncommented throw errors if they are not!
:sad:

again, thanks for the help you coud give!

.Const

.Data?
hInstance DD ?
hREd HWND ? ; Handle

;lStructSize DWord ?
;hwndOwner HWND ?
hDevMode HGLOBAL ?
hDevNames HGLOBAL ?
;hDC HDC ?
;Flags DWord ?
nFromPage Word ?
nToPage Word ?
nMinPage Word ?
nMaxPage Word ?
nCopies Word ?

;lCustData LPARAM ?

;lpfnPrintHook LPPRINTHOOKPROC ?
;lpfnSetupHook LPSETUPHOOKPROC ?

;lpPrintTemplateName LPCTSTR ?
;lpSetupTemplateName LPCTSTR ?
;hPrintTemplate HANDLE ?
;hSetupTemplate HANDLE ?

cr CHARRANGE <?> ;Character range

.Data
cnt DD 0
Sel DD  0  ; Flags a 'Range' type print job, currently unused

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

Local pd:PRINTDLG
.If uMsg == WM_CREATE

.ElseIf uMsg == WM_COMMAND

LoWord wParam
.If Eax == IDC_WINDOW1_PRNT
HiWord wParam
.ElseIf Ax == BN_CLICKED

Mov cnt, 0
Mov Eax, 0
        Mov pd.lStructSize, SizeOf pd


;-----------------------------------------------------
; inicializa miembros del struct

        Mov Eax, hWnd
        Mov pd.hwndOwner, Eax

        ;Mov Eax, hInstance
        Mov pd.hInstance, 0
        ;Mov Eax, hDevMode
        Mov pd.hDevMode, NULL
        Mov pd.hDevNames, NULL
        Mov pd.hDC, NULL
        ;Mov Eax, hDevNames

        ;Mov Ax, nCopies
        ;Mov pd.nCopies, Ax
        ;Mov Ax, nFromPage
        ;Mov pd.nFromPage, Ax
        ;Mov Ax, nMinPage
        Mov pd.nMinPage, 1
        ;Mov Ax, nMaxPage
        Mov pd.nMaxPage, 100
        Mov pd.lpPrintTemplateName, NULL

;-----------------------------------------------------
        Mov pd.Flags, PD_RETURNDC

Invoke PrintDlg, Addr pd
;Mov Ax, pd.nToPage

;Cmp Eax, FALSE
        ;Je PrtRet
        Mov Eax, pd.Flags
        Mov Ebx, Eax
        And Ebx, 000000FFH
        ;Mov Sel, Ebx
       
;PrtRet:
.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE

Window1Procedure EndP



Posted on 2010-01-19 00:50:10 by smurillo9
smurillo9,

I've successfully compiled and run the following code:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE WINDOWS.INC
INCLUDE KERNEL32.INC
ZeroMemory EQU RtlZeroMemory
INCLUDE COMDLG32.INC
INCLUDELIB KERNEL32.LIB
INCLUDELIB COMDLG32.LIB

.DATA?
pd PRINTDLG <>

.CODE
ShowPrintDlg:
INVOKE ZeroMemory, ADDR pd, SIZEOF pd; just to be sure
mov pd.lStructSize, SIZEOF pd
INVOKE GetModuleHandle, NULL
mov pd.hInstance, eax
mov pd.hwndOwner, HWND_DESKTOP
mov pd.Flags, PD_RETURNDC
INVOKE PrintDlg, ADDR pd
ret

END ShowPrintDlg


It shows print dialog, though I didn't check any of the return values. Probably you should run your code under debugger and check that it behaves correctly (if you attach something compilable, I'll check that myself).
Posted on 2010-01-19 07:58:58 by baldr
all codes i've posted are compilable, they are implemented in easy code. the GUI is a simple button named prnt and when is clicked it calls printproc where i initialize the strct and call printdlg

.Const

.Data?
hInstance DD ?
hREd HWND ? ; Handle

;lStructSize DWord ?
hwndOwner HWND ?
hDevMode HGLOBAL ?
hDevNames HGLOBAL ?
;hDC HDC ?
;Flags DWord ?
;nFromPage Word ?
;nToPage Word ?
;nMinPage Word ?
;nMaxPage Word ?
nCopies Word ?

;lCustData LPARAM ?

;lpfnPrintHook LPPRINTHOOKPROC ?
;lpfnSetupHook LPSETUPHOOKPROC ?

;lpPrintTemplateName LPCTSTR ?
;lpSetupTemplateName LPCTSTR ?
;hPrintTemplate HANDLE ?
;hSetupTemplate HANDLE ?

.Data

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

.If uMsg == WM_CREATE

.ElseIf uMsg == WM_COMMAND

LoWord wParam
.If Eax == IDC_WINDOW1_PRNT
HiWord wParam
.ElseIf Ax == BN_CLICKED

Call printProc

.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE

Window1Procedure EndP

printProc Proc hWnd:HWND
Local pd:PRINTDLG

;Mov cnt, 0
;Mov Eax, 0
;-----------------------------------------------------
; inicializa miembros del struct

Mov pd.lStructSize, SizeOf pd
Invoke GetModuleHandle, NULL

Mov Eax, hWnd
Mov pd.hInstance, Eax
Mov pd.hwndOwner, HWND_DESKTOP
Mov pd.Flags, PD_RETURNDC ;Or PD_COLLATE
Mov pd.hDevMode, NULL
Mov pd.hDevNames, NULL
Mov pd.hDC, NULL
; Mov pd.nMinPage, 1
; Mov pd.nMaxPage, 100
Mov pd.lpPrintTemplateName, NULL

Invoke PrintDlgA, Addr pd

;-----------------------------------------------------

Ret
printProc EndP




the problem is that the code compiles fine and when i click on execute the window appears, but the button doesn't invoke the print dialog
Posted on 2010-01-19 19:16:18 by smurillo9
smurillo9,

Something compilable to .Exe, that's what I meant. Your samples definitely lack initialization (entry point and such things as CreateWindow() call).

I was focused on PrintDlg() behavior and overlooked this:

.ElseIf uMsg == WM_COMMAND

LoWord wParam
.If Eax == IDC_WINDOW1_PRNT
HiWord wParam
.ElseIf Ax == BN_CLICKED

Call printProc

.EndIf


This reads as "call printProc if uMsg==WM_COMMAND and LoWord(wParam)==BN_CLICKED" (that is, notification from control with id==0 (BN_CLICKED)). Indentation is ignored by MASM, .ElseIf is an alternate branch of previous .If (not a nested .If within it).
Posted on 2010-01-20 00:37:44 by baldr
good news at last, it seems that the printdgl was the problem, but i implemented the invoke with the printdialog and using the 3 parameters instead the lonely addr pd, and it worked fine!

Thanks for your help  :P

Posted on 2010-01-20 12:03:13 by smurillo9
For example, non-NULL hDevMode should be valid handle for GlobalAlloc'd moveable memory that contains DEVMODE structure, the same for hDevNames/DEVNAMES;
Interesting, just checked MSDN - it's slightly vague, just mentioning "movable global memory"... when that's expected, it usually explicitly mentions GlobalAlloc(). Good catch :)
Posted on 2010-01-20 18:10:55 by f0dder