Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Calling BrowseForFile DLL


1 reply to this topic

blood_on_ice

blood_on_ice
  • Full Members
  • 4 posts

Posted 17 March 2008 - 11:15

Hello!

I try to use the BrowseForFile DLL from http://www.installsi...owseForFile.zip I inserted the BrowseForFile.dll in the support files section.

Then I do the following in the install-script:
prototype BYREF STRING BrowseForFile.BrowseForFile(BYREF STRING, BYREF STRING);

szFilter = "Certificate File (*.cer)\0*.cer\0";
UseDLL(SUPPORTDIR ^ "BrowseForFile.DLL");
BrowseForFile.BrowseForFile(szCertificatePath, szFilter);
MessageBox( "Selected Path: " + szCertificatePath, INFORMATION );
UnUseDLL(SUPPORTDIR ^ "BrowseForFile.DLL");

I get the error 0x80040704

What's the problem, how can i prototype this function and call it after that?

Here's the code of the dll:
CODE

//***********************************************************
//** This source code is provided "AS IS" with no warranties,
//** and confers no rights.
//***********************************************************

#include <tchar.h>
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#include "msiquery.h"
#include "strsafe.h"

//***********************************************************
//** Call back function for EnumChildWindows()
//**---------------------------------------------------------
//** Author: Kallely L Sajan
//***********************************************************
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
 TCHAR buf[100];
 GetClassName( hwnd, (LPTSTR)&buf, 100 );

 if ( _tcscmp ( buf, (_T("RichEdit20W")) ) == 0 )
 {
  *(HWND*)lParam = hwnd;
  return FALSE;
 }
}

UINT __stdcall BrowseForFile(MSIHANDLE hInstall)
{
//MessageBox(NULL, "BrowseForFile", "BrowseForFile", MB_OK);

//Set up storage for PATHTOFILE
TCHAR szOriginalPath[MAX_PATH];
DWORD cchValue = sizeof(szOriginalPath)/sizeof(TCHAR);
ZeroMemory(szOriginalPath, sizeof(TCHAR)*MAX_PATH);

// Get PATHTOFILE
MsiGetProperty(hInstall, TEXT("PATHTOFILE"), szOriginalPath, &cchValue);

long lErrMsg = 0;
OPENFILENAME ofn;

ZeroMemory(&ofn, sizeof(ofn));

TCHAR szFilters[] =
   _T("All Files (*.*)\0*.*\0")
_T("Text File (*.txt)\0*.txt\0");

// Initialize OPENFILENAME structure.
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetForegroundWindow();
ofn.lpstrFile = szOriginalPath;
ofn.nMaxFile = sizeof(szOriginalPath);
ofn.lpstrFilter = szFilters;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
//ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
//ofn.Flags = OFN_HIDEREADONLY;

if (GetOpenFileName(&ofn))
{
 MsiSetProperty(hInstall, TEXT("PATHTOFILE"), szOriginalPath);

 //This next bit of code fixes a problem that occurs if the author is
 //using an Edit box for the path. For whatever reason, if a user
 //types into the edit box before browsing for a file or folder
 //the Edit box is not updated once the custom action completes.
 //Much of the following code was modified from
 //Kallely L Sajan's IsLicensedViewed article from InstallSite.org
 HWND hWnd;
 HWND hWndChild=NULL;

 hWnd = FindWindow(NULL, "Default - InstallShield Wizard");
 if (hWnd) {
  EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
  if ( hWndChild ) {
   TCHAR buf[100];
   _tcscpy(buf, szOriginalPath);
   //the following call will not work if _UNICODE is defined in Prepocessor definitions
   SendMessage(hWndChild, WM_SETTEXT, 0, (LPARAM)szOriginalPath);
  }
 }
}
return ERROR_SUCCESS;
}



Kind regards,
Peter

blood_on_ice

blood_on_ice
  • Full Members
  • 4 posts

Posted 18 March 2008 - 17:58

Here's the solution (for installscript):

http://www.installsi...eBrowseDlg6.zip

Kind regards,
Peter