Common dialogs

Got a problem you cannot solve? Try here.
hess_joel
Posts: 47
Joined: Mon Nov 21, 2005 1:52 pm
Location: Eden Prairie, MN

Common dialogs

Postby hess_joel » Wed Jan 11, 2006 2:13 pm

Is there a plugin available, (or a sample) that shows how to use a Common windows dialog (i.e. an open file dialog or browse for file). I want to add functionality to a form to have a browse button.

Joel Hess

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Wed Jan 11, 2006 2:42 pm

Hi Joel

While I cannot offer you anything prebuilt, I can offer you some ideas to get you started:

    You can study the CD Autorun template to see how to process individual button click events in your setup script.
    You can call the native Win32 API for displaying an open dialog box using the Call DLL Function command.
    You can build your own dialog for browsing to a particular file using the rich set of dialog controls available - including tree, combo, and list views for navigating folders and files on the system.


Just some ideas to get you going!
Michael Nesmith
InstallAware
Home of The Next Generation MSI Installer
Get your free copy today - http://www.installaware.com/

hess_joel
Posts: 47
Joined: Mon Nov 21, 2005 1:52 pm
Location: Eden Prairie, MN

Postby hess_joel » Thu Jan 12, 2006 9:51 am

I opted to add the API Call to a Support DLL that we are already using, but the function is returning an LPSTR and I can't seem to get Installaware to acknowledge the response. The value of the variable that I'm assigning the result to doesn't change after it's been called.

Here's my CallDLL Function:

~InstallAware Clipboard Data~
~Call DLL Function~
~{1D47A69E-6C73-F75-AA23-835243005153}~
~$SUPPORTDIR$\\fgfinst.dll,fnOpenDialog,word,$ret1$,long,$Parm1$,long,$Parm3$,"pointer to string",$Parm2$,$~
~mIDEFunc.dll\\mEXEFunc.dll~

And just for the sake of completeness, here's my C++ function:

Code: Select all

extern "C" LPSTR PASCAL EXPORT fnOpenDialog(HWND hWnd, LPLONG/*lplValue*/, LPSTR lpszValue )
{
   //LONG   nReturn;
   LONG  nResult;
   //CString strPrinter(lpszValue);

   // generate debug message
   TRACE(_T("fnOpenDialog() called!\\n"));

   OPENFILENAME ofn = {0};
   TCHAR szFile[MAX_PATH+1] = {0};
   static TCHAR *szFilter   =
                        _T("All Files\\0*.*\\0\\0");

   //
   // Fill out data structure
   //
   ofn.Flags             = OFN_HIDEREADONLY;
   ofn.hInstance         = GetModuleHandle( NULL );
   ofn.hwndOwner         = hWnd;
   ofn.lpstrCustomFilter = 0;
   ofn.lpstrFile         = szFile;
   ofn.lpstrFileTitle    = 0;
   ofn.lpstrFilter       = szFilter;
   ofn.lpstrInitialDir   = 0;
   ofn.lpstrTitle        = _T("Browse for File");
   ofn.lStructSize       = sizeof( OPENFILENAME );
   ofn.nMaxFile          = MAX_PATH;

   //
   // Show dialog
   //
   nResult = GetOpenFileName( &ofn );

   TRACE(_T("-- INFO -- fnOpenDialog() nResult(%d)\\n"), nResult);
   TRACE(_T("-- INFO -- fnOpenDialog() szFile(%s)\\n"), szFile);

   if( nResult == 1 )
      return szFile;
   else
      return _T("Cancel");
}

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Thu Jan 12, 2006 10:55 am

Your function should not return a string. The return value should instead be an integer (-ish) value, following standard Win32 API conventions. You can pass the string value in a dedicated string buffer that is one of the function parameters. You can instruct InstallAware to allocate the memory required for this parameter in the Call DLL Function plug-in.

The problem with returning a string is that memory is allocated for it by the DLL, but never freed. Also it is not "defined" whether the host application can access this memory - given the state of the DLL, its memory contents may be ambiguous. This can cause lots of problems including stack corruption.
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

hess_joel
Posts: 47
Joined: Mon Nov 21, 2005 1:52 pm
Location: Eden Prairie, MN

Postby hess_joel » Thu Jan 12, 2006 3:50 pm

OK, I'm getting closer.

I've changed my function to:

Code: Select all

extern "C" LONG PASCAL EXPORT fnOpenDialog(HWND hWnd, LPSTR lpszValue, LONG lpBuffSize )
{
   //LONG   nReturn;
   LONG  nResult;
   //CString strPrinter(lpszValue);

   // generate debug message
   TRACE(_T("fnOpenDialog() called!\\n"));

   OPENFILENAME ofn = {0};
   TCHAR szFile[MAX_PATH+1] = {0};
   static TCHAR *szFilter   =
                        _T("All Files\\0*.*\\0\\0");

   //
   // Fill out data structuren
   //


   //
   // Show dialog
   //
   nResult = GetOpenFileName( &ofn );


   TRACE(_T("-- INFO -- fnOpenDialog() nResult(%d)\\n"), nResult);
   TRACE(_T("-- INFO -- fnOpenDialog() szFile(%s)\\n"), szFile);
   TRACE(_T("-- INFO -- fnOpenDialog() lpBuffSize(%d)\\n"), lpBuffSize);


   if( nResult == 1 )
   {
      strncpy(lpszValue, szFile, lpBuffSize);
      TRACE(_T("-- INFO -- fnOpenDialog() szValue(%s)\\n"), lpszValue);

   }


   return nResult;


and my Call DLL function to:
~InstallAware Clipboard Data~
~Call DLL Function~
~{F22EA679-6E8B-4C4A-9FE0-B6384E107B0B}~
~C:\\PRNInst\\Debug\\fgfinst.dll,fnOpenDialog,void,$ret1$,long,$Handle$,"allocated string buffer (MAX_PATH length)",$Parm3$,long,$strBuffer$,$~
~mIDEFunc.dll\\mEXEFunc.dll~

But I'm not getting anything back into my variables. I can watch the Debug output from the DLL and everything appears to be working correctly.

Ideas?

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Thu Jan 12, 2006 4:17 pm

Are you initializing the variables beforehand?
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

hess_joel
Posts: 47
Joined: Mon Nov 21, 2005 1:52 pm
Location: Eden Prairie, MN

Postby hess_joel » Thu Jan 12, 2006 4:58 pm

Yep

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Thu Jan 12, 2006 6:05 pm

I'm not a C expert...not sure what might be going wrong. I apologize for the inconvenience.
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

casic
Posts: 260
Joined: Thu Mar 17, 2005 4:02 am
Location: Germany
Contact:

Postby casic » Thu Jan 12, 2006 7:22 pm

Hi,

I'm currently developing a plugin to use common dialogs (Open File Dialog, Save File Dialog and Path Selector). The IDE part is already done - the complete plugin will published tomorrow.

Hope this helps,

Markus
Markus Diettrich
InstallAware MVP
If it can't be done with InstallAWARE then you are not using Windows

casic
Posts: 260
Joined: Thu Mar 17, 2005 4:02 am
Location: Germany
Contact:

Postby casic » Fri Jan 13, 2006 1:33 pm

Hi,

the plugin is now available - please check out this post:
http://www.installaware.com/forum/viewtopic.php?t=503

You can download the mdPLUGINS for InstallAWARE Setup here...

cu

Markus
Markus Diettrich

InstallAware MVP

If it can't be done with InstallAWARE then you are not using Windows

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Fri Jan 13, 2006 2:13 pm

Many thanks for the support here, Markus!
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

Gareth Owen
Posts: 149
Joined: Fri Oct 21, 2005 8:42 am
Location: UK

Postby Gareth Owen » Thu Jan 19, 2006 3:11 am

Hi guys, I have just been using the plugin written by casic. this seems great, I do however have one issue.

How do you fire this off from a dialog in the middle of the installation?

I am trying to add a dialog that allows you to select a licese file from your system. The idea was to have a text entry field for the file name and a browse button that will open the file open dialog and enter the selected file name in the text box.

I have managed to get most of the functionality by setting the browse button to goto the next dialog, running the file open script and then returning to the original dialog, but how should I differentiate between clicking the Next button and clicking the Browse button :?

Cheers

Gareth Owen
Posts: 149
Joined: Fri Oct 21, 2005 8:42 am
Location: UK

Postby Gareth Owen » Thu Jan 19, 2006 3:19 am

Ok, never mind, just ignore me, :oops:

do not know exactly what I managed to do there, but it seems to have sorted itself.

bobkaine
Posts: 4
Joined: Tue Aug 27, 2013 2:04 pm

Re:

Postby bobkaine » Fri Aug 30, 2013 12:15 pm

Gareth Owen wrote:Hi guys, I have just been using the plugin written by casic. this seems great, I do however have one issue.

How do you fire this off from a dialog in the middle of the installation?

I am trying to add a dialog that allows you to select a licese file from your system. The idea was to have a text entry field for the file name and a browse button that will open the file open dialog and enter the selected file name in the text box.

I have managed to get most of the functionality by setting the browse button to goto the next dialog, running the file open script and then returning to the original dialog, but how should I differentiate between clicking the Next button and clicking the Browse button :?

Cheers


I know this is a very old thread but how did you work out differentiating between the Next and Browse button?

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Common dialogs

Postby FrancescoT » Mon Sep 02, 2013 10:21 am

... just conditionally check in your script the returned value by the WIZARD pre-defined variable.

With the following example, the conditional statement is executed if the CANCEL button has been selected.

Code: Select all

if Variable WIZARD Equals CANCEL
 GoTo Label: Main Install
end


Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE


Return to “Technical Support”

Who is online

Users browsing this forum: Google [Bot] and 87 guests