[solved] SHOpenWithDialog lazarus / 34-Windows ---------------------------------------------------------------------- Cliff48 · 2015-06-17 10:37 I cant get this API to work.  I have: Code: [Select]Function SHOpenWithDialog( w: HWND; oai: OPenASInfo): hResult; stdcall; External 'shell32.dll'; . .    OPENASINFO = RECORD     pcszFile:  LPCWstr;     pcszClass: LPCWSTR;     FLAGS: DWORD;   end;                      . .    fillchar(OasINFO, SIZEOF(OPENASINFO), #00);   OasInfo.pcszFile := PWideChar(fn);   oasinfo.flags := 7;   SHOpenWithDialog(Form1.Handle, OasInfo); Gives a SIGSEGV (Assembler debug window shows rtn: SHRegSetPathA I also tried:   wfn := UTF8Decode (fn); This did bring up the Dialog box , but it was basically empty....   except for an instruction of: "Choose the program you want to use to open this protocol" Like all experiments like this I tried all sorts of subtle changes and one of them (I cant remember what it was) actually brought up the dialog window correctly populated with suitable programs to open the file I passed, unfortunately, when I selected the program I wanted, I received a SIDSEGV!!! and of course, the program selected didnt get opened. Anyone have any ideas how to make this work? Thanks in advance. ---------------------------------------------------------------------- Bart · 2015-06-17 11:07 Maybe use widestring API explicitely (untested code)? Code: [Select]Function SHOpenWithDialogW( w: HWND; oai: OPenASInfo): hResult; stdcall; External 'shell32.dll' name 'SHOpenWithDialogW'; The record structure may require some packing option, not sure about that. Bart ---------------------------------------------------------------------- Bart · 2015-06-17 11:23 This seems to work for me: Code: [Select]type   POPENASINFO = ^OPENASINFO;   OPENASINFO = RECORD       pcszFile:  LPCWstr;       pcszClass: LPCWSTR;       FLAGS: DWORD;   end;   Function SHOpenWithDialog( w: HWND; oai: POPenASInfo): hResult; stdcall; External 'shell32.dll' name 'SHOpenWithDialog'; //Note: the api expects a pointer to a OPENASINFO structure   ...   fn := 'foo';   fillchar(OasINFO, SIZEOF(OPENASINFO), #00);   OasInfo.pcszFile := PWideChar(Utf8ToUtf16(fn));  //uses LazUtf8 unit   oasinfo.flags := 7;   SHOpenWithDialog(Form1.Handle, @OasInfo); ... See also this thread on how to achive this on Windows versions lower than Vista. Bart ---------------------------------------------------------------------- Cliff48 · 2015-06-17 11:49 Thank you so much ....  it was the pointer to the structure that I missed. working beautifully  .. thanks again