This is very interesting, thank you for the code on how to define the GetSaveFileNameA function. I wrote a sample program to get it to work, but I think I have some syntax wrong, or maybe I'm not initializing something correctly. It compiles ok, but it doesn't execute even my writeln's, I just get an exit code = 1
James Program TestGetSaveFileNameA; Uses CRT,Classes,Sysutils,windows; Type TOpenFileNameAHookProc = function(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): UINT stdcall; TOpenFileNameA = Packed Record lStructSize: DWord; hWndOwner: HWND; hInstance: HINST; lpstrFilter: PChar; lpstrCustomFilter: PChar; nMaxCustFilter: DWord; nFilterIndex: DWord; lpstrFile: PChar; nMaxFile: DWord; lpstrFileTitle: PChar; nMaxFileTitle: DWord; lpstrInitialDir: PChar; lpstrTitle: PChar; Flags: DWord; nFileOffset: Word; nFileExtension: Word; lpstrDefExt: PChar; lCustData: LPARAM; lpfnHook: TOpenFileNameAHookProc; lpTemplateName: PChar; lpEditInfo: Pointer; // Undocumented? lpstrPrompt: PChar; _Reserved1: Pointer; _Reserved2: DWord; FlagsEx: DWord; End; POpenFileNameA = ^TOpenFileNameA; Function GetSaveFileNameA(arg: POpenFileNameA): windows.bool; stdcall; external 'comdlg32' name 'GetSaveFileNameA'; Var TFilename : TOpenFileNameA; PFilename : POpenFileNameA; Begin Writeln('Start'); TFilename.lpstrInitialDir:=Pchar('I:\'); Pfilename:=@Tfilename; Writeln(GetSaveFileNameA(PFilename)); Writeln('Finished'); Readln; End. -----Original Message----- From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf Of Ewald Sent: Sunday, November 4, 2018 8:06 AM To: fpc-pascal@lists.freepascal.org Subject: Re: [fpc-pascal] Windows programming tutorials for FPC On 11/03/2018 09:04 PM, James wrote: > So my question is, how can I use Ifilesavedialog with just FreePascal > in a console application? First off, the IFileSaveDialog is an interface, not a simple function. So, you'll need to: - Include the right units from freepascal (ActiveX and comobj IIRC) - Initialize and finalize the COM subsystem (see CoInitialize and CoUninitialize) - Use the CoCreateInstance to instantiate an IFileSaveDialog, etc.. I've never used the IFileSaveDialog myself, so have a look at https://msdn.microsoft.com/en-us/library/windows/desktop/bb776913%28v=vs.85%29.aspx#usage That's the nice thing about the GetSaveFileNameA function: one call, and you're done :-) Now, if this function is not defined in the windows unit (which could be the case), you can either look into some other units or simply define it yourself: === code begin === Type TOpenFileNameAHookProc = function(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): UINT stdcall; TOpenFileNameA = Packed Record lStructSize: DWord; hWndOwner: HWND; hInstance: HINST; lpstrFilter: PChar; lpstrCustomFilter: PChar; nMaxCustFilter: DWord; nFilterIndex: DWord; lpstrFile: PChar; nMaxFile: DWord; lpstrFileTitle: PChar; nMaxFileTitle: DWord; lpstrInitialDir: PChar; lpstrTitle: PChar; Flags: DWord; nFileOffset: Word; nFileExtension: Word; lpstrDefExt: PChar; lCustData: LPARAM; lpfnHook: TOpenFileNameAHookProc; lpTemplateName: PChar; lpEditInfo: Pointer; // Undocumented? lpstrPrompt: PChar; _Reserved1: Pointer; _Reserved2: DWord; FlagsEx: DWord; End; POpenFileNameA = ^TOpenFileNameA; Function GetSaveFileNameA(arg: POpenFileNameA): windows.bool; stdcall; external 'comdlg32' name 'GetSaveFileNameA'; === code end === -- Ewald _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal