flat assembler
Message board for the users of flat assembler.

Index > Windows > [EXAMPLE] IFileDialog, IFileOpenDialog, and IFileSaveDialog

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 23 Mar 2012, 13:11
Has anyone tried to use those? MSDN says they replace FileOpenDialog in Vista/7.

I found an example on C, but being inexperienced in calling to COM functions, unable to translate to fasm. Here's some reading:

Excuse me, if I'm asking the obvious stuff. Also, I used search and didn't find any relevant information.


Last edited by bzdashek on 01 Jul 2012, 12:31; edited 1 time in total
Post 23 Mar 2012, 13:11
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 23 Mar 2012, 13:12
Post 23 Mar 2012, 13:12
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 23 Mar 2012, 18:19
EDIT: I took 2 days to learn about M$ COM and I got the whole thing down.

I also tried some examples in FASM and they work. You just need the CLSID_ and IID_ GUIDs and initialize them. OLE32 will do the magic and load the appropriate library for you. It's easy , really !

You can look for the GUIDs on MSDN although some are actually stored in the registry only (There's a special function that retrieves them). Alternatively if you do not have Visual Studio or Windows SDK files you can download this tool that'll let you browser all the COM Interfaces on your machine and their GUIDs.

http://www.microsoft.com/download/en/details.aspx?id=7007

I'll post some of the examples in FASM later on.
Post 23 Mar 2012, 18:19
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 25 Apr 2012, 19:25
Oh, thanks a lot, typedef! I'm sorry I just have noticed your answer.

I also studied the source code during this period of time. Almost everything is clear. I can't understand what is happening in the last line of the fragment:
Code:

        IFileDialogEvents *pfde = NULL;
        hr = CDialogEventHandler_CreateInstance(IID_PPV_ARGS(&pfde));
    


Been searching for "CDialogEventHandler_CreateInstance", but found no clear explanation. One guy just rewrote the whole thing.

I mean it's not hard to guess that it assigns an event handler, but how to implement this thing on fasm is unclear.

Do you have any ideas?
Post 25 Apr 2012, 19:25
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 25 Apr 2012, 19:40
I have this code so far:
Code:


; Template for program using standard Win32 headers

format PE GUI 6.0
entry start
include 'win32a.inc'
include 'ccom.inc'

FOS_OVERWRITEPROMPT = 2
FOS_STRICTFILETYPES = 4
FOS_NOCHANGEDIR = 8
FOS_PICKFOLDERS = $20
FOS_FORCEFILESYSTEM = $40
FOS_ALLNONSTORAGEITEMS = $80
FOS_NOVALIDATE = $100
FOS_ALLOWMULTISELECT = $200
FOS_PATHMUSTEXIST = $800
FOS_FILEMUSTEXIST = $1000
FOS_CREATEPROMPT = $2000
FOS_SHAREAWARE = $4000
FOS_NOREADONLYRETURN = $8000
FOS_NOTESTFILECREATE = $10000
FOS_HIDEMRUPLACES = $20000
FOS_HIDEPINNEDPLACES = $40000
FOS_NODEREFERENCELINKS = $100000
FOS_DONTADDTORECENT = $2000000
FOS_FORCESHOWHIDDEN = $10000000
FOS_DEFAULTNOMINIMODE = $20000000
FOS_FORCEPREVIEWPANEON = $40000000


;IID_IFileSaveDialog GUID $84bccd23,$5fde,$4cdb,<$ae,$a4,$af,$64,$b8,$3d,$78,$ab>
interface IFileSaveDialog,\
     QueryInterface,\
   AddRef,\
   Release,\
          Show,\
     SetFileTypes,\
     SetFileTypeIndex,\
         GetFileTypeIndex,\
         Advise,\
   Unadvise,\
         SetOptions,\
       GetOptions,\
       SetDefaultFolder,\
         SetFolder,\
        GetFolder,\
        GetCurrentSelection,\
      SetFileName,\
      GetFileName,\
      SetTitle,\
         SetOkButtonLabel,\
         SetFileNameLabel,\
         GetResult,\
        AddPlace,\
         SetDefaultExtension,\
      Close,\
    SetClientGuid,\
    ClearClientData,\
          SetFilter,\
        SetSaveAsItem,\
    SetProperties,\
    SetCollectedProperties,\
   GetProperties,\
    ApplyProperties


;IID_IFileOpenDialog GUID $d57c7288,$d4ad,$4768,<$be,2,$9d,$96,$95,$32,$d9,$60>
interface IFileOpenDialog,\
    QueryInterface,\
   AddRef,\
   Release,\
          Show,\
     SetFileTypes,\
     SetFileTypeIndex,\
         GetFileTypeIndex,\
         Advise,\
   Unadvise,\
         SetOptions,\
       GetOptions,\
       SetDefaultFolder,\
         SetFolder,\
        GetFolder,\
        GetCurrentSelection,\
      SetFileName,\
      GetFileName,\
      SetTitle,\
         SetOkButtonLabel,\
         SetFileNameLabel,\
         GetResult,\
        AddPlace,\
         SetDefaultExtension,\
      Close,\
    SetClientGuid,\
    ClearClientData,\
          SetFilter,\
        GetResults,\
       GetSelectedItems

;IID_IFileDialogEvents GUID $973510db,$7d7f,$452b,<$89,$75,$74,$a8,$58,$28,$d3,$54>
interface IFileDialogEvents,\
         QueryInterface,\
   AddRef,\
   Release,\
          OnFileOk,\
         OnFolderChanging,\
         OnFolderChange,\
   OnSelectionChange,\
        OnShareViolation,\
         OnTypeChange,\
     OnOverwrite

;IID_IShellItem GUID $43826d1e,$e718,$42ee,<$bc,$55,$a1,$e2,$61,$c3,$7b,$fe>
interface IShellItem,\
    QueryInterface,\
   AddRef,\
   Release,\
          BindToHandler,\
    GetParent,\
        GetDisplayName,\
   GetAttributes,\
    Compare

section '.text' code readable executable

  start:

 invoke  GetModuleHandle,0
   mov     [wc.hInstance],eax
  invoke  LoadIcon,0,IDI_APPLICATION
  mov     [wc.hIcon],eax
      invoke  LoadCursor,0,IDC_ARROW
      mov     [wc.hCursor],eax
    invoke  RegisterClass,wc
    test    eax,eax
     jz      error

   invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
      test    eax,eax
     jz      error
       mov     [hwnd],eax
  msg_loop:
       invoke  GetMessage,msg,NULL,0,0
     cmp     eax,1
       jb      end_loop
    jne     msg_loop
    invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
 jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:

   invoke  ExitProcess,[msg.wParam]

proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
   cmp     [wmsg],WM_COMMAND
   je      .wmcommand
  cmp     [wmsg],WM_CREATE
    je      .wmcreate
   cmp     [wmsg],WM_DESTROY
   je      .wmdestroy
  .defwndproc:
    invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
       jmp     .finish
  .wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + IDC_OPENDLG
    je      .OPENDLG
    jmp     .finish
    .OPENDLG:
        call    BasicFileOpen
       jmp     .finish
  .wmcreate:
 invoke  CreateWindowEx,0,_classb,_OpenFileDlg,WS_VISIBLE+WS_CHILD+ BS_PUSHBUTTON+WS_TABSTOP,20,20,120,30,[hwnd],IDC_OPENDLG,[wc.hInstance],0
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
   xor     eax,eax
  .finish:
   ret
endp

proc BasicFileOpen
       invoke  CoInitialize,NULL
   cmp     eax,S_OK
    jne     .error
      invoke  CoCreateInstance,CLSID_FileOpenDialog,NULL,CLSCTX_INPROC_SERVER,IID_IFileOpenDialog,FileOpenDialog
  cmp     eax,S_OK
    jne     .error
      cmp     [FileOpenDialog],0
  jz      .error

  ;invoke FileOpenDialog,QueryInterface,

  cominvk FileOpenDialog,GetOptions,dwFlags
   cmp     eax,S_OK
    jne     .error

  or      [dwFlags],FOS_FORCEFILESYSTEM

   cominvk FileOpenDialog,SetOptions,[dwFlags]
 cmp     eax,S_OK
    jne     .error

  cominvk FileOpenDialog, SetFileTypes,c_size,c_rgSaveTypes
   cmp     eax,S_OK
    jne     .error
      
    invoke  MessageBox,[hwnd],_OpenFileDlg,0,MB_OK

  cominvk FileOpenDialog,Release
      jmp     .finish
  .error:
    invoke  MessageBox,[hwnd],_cmerr,0,MB_ICONHAND+MB_OK
  .finish:
      ret
endp
 

section '.data' data readable writeable

IDC_OPENDLG    = 1001

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0
  _cmerr TCHAR 'COM Invoke failed.',0

  _classb TCHAR   'BUTTON',0
  _OpenFileDlg  TCHAR   'iFileOpenDialog',0

  CLSID_FileOpenDialog GUID DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7
  CLSID_FileSaveDialog GUID C0B4E2F3-BA21-4773-8DBA-335EC946EB8B

  IID_IFileSaveDialog GUID 84bccd23-5fde-4cdb-aea4-af64b83d78ab
  IID_IFileOpenDialog GUID d57c7288-d4ad-4768-be02-9d969532d960
  IID_IFileDialogEvents GUID 973510db-7d7f-452b-8975-74a85828d354
  IID_IShellItem GUID 43826d1e-e718-42ee-bc55-a1e261c37bfe

  FileSaveDialog IFileSaveDialog
  FileOpenDialog IFileOpenDialog
  FileDialogEvents IFileDialogEvents
  ShellItem IShellItem

; CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090
; IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090

; ShellTaskBar ITaskBarList

;const COMDLG_FILTERSPEC c_rgSaveTypes[] =
;{
;    {L"Word Document (*.doc)",       L"*.doc"},
;    {L"Web Page (*.htm; *.html)",    L"*.htm;*.html"},
;    {L"Text Document (*.txt)",       L"*.txt"},
;    {L"All Documents (*.*)",         L"*.*"}
;};

  c_rgSaveTypes        dd _st1,_st2    
  c_size    = 2
   _st1          db 'Word Document (*.doc)',0
   _st2               db '*.doc',0
;#define ARRAYSIZE(a) \
;  ((sizeof(a) / sizeof(*(a))) / \
;  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
;#endif



  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

  hwnd              dd ?
  dwFlags       dd ?


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
       user32,'USER32.DLL',\
    ole,'OLE32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'

  import ole,\
   CoInitialize,'CoInitialize',\
    CoCreateInstance,'CoCreateInstance'
    


And it crashes on setting file types
source code ref:
Code:
                        hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
    


I can't figure out what ARRAYSIZE macro returns.

CCOM.INC:
Code:
struc GUID def
 {
   match d1-d2-d3-d4-d5, def
    \{
      .Data1 dd 0x\#d1
      .Data2 dw 0x\#d2
      .Data3 dw 0x\#d3
      .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh
      .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh
    \}
 }

CLSCTX_INPROC_SERVER      = 0x1
CLSCTX_INPROC_HANDLER          = 0x2
CLSCTX_LOCAL_SERVER            = 0x4
CLSCTX_INPROC_SERVER16         = 0x8
CLSCTX_REMOTE_SERVER           = 0x10
CLSCTX_INPROC_HANDLER16     = 0x20
CLSCTX_INPROC_SERVERX86     = 0x40
CLSCTX_INPROC_HANDLERX86    = 0x80
CLSCTX_ESERVER_HANDLER      = 0x100
CLSCTX_NO_CODE_DOWNLOAD     = 0x400
CLSCTX_NO_CUSTOM_MARSHAL    = 0x1000
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000
CLSCTX_NO_FAILURE_LOG         = 0x4000
CLSCTX_DISABLE_AAA          = 0x8000
CLSCTX_ENABLE_AAA           = 0x10000
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000

S_OK = 0
S_FALSE = 1
    
Post 25 Apr 2012, 19:40
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 01 Jul 2012, 12:09
Thanks to hopcode I was able to finish this example and make it work.

Now we have an example of IFileOpenDialog:
Code:


; Template for program using standard Win32 headers

format PE GUI 6.0
entry start
include 'win32w.inc'
include 'ccom.inc'

FOS_OVERWRITEPROMPT = 2
FOS_STRICTFILETYPES = 4
FOS_NOCHANGEDIR = 8
FOS_PICKFOLDERS = $20
FOS_FORCEFILESYSTEM = $40
FOS_ALLNONSTORAGEITEMS = $80
FOS_NOVALIDATE = $100
FOS_ALLOWMULTISELECT = $200
FOS_PATHMUSTEXIST = $800
FOS_FILEMUSTEXIST = $1000
FOS_CREATEPROMPT = $2000
FOS_SHAREAWARE = $4000
FOS_NOREADONLYRETURN = $8000
FOS_NOTESTFILECREATE = $10000
FOS_HIDEMRUPLACES = $20000
FOS_HIDEPINNEDPLACES = $40000
FOS_NODEREFERENCELINKS = $100000
FOS_DONTADDTORECENT = $2000000
FOS_FORCESHOWHIDDEN = $10000000
FOS_DEFAULTNOMINIMODE = $20000000
FOS_FORCEPREVIEWPANEON = $40000000

SIGDN_NORMALDISPLAY = 0
SIGDN_PARENTRELATIVEPARSING = $80018001
SIGDN_DESKTOPABSOLUTEPARSING = $80028000
SIGDN_PARENTRELATIVEEDITING = $80031001
SIGDN_DESKTOPABSOLUTEEDITING = $8004c000
SIGDN_FILESYSPATH = $80058000
SIGDN_URL = $80068000
SIGDN_PARENTRELATIVEFORADDRESSBAR = $8007c001
SIGDN_PARENTRELATIVE = $80080001



;IID_IFileSaveDialog GUID $84bccd23,$5fde,$4cdb,<$ae,$a4,$af,$64,$b8,$3d,$78,$ab>
interface IFileSaveDialog,\
          QueryInterface,\
          AddRef,\
          Release,\
          Show,\
          SetFileTypes,\
          SetFileTypeIndex,\
          GetFileTypeIndex,\
          Advise,\
          Unadvise,\
          SetOptions,\
          GetOptions,\
          SetDefaultFolder,\
          SetFolder,\
          GetFolder,\
          GetCurrentSelection,\
          SetFileName,\
          GetFileName,\
          SetTitle,\
          SetOkButtonLabel,\
          SetFileNameLabel,\
          GetResult,\
          AddPlace,\
          SetDefaultExtension,\
          Close,\
          SetClientGuid,\
          ClearClientData,\
          SetFilter,\
          SetSaveAsItem,\
          SetProperties,\
          SetCollectedProperties,\
          GetProperties,\
          ApplyProperties


;IID_IFileOpenDialog GUID $d57c7288,$d4ad,$4768,<$be,2,$9d,$96,$95,$32,$d9,$60>
interface IFileOpenDialog,\
          QueryInterface,\
          AddRef,\
          Release,\
          Show,\
          SetFileTypes,\
          SetFileTypeIndex,\
          GetFileTypeIndex,\
          Advise,\
          Unadvise,\
          SetOptions,\
          GetOptions,\
          SetDefaultFolder,\
          SetFolder,\
          GetFolder,\
          GetCurrentSelection,\
          SetFileName,\
          GetFileName,\
          SetTitle,\
          SetOkButtonLabel,\
          SetFileNameLabel,\
          GetResult,\
          AddPlace,\
          SetDefaultExtension,\
          Close,\
          SetClientGuid,\
          ClearClientData,\
          SetFilter,\
          GetResults,\
          GetSelectedItems

;IID_IFileDialogEvents GUID $973510db,$7d7f,$452b,<$89,$75,$74,$a8,$58,$28,$d3,$54>
interface IFileDialogEvents,\
          QueryInterface,\
          AddRef,\
          Release,\
          OnFileOk,\
          OnFolderChanging,\
          OnFolderChange,\
          OnSelectionChange,\
          OnShareViolation,\
          OnTypeChange,\
          OnOverwrite

;IID_IShellItem GUID $43826d1e,$e718,$42ee,<$bc,$55,$a1,$e2,$61,$c3,$7b,$fe>
interface IShellItem,\
          QueryInterface,\
          AddRef,\
          Release,\
          BindToHandler,\
          GetParent,\
          GetDisplayName,\
          GetAttributes,\
          Compare

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error
        mov     [hwnd],eax
  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:

        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
        cmp     [wmsg],WM_COMMAND
        je      .wmcommand
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + IDC_OPENDLG
        je      .OPENDLG
        jmp     .finish
    .OPENDLG:
        call    BasicFileOpen
        jmp     .finish
  .wmcreate:
        invoke  CreateWindowEx,0,_classb,_OpenFileDlg,WS_VISIBLE+WS_CHILD+ BS_PUSHBUTTON+WS_TABSTOP,20,20,120,30,[hwnd],IDC_OPENDLG,[wc.hInstance],0
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
endp

proc BasicFileOpen
        invoke  CoInitialize,NULL
        cmp     eax,S_OK
        jne     .error
        invoke  CoCreateInstance,CLSID_FileOpenDialog,NULL,CLSCTX_INPROC_SERVER,IID_IFileOpenDialog,FileOpenDialog
        cmp     eax,S_OK
        jne     .error
        cmp     [FileOpenDialog],0
        jz      .error

        ;invoke  FileOpenDialog,QueryInterface,

        cominvk FileOpenDialog,GetOptions,dwFlags
        cmp     eax,S_OK
        jne     .error

        or      [dwFlags],FOS_FORCEFILESYSTEM

        cominvk FileOpenDialog,SetOptions,[dwFlags]
        cmp     eax,S_OK
        jne     .error

        cominvk FileOpenDialog, SetFileTypes,c_size,c_rgSaveTypes
        cmp     eax,S_OK
        jne     .error

        cominvk FileOpenDialog,Show,[hwnd]

        cominvk FileOpenDialog,GetResult,ShellItem
        cmp     eax,S_OK
        jne     .error

        cominvk ShellItem,GetDisplayName,SIGDN_FILESYSPATH,fname
        
        invoke  MessageBox,[hwnd],[fname],0,MB_OK


        cominvk FileOpenDialog,Release
        cominvk ShellItem,Release
        jmp     .finish
  .error:
        invoke  MessageBox,[hwnd],_cmerr,0,MB_ICONHAND+MB_OK
  .finish:
        ret
endp
        

section '.data' data readable writeable

  CLSID_FileOpenDialog GUID DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7
  CLSID_FileSaveDialog GUID C0B4E2F3-BA21-4773-8DBA-335EC946EB8B

  IID_IFileSaveDialog GUID 84bccd23-5fde-4cdb-aea4-af64b83d78ab
  IID_IFileOpenDialog GUID d57c7288-d4ad-4768-be02-9d969532d960
  IID_IFileDialogEvents GUID 973510db-7d7f-452b-8975-74a85828d354
  IID_IShellItem GUID 43826d1e-e718-42ee-bc55-a1e261c37bfe

  FileSaveDialog IFileSaveDialog
  FileOpenDialog IFileOpenDialog
  FileDialogEvents IFileDialogEvents
  ShellItem IShellItem


IDC_OPENDLG     = 1001

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0
  _cmerr TCHAR 'COM Invoke failed.',0

  _classb       TCHAR   'BUTTON',0
  _OpenFileDlg  TCHAR   'iFileOpenDialog',0

  fname dd      ?


; CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090
; IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090

; ShellTaskBar ITaskBarList

;const COMDLG_FILTERSPEC c_rgSaveTypes[] =
;{
;    {L"Word Document (*.doc)",       L"*.doc"},
;    {L"Web Page (*.htm; *.html)",    L"*.htm;*.html"},
;    {L"Text Document (*.txt)",       L"*.txt"},
;    {L"All Documents (*.*)",         L"*.*"}
;};

  c_rgSaveTypes dd _st1,_st2    
  c_size        = 1
   _st1         TCHAR 'Word Document (*.doc)',0
   _st2         TCHAR '*.doc',0
;#define ARRAYSIZE(a) \
;  ((sizeof(a) / sizeof(*(a))) / \
;  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
;#endif



  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

  hwnd          dd ?
  dwFlags       dd ?


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          ole,'OLE32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'

  import ole,\
         CoInitialize,'CoInitialize',\
         CoCreateInstance,'CoCreateInstance'

    


Last edited by bzdashek on 01 Jul 2012, 12:31; edited 1 time in total
Post 01 Jul 2012, 12:09
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 01 Jul 2012, 12:11
CCOM.INC:
Code:

struc GUID def
 {
   match d1-d2-d3-d4-d5, def
    \{
      .Data1 dd 0x\#d1
      .Data2 dw 0x\#d2
      .Data3 dw 0x\#d3
      .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh
      .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh
    \}
 }

CLSCTX_INPROC_SERVER           = 0x1
CLSCTX_INPROC_HANDLER          = 0x2
CLSCTX_LOCAL_SERVER            = 0x4
CLSCTX_INPROC_SERVER16         = 0x8
CLSCTX_REMOTE_SERVER           = 0x10
CLSCTX_INPROC_HANDLER16     = 0x20
CLSCTX_INPROC_SERVERX86     = 0x40
CLSCTX_INPROC_HANDLERX86    = 0x80
CLSCTX_ESERVER_HANDLER      = 0x100
CLSCTX_NO_CODE_DOWNLOAD     = 0x400
CLSCTX_NO_CUSTOM_MARSHAL    = 0x1000
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000
CLSCTX_NO_FAILURE_LOG         = 0x4000
CLSCTX_DISABLE_AAA          = 0x8000
CLSCTX_ENABLE_AAA           = 0x10000
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000

S_OK = 0
S_FALSE = 1
    
Post 01 Jul 2012, 12:11
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 15 Oct 2012, 02:01
Thanks to bzdashek, typedef, & hopcode for this posting!

It is just what I needed. I wanted to set the starting target folder to look into. It was not easy, but I stumbled on a way to do it.

Code:
  invoke  SHCreateItemFromParsingName, c_def_folder, NULL, IID_IShellItem, ShellItem

      cominvk FileOpenDialog, SetFolder, [ShellItem]
      cmp     eax, S_OK 
  jne     .error 

 cominvk FileOpenDialog, Show, NULL
    


c_def_folder is a unicode string denoting the path to start the dialog from.

My thanks again,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 15 Oct 2012, 02:01
View user's profile Send private message Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg 19 Oct 2012, 20:00
I started learning about COM, but I got into trouble, which needs to be resolved in order to know if I made a mistake, or the windows documentation(better be me).

Where is the Show method documented by Microsoft? For example this line:
Code:
cominvk FileOpenDialog,Show,[hwnd]    

Where did you get the information that that method even exists? It is not mentioned in these places:

IFileDialog
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775966(v=vs.85).aspx

IFileOpenDialog
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx

IFileSaveDialog
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775688(v=vs.85).aspx

If it exists, in the future how can I know where to look for other methods?
Post 19 Oct 2012, 20:00
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 20 Oct 2012, 06:51
rohagymeg,

In the .data section of the asm file you will see:

FileOpenDialog IFileOpenDialog

If you search MSDN or your local SDK docs for IFileOpenDialog , you will find all the members of this interface. Including Show

Ask more questions if you need help.

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 20 Oct 2012, 06:51
View user's profile Send private message Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg 20 Oct 2012, 11:00
Can you just give me a link? If those 3 I posted aren't the ones you're talking about, can you be more specific about which link you were talking about?

I mean you personally, where did you find this information?

EDIT: I found it! The Show method belongs to IModalWindow.

Thanks for the help, I need to read thoroughly Smile
If I have more questions, I'll ask it in this post, but first I'll get into read only mode Smile
Post 20 Oct 2012, 11:00
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 20 Oct 2012, 11:16
Hey, rohagymeg.

Seems to me that Show method is inherited from IModalWindow interface:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
Post 20 Oct 2012, 11:16
View user's profile Send private message Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg 20 Oct 2012, 12:37
I found it myself, but thanks anyway! The problem was that I didn't know about inheritance, and only looked at the methods that are OWNED by IFileDialog interface.
Post 20 Oct 2012, 12:37
View user's profile Send private message Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek 20 Oct 2012, 17:01
rohagymeg wrote:
I found it myself, but thanks anyway! The problem was that I didn't know about inheritance, and only looked at the methods that are OWNED by IFileDialog interface.

Yeah,I noticed that you updated your message only after replying Smile You're welcome!
Post 20 Oct 2012, 17:01
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_ 21 Dec 2012, 19:23
This code compiles but does not run for me. I am on an older XP 32 bit operating system any ideas why? I did have to make the CCOM.INC file and placed in the INCLUDES folder but does it matter where you install the fasmw17003 working folder? When I try to run the exe file I get not a valid win32 program see pic at bottom.

Code:
; Template for program using standard Win32 headers

format PE GUI 6.0
entry start
include 'win32w.inc'
include 'ccom.inc'

FOS_OVERWRITEPROMPT = 2
FOS_STRICTFILETYPES = 4
FOS_NOCHANGEDIR = 8
FOS_PICKFOLDERS = $20
FOS_FORCEFILESYSTEM = $40
FOS_ALLNONSTORAGEITEMS = $80
FOS_NOVALIDATE = $100
FOS_ALLOWMULTISELECT = $200
FOS_PATHMUSTEXIST = $800
FOS_FILEMUSTEXIST = $1000
FOS_CREATEPROMPT = $2000
FOS_SHAREAWARE = $4000
FOS_NOREADONLYRETURN = $8000
FOS_NOTESTFILECREATE = $10000
FOS_HIDEMRUPLACES = $20000
FOS_HIDEPINNEDPLACES = $40000
FOS_NODEREFERENCELINKS = $100000
FOS_DONTADDTORECENT = $2000000
FOS_FORCESHOWHIDDEN = $10000000
FOS_DEFAULTNOMINIMODE = $20000000
FOS_FORCEPREVIEWPANEON = $40000000

SIGDN_NORMALDISPLAY = 0
SIGDN_PARENTRELATIVEPARSING = $80018001
SIGDN_DESKTOPABSOLUTEPARSING = $80028000
SIGDN_PARENTRELATIVEEDITING = $80031001
SIGDN_DESKTOPABSOLUTEEDITING = $8004c000
SIGDN_FILESYSPATH = $80058000
SIGDN_URL = $80068000
SIGDN_PARENTRELATIVEFORADDRESSBAR = $8007c001
SIGDN_PARENTRELATIVE = $80080001



;IID_IFileSaveDialog GUID $84bccd23,$5fde,$4cdb,<$ae,$a4,$af,$64,$b8,$3d,$78,$ab>
interface IFileSaveDialog,\
          QueryInterface,\
          AddRef,\
          Release,\
          Show,\
          SetFileTypes,\
          SetFileTypeIndex,\
          GetFileTypeIndex,\
          Advise,\
          Unadvise,\
          SetOptions,\
          GetOptions,\
          SetDefaultFolder,\
          SetFolder,\
          GetFolder,\
          GetCurrentSelection,\
          SetFileName,\
          GetFileName,\
          SetTitle,\
          SetOkButtonLabel,\
          SetFileNameLabel,\
          GetResult,\
          AddPlace,\
          SetDefaultExtension,\
          Close,\
          SetClientGuid,\
          ClearClientData,\
          SetFilter,\
          SetSaveAsItem,\
          SetProperties,\
          SetCollectedProperties,\
          GetProperties,\
          ApplyProperties


;IID_IFileOpenDialog GUID $d57c7288,$d4ad,$4768,<$be,2,$9d,$96,$95,$32,$d9,$60>
interface IFileOpenDialog,\
          QueryInterface,\
          AddRef,\
          Release,\
          Show,\
          SetFileTypes,\
          SetFileTypeIndex,\
          GetFileTypeIndex,\
          Advise,\
          Unadvise,\
          SetOptions,\
          GetOptions,\
          SetDefaultFolder,\
          SetFolder,\
          GetFolder,\
          GetCurrentSelection,\
          SetFileName,\
          GetFileName,\
          SetTitle,\
          SetOkButtonLabel,\
          SetFileNameLabel,\
          GetResult,\
          AddPlace,\
          SetDefaultExtension,\
          Close,\
          SetClientGuid,\
          ClearClientData,\
          SetFilter,\
          GetResults,\
          GetSelectedItems

;IID_IFileDialogEvents GUID $973510db,$7d7f,$452b,<$89,$75,$74,$a8,$58,$28,$d3,$54>
interface IFileDialogEvents,\
          QueryInterface,\
          AddRef,\
          Release,\
          OnFileOk,\
          OnFolderChanging,\
          OnFolderChange,\
          OnSelectionChange,\
          OnShareViolation,\
          OnTypeChange,\
          OnOverwrite

;IID_IShellItem GUID $43826d1e,$e718,$42ee,<$bc,$55,$a1,$e2,$61,$c3,$7b,$fe>
interface IShellItem,\
          QueryInterface,\
          AddRef,\
          Release,\
          BindToHandler,\
          GetParent,\
          GetDisplayName,\
          GetAttributes,\
          Compare

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error
        mov     [hwnd],eax
  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:

        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
        cmp     [wmsg],WM_COMMAND
        je      .wmcommand
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + IDC_OPENDLG
        je      .OPENDLG
        jmp     .finish
    .OPENDLG:
        call    BasicFileOpen
        jmp     .finish
  .wmcreate:
        invoke  CreateWindowEx,0,_classb,_OpenFileDlg,WS_VISIBLE+WS_CHILD+ BS_PUSHBUTTON+WS_TABSTOP,20,20,120,30,[hwnd],IDC_OPENDLG,[wc.hInstance],0
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
endp

proc BasicFileOpen
        invoke  CoInitialize,NULL
        cmp     eax,S_OK
        jne     .error
        invoke  CoCreateInstance,CLSID_FileOpenDialog,NULL,CLSCTX_INPROC_SERVER,IID_IFileOpenDialog,FileOpenDialog
        cmp     eax,S_OK
        jne     .error
        cmp     [FileOpenDialog],0
        jz      .error

        ;invoke  FileOpenDialog,QueryInterface,

        cominvk FileOpenDialog,GetOptions,dwFlags
        cmp     eax,S_OK
        jne     .error

        or      [dwFlags],FOS_FORCEFILESYSTEM

        cominvk FileOpenDialog,SetOptions,[dwFlags]
        cmp     eax,S_OK
        jne     .error

        cominvk FileOpenDialog, SetFileTypes,c_size,c_rgSaveTypes
        cmp     eax,S_OK
        jne     .error

        cominvk FileOpenDialog,Show,[hwnd]

        cominvk FileOpenDialog,GetResult,ShellItem
        cmp     eax,S_OK
        jne     .error

        cominvk ShellItem,GetDisplayName,SIGDN_FILESYSPATH,fname
        
        invoke  MessageBox,[hwnd],[fname],0,MB_OK


        cominvk FileOpenDialog,Release
        cominvk ShellItem,Release
        jmp     .finish
  .error:
        invoke  MessageBox,[hwnd],_cmerr,0,MB_ICONHAND+MB_OK
  .finish:
        ret
endp
        

section '.data' data readable writeable

  CLSID_FileOpenDialog GUID DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7
  CLSID_FileSaveDialog GUID C0B4E2F3-BA21-4773-8DBA-335EC946EB8B

  IID_IFileSaveDialog GUID 84bccd23-5fde-4cdb-aea4-af64b83d78ab
  IID_IFileOpenDialog GUID d57c7288-d4ad-4768-be02-9d969532d960
  IID_IFileDialogEvents GUID 973510db-7d7f-452b-8975-74a85828d354
  IID_IShellItem GUID 43826d1e-e718-42ee-bc55-a1e261c37bfe

  FileSaveDialog IFileSaveDialog
  FileOpenDialog IFileOpenDialog
  FileDialogEvents IFileDialogEvents
  ShellItem IShellItem


IDC_OPENDLG     = 1001

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0
  _cmerr TCHAR 'COM Invoke failed.',0

  _classb       TCHAR   'BUTTON',0
  _OpenFileDlg  TCHAR   'iFileOpenDialog',0

  fname dd      ?


; CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090
; IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090

; ShellTaskBar ITaskBarList

;const COMDLG_FILTERSPEC c_rgSaveTypes[] =
;{
;    {L"Word Document (*.doc)",       L"*.doc"},
;    {L"Web Page (*.htm; *.html)",    L"*.htm;*.html"},
;    {L"Text Document (*.txt)",       L"*.txt"},
;    {L"All Documents (*.*)",         L"*.*"}
;};

  c_rgSaveTypes dd _st1,_st2    
  c_size        = 1
   _st1         TCHAR 'Word Document (*.doc)',0
   _st2         TCHAR '*.doc',0
;#define ARRAYSIZE(a) \
;  ((sizeof(a) / sizeof(*(a))) / \
;  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
;#endif



  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

  hwnd          dd ?
  dwFlags       dd ?


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          ole,'OLE32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'

  import ole,\
         CoInitialize,'CoInitialize',\
         CoCreateInstance,'CoCreateInstance'
                                                             
    


Description:
Filesize: 68.02 KB
Viewed: 19971 Time(s)

notvalid.PNG


Post 21 Dec 2012, 19:23
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 21 Dec 2012, 19:53
Possibly the "format PE GUI 6.0" I think XP was 5 Question
Post 21 Dec 2012, 19:53
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_ 21 Dec 2012, 20:28
Thanks its better but I have another small issue now; Any ideas on this one?


Description:
Filesize: 26.87 KB
Viewed: 19961 Time(s)

com failed.PNG


Post 21 Dec 2012, 20:28
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 21 Dec 2012, 20:55
_Rob_,

It works in Win7 Home Basic. One caveat is that COM is already initialized, so CoInitialize() returns S_FALSE, but that's OK.
Post 21 Dec 2012, 20:55
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_ 21 Dec 2012, 23:36
Thanks, but at this point I don't really know much at all with the assembly language; so I am just looking at source code and trying to learn as I go.
Post 21 Dec 2012, 23:36
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 22 Dec 2012, 00:41
_Rob_,

Try to comment out cmp/jne after invoke CoInitialize, that probably will allow to run program as intended.
Post 22 Dec 2012, 00:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.