The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: minor28 on November 24, 2010, 11:47:21 AM

Title: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 11:47:21 AM
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
Title: Re: Problem with a OFNHookProc
Post by: ToutEnMasm on November 24, 2010, 01:25:31 PM
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


Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 01:32:45 PM
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
Title: Re: Problem with a OFNHookProc
Post by: ToutEnMasm on November 24, 2010, 01:58:53 PM

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.


Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 02:06:59 PM
yes, I have verifyed that WM_NOTIFY is sent to hookprocess.
Title: Re: Problem with a OFNHookProc
Post by: ToutEnMasm on November 24, 2010, 02:17:42 PM

IT is a WM_NOTIFY but another can be send to the mother,is that you need to verify
Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 02:19:27 PM
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.
Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 02:20:42 PM
Nothing is sent to the mother.
Title: Re: Problem with a OFNHookProc
Post by: ToutEnMasm on November 24, 2010, 02:24:01 PM

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>

Title: Re: Problem with a OFNHookProc
Post by: dedndave on November 24, 2010, 02:31:07 PM
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"
Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 02:37:59 PM
What is the ready to use SDK and how do I use these constants?
Title: Re: Problem with a OFNHookProc
Post by: ToutEnMasm on November 24, 2010, 02:51:48 PM
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
Title: Re: Problem with a OFNHookProc
Post by: dedndave on November 24, 2010, 02:52:53 PM
.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
Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 02:54:23 PM
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
Title: Re: Problem with a OFNHookProc
Post by: dedndave on November 24, 2010, 02:55:46 PM
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
Title: Re: Problem with a OFNHookProc
Post by: minor28 on November 24, 2010, 03:06:23 PM
dedndave, your suggestion didn't work.

ToutEnMasm, your suggestion did work with sdword ptr eax.

Thank you both for your help
Title: Re: Problem with a OFNHookProc
Post by: donkey on November 24, 2010, 04:07:36 PM
The issue in Windows.inc with the CDN_xxx values has been brought up before:

http://www.masm32.com/board/index.php?topic=10497.msg76918#msg76918

I could have an old version of the includes (I don't use them much) so it may well be that the equates have already been fixed but they are still incorrect in my version.

Edgar