Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get result from an IFileOpenDialog's IShellItem#get_display_name #44

Open
cyberarm opened this issue Apr 30, 2024 · 0 comments

Comments

@cyberarm
Copy link

require "win32cr"
require "win32cr/system/com"

LibWin32.CoInitializeEx(nil, LibWin32::COINIT::COINIT_APARTMENTTHREADED | LibWin32::COINIT::COINIT_DISABLE_OLE1DDE)

begin
  com = ComPtr(LibWin32::IFileOpenDialog).new(LibWin32::CLSID_FileOpenDialog, LibWin32::IID_IFileOpenDialog)
  default_flags = 0_u32
  com.get_options(pointerof(default_flags))
  com.set_options((default_flags | LibWin32::FILEOPENDIALOGOPTIONS::FOS_PATHMUSTEXIST.to_i | LibWin32::FILEOPENDIALOGOPTIONS::FOS_PICKFOLDERS.to_i))
  com.show(Pointer(Void).null)

  item = LibWin32::IShellItem.new
  buffer = uninitialized UInt16*
  if com.get_folder(pointerof(item))
    result = item.get_display_name(pointerof(item), LibWin32::SIGDN::SIGDN_FILESYSPATH, pointerof(buffer))
    pp result #String.from_utf16(buffer)
    # pp String.from_utf16(buffer)[0]
  else
    puts "Failed."
  end
rescue e
  puts e.message
end

LibWin32.CoUninitialize
Invalid memory access (C0000005) at address 0x7fffe5785de8
[0x7fffe5785de8] ShellExecuteExW +759464 in C:\Windows\SYSTEM32\windows.storage.dll
[0x7ff6a8c50cc1] get_display_name at C:\Users\cyber\Code\w3dhub_packager_webview\lib\win32cr\src\win32cr\ui\shell.cr:17422
[0x7ff6a8b8177e] __crystal_main at C:\Users\cyber\Code\w3dhub_packager_webview\src\w3dhub_packager.cr:16
[0x7ff6a8c57569] main_user_code at C:\Users\cyber\Applications\crystal-1.12.1\src\crystal\main.cr:129
[0x7ff6a8c5748a] main at C:\Users\cyber\Applications\crystal-1.12.1\src\crystal\main.cr:115
[0x7ff6a8bcf449] main at C:\Users\cyber\Applications\crystal-1.12.1\src\crystal\main.cr:141
[0x7ff6a8bcf563] wmain at C:\Users\cyber\Applications\crystal-1.12.1\src\crystal\system\win32\wmain.cr:37
[0x7ff6a8c58da0] __scrt_common_main_seh at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
[0x7fffe7cb7344] BaseThreadInitThunk +20 in C:\Windows\System32\KERNEL32.DLL
[0x7fffe9ae26b1] RtlUserThreadStart +33 in C:\Windows\SYSTEM32\ntdll.dll

Function being used:
https://github.com/mjblack/win32cr/blob/c4da22cfbe3bf363bf7ef5af1c00408f6626ce42/src/win32cr/ui/shell.cr#L17421-L17423

  def get_display_name(this : IShellItem*, sigdnname : SIGDN, ppszname : LibC::LPWSTR*) : HRESULT
    @lpVtbl.value.get_display_name.call(this, sigdnname, ppszname)
  end

*it is midnight, so I may be missing something obvious...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant