News:

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

Problem with a OFNHookProc

Started by minor28, November 24, 2010, 11:47:21 AM

Previous topic - Next topic

minor28

I have a GetFileName dialog with a template and the OFNHookProc.


mov ofn.Flags,OFN_LONGNAMES or OFN_ENABLEHOOK or OFN_ENABLETEMPLATE or OFN_EXPLORER
mov ofn.lpfnHook,offset OFNHookProc
mov ofn.lpTemplateName,offset szTemplateName


The dialog opens as it should and it sends the WM_NOTIFY message to the OFNHookProc.
However the lParam seems not to be a pointer to the OFNOTIFY structure.


.if uMsg==WM_INITDIALOG
invoke GetDlgItem,hWin,IDC_TRB2
mov hTRB2,eax

mov eax,FALSE
ret
.elseif uMsg==WM_NOTIFY
mov eax,lParam
mov eax,dword ptr [eax].NMHDR.code
.if eax==CDN_INITDONE ;code=0

.elseif eax==CDN_FOLDERCHANGE ;code=2

.elseif eax==CDN_HELP ;code=4

.elseif eax==CDN_INCLUDEITEM ;code=7

.elseif eax==CDN_FILEOK ;code=5

.elseif eax==CDN_SELCHANGE ;code=1

.elseif eax==CDN_SHAREVIOLATION ;code=3

.elseif eax==CDN_TYPECHANGE ;code=6
mov eax,lParam
mov eax,dword ptr [eax].OFNOTIFY.lpOFN.OPENFILENAME.nFilterIndex
.if eax==2
invoke ShowWindow,hTRB2,SW_SHOW
.endif
.endif
mov eax,FALSE
ret


Any suggestions?

Best regards

ToutEnMasm

Quote
OFNOTIFYA   STRUCT
   hdr NMHDR <>
   lpOFN DWORD ?
   pszFile DWORD ? ; May be NULL
OFNOTIFYA      ENDS

FALSE
Quote
OFNOTIFY.lpOFN <--- cut it ------------------ OPENFILENAME.nFilterIndex

lpOFN must be a pointer on OPENFILENAME
mov eax,dword ptr [eax].OFNOTIFY.lpOFN
mov eax,dword ptr [eax].OPENFILENAME.nFilterIndex



minor28

Thanks for your answer.

Yes I know this was wrong but the main problem is that lParam not will send the notification notices. lParam seem not to point to an OFNOTIFY structure

ToutEnMasm


Verify that the WM_NOTIFY message is send to the hookproc and not to the mother window.
To verify that create a WM_NOTIFY in the mother window and filter the handle of the dialog.



minor28

yes, I have verifyed that WM_NOTIFY is sent to hookprocess.

ToutEnMasm


IT is a WM_NOTIFY but another can be send to the mother,is that you need to verify

minor28

I looked in windows.inc and this is the constants

CDN_INITDONE                     equ 0000h
CDN_SELCHANGE                    equ 0001h
CDN_FOLDERCHANGE                 equ 0002h
CDN_SHAREVIOLATION               equ 0003h
CDN_HELP                         equ 0004h
CDN_FILEOK                       equ 0005h
CDN_TYPECHANGE                   equ 0006h
CDN_INCLUDEITEM                  equ 0007h


The same in Commdlg.h is

#define CDN_FIRST   (0U-601U)
#define CDN_LAST    (0U-699U)

// Notifications when Open or Save dialog status changes
#define CDN_INITDONE            (CDN_FIRST - 0x0000)
#define CDN_SELCHANGE           (CDN_FIRST - 0x0001)
#define CDN_FOLDERCHANGE        (CDN_FIRST - 0x0002)
#define CDN_SHAREVIOLATION      (CDN_FIRST - 0x0003)
#define CDN_HELP                (CDN_FIRST - 0x0004)
#define CDN_FILEOK              (CDN_FIRST - 0x0005)
#define CDN_TYPECHANGE          (CDN_FIRST - 0x0006)
#define CDN_INCLUDEITEM         (CDN_FIRST - 0x0007)


What is 0U-601U. This could be the reson to failur.

minor28


ToutEnMasm


I have this values in the ready to use SDK
Quote
CDN_FIRST   equ   < 0 - 601>
CDN_LAST   equ   < 0 - 699>
; Notifications from Open or Save dialog
CDN_INITDONE   equ   < CDN_FIRST - 00000h>
CDN_SELCHANGE   equ   < CDN_FIRST - 00001h>
CDN_FOLDERCHANGE   equ   < CDN_FIRST - 00002h>
CDN_SHAREVIOLATION   equ   < CDN_FIRST - 00003h>
CDN_HELP   equ   < CDN_FIRST - 00004h>
CDN_FILEOK   equ   < CDN_FIRST - 00005h>
CDN_TYPECHANGE   equ   < CDN_FIRST - 00006h>
IF ( NTDDI_VERSION GE  NTDDI_WIN2K)
CDN_INCLUDEITEM   equ   < CDN_FIRST - 00007h>
ENDIF ; (NTDDI_VERSION >= NTDDI_WIN2K)
CDM_FIRST   equ   < WM_USER + 100>
CDM_LAST   equ   < WM_USER + 200>


dedndave

seems to me that you need an ASSUME, maybe PTR ???
maybe the problem is that the assembler does not know that EAX points to the base of the structure
the forum search tool may help - "assume ptr structure"

minor28

What is the ready to use SDK and how do I use these constants?

ToutEnMasm

The ready to use SDk is a translate of the WIN7 SDk made by my translator and dowloadable in the masm32 forum,windows.inc subforum.
To make a test:
Copy the values in your source:
add a A to each one to avoid redifinitions and modify your condition with the new value.
If it don't work,take care it is negative values and you need perhaps to put them in a SDWORD before used them in a condition
svalue SDWORD 0

mov eax,dword ptr [eax].NMHDR.code
mov svalue,eax
.if  svalue==ACDN_TYPECHANGE

This must be tested in case of failure

l

dedndave

.if uMsg==WM_INITDIALOG
        invoke GetDlgItem,hWin,IDC_TRB2
        mov hTRB2,eax

        mov eax,FALSE
        ret
.elseif uMsg==WM_NOTIFY
        ASSUME  eax:PTR OFNOTIFY
        mov eax,lParam
        mov eax,dword ptr [eax].NMHDR.code
        .if eax==CDN_INITDONE ;code=0

        .elseif eax==CDN_FOLDERCHANGE ;code=2

        .elseif eax==CDN_HELP ;code=4

        .elseif eax==CDN_INCLUDEITEM ;code=7

        .elseif eax==CDN_FILEOK ;code=5

        .elseif eax==CDN_SELCHANGE ;code=1

        .elseif eax==CDN_SHAREVIOLATION ;code=3

        .elseif eax==CDN_TYPECHANGE ;code=6
                mov eax,lParam
                mov eax,dword ptr [eax].lpOFN.OPENFILENAME.nFilterIndex ;note the change here
        ASSUME  eax:NOTHING
                .if eax==2
                        invoke ShowWindow,hTRB2,SW_SHOW
                .endif
        .endif
        mov eax,FALSE
        ret

minor28

Before your answer I tryed this and it did work


.elseif uMsg==WM_NOTIFY
mov ecx,lParam
mov ecx,dword ptr [ecx].NMHDR.code
mov eax,CDN_FIRST
sub eax,ecx
.if eax==CDN_INITDONE ;code=0


I will try your suggestion also

dedndave

edited previous post

i noticed here....
        mov eax,dword ptr [eax].NMHDR.code

then, here, you had....
                mov eax,dword ptr [eax].OFNOTIFY.lpOFN.OPENFILENAME.nFilterIndex
(with OFNOTIFY)

unreleated: "dword ptr" is not needed in these lines, so long as code and cnFilterIndex are dwords
moving into eax, it cannot be anything else