Porting code from InstallShield to IA
Posted: Tue May 28, 2013 11:15 am
I am tasked with porting installation code from InstallShield to IA.
Below is a code snippet that is using a helper DLL and creates a dialog that lists Ethernet printers and lets the user pick one that is getting installed.
Can this be done in IA?
function ShowDiscoverPrinterDlg(szTitle)
STRING szDialogName, szButtonText, szAdapterName[260], szSelAdapterName[260];
NUMBER nResult, nCmdValue, nStartIP, nEndIP, nItem, nIP;
BOOL bDone, b, bSearch;
LVCOLUMN lv;
LVITEM li;
STRING szCol1, szCol2, szCol3;
STRING szModel, szIP, szSerialNo, szSelectedIP, szIpName, szKey;
STRING szIPStart[16], szIPEnd[16], szDefIPStart, szDefIPEnd;
long lResult;
NUMBER nDllResult, nAdapterCnt, nCount;
HWND hWndDlg, hWndList, hStaticStartIP, hStaticEndIP, hStartIPCtrl, hEndIPCtrl, hStaticIP, hIPCtrl;
RECT rcStartIP, rcEndIP, rcIP;
POINT ptStartIP, ptEndIP, ptIP;
POINTER hGlobal, pBuffer;
LIST lsAdapter;
STRING svSection;
NUMBER nvIP;
begin
// list view column names
szCol1 = "IP Address";
szCol2 = "MAC Address";
szCol3 = "Serial No";
bSearch = TRUE;
// Specify a name to identify the custom dialog box in this installation.
szDialogName = "PrinterDiscoverDialog";
//nResult = EzDefineDialog (szDialogName, "", "", RES_DIALOG_ID);
nResult = DefineDialog (szDialogName, 0, "", RES_DIALOG_ID, "", 0, HWND_INSTALL, DLG_MSG_ALL|DLG_CENTERED);
if (nResult < 0) then
// Report an error; then terminate.
MessageBox ("Error in defining dialog box", SEVERE);
abort;
endif;
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done
repeat
// Display the dialog box and return the next dialog box event.
nCmdValue = WaitOnDialog(szDialogName);
// Respond to the event.
ChangeDirectory(SUPPORTDIR);
nDllResult = UseDLL (INSTALLERDLLNAME );
switch (nCmdValue)
case RES_PBUT_CLOSE:
// The user clicked the window's Close button.
Do (EXIT);
case DLG_CLOSE:
Do (EXIT);
case DLG_ERR:
MessageBox ("Unable to display dialog box. Setup canceled.", SEVERE);
abort;
case DLG_INIT:
// No initialization is required for this example.
hWndDlg = CmdGetHwndDlg( szDialogName );
SdGeneralInit( szDialogName, hWndDlg, STYLE_NORMAL, szSdProduct );
// -- Set Dialog Title and Header caption
SetWindowText(hWndDlg, szTitle);
SetWindowText(GetDlgItem(hWndDlg,50), "Search Ethernet Printers");
SetWindowText(GetDlgItem(hWndDlg,51), "Setup will search for the Ethernet printers in the network and display the available printers. You can select one of the available printers so that setup will install drivers for it.");
// -- Init ListView Columns
lv.mask = 6;
lv.Text = &szCol1;
lv.cx = 150;
lv.cchTextMax = 30;
hWndList = GetDlgItem(hWndDlg,1201);
lResult = SendMessage(hWndList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
nResult = lResult | LVS_EX_FULLROWSELECT;
SendMessage(hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, nResult);
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 0, &lv);
lv.mask = 6;
lv.Text = &szCol2;
lv.cx = 120;
lv.cchTextMax = 30;
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 1, &lv);
lv.mask = 6;
lv.Text = &szCol3;
lv.cx = 120;
lv.cchTextMax = 30;
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 2, &lv);
// -- Init IP Control
//Get the static control place holder
hStaticIP = GetDlgItem(hWndDlg, RES_IP);
//Get the static control's coordinates
b = GetWindowRect(hStaticIP, &rcIP);
ptIP.x = rcIP.left;
ptIP.y = rcIP.top;
//Convert coordinates relative to dialog's coordinates
ScreenToClient(hWndDlg, &ptIP);
//Create the IPAddress control on top of static control placeholder
/*hStartIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptStartIP.x,
ptStartIP.y,
rcStartIP.right - rcStartIP.left,
rcStartIP.bottom - rcStartIP.top,
hWndDlg,
NULL,
NULL,
NULL
);
hEndIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptEndIP.x,
ptEndIP.y,
rcEndIP.right - rcEndIP.left,
rcEndIP.bottom - rcEndIP.top,
hWndDlg,
NULL,
NULL,
NULL
); */
hIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptIP.x,
ptIP.y,
rcIP.right - rcIP.left,
rcIP.bottom - rcIP.top,
hWndDlg,
NULL,
NULL,
NULL
);
SdShowMsg(@IDS_ETHERNET_DISCOVERY_IN_PROGRESS, TRUE);
PopulatePrinterList( hWndList );
SdShowMsg("", FALSE);
// No initialization is required for this example.
case RES_PBUT_REFRESH:
SdShowMsg(@IDS_ETHERNET_DISCOVERY_IN_PROGRESS, TRUE);
PopulatePrinterList( hWndList );
SdShowMsg("", FALSE);
case RES_PBUT_CANCEL:
// The user clicked the Cancel button.
Do (EXIT);
case RES_PBUT_NEXT:
nIP = 0;
SendMessage(hIPCtrl , IPM_GETADDRESS, 0, &nIP );
if( nIP = 0 ) then
MessageBox("Please enter IP address (or) search for printer and select IP address", INFORMATION);
else
if(ValidateIP(nIP) == 0) then
MessageBox("Please enter valid IP address (or) search for printer and select IP address from displayed printers", INFORMATION);
else
szSelectedIP = "";
GetStringIPAddress( nIP, szSelectedIP );
if( StrLength( szSelectedIP ) > 0 ) then
if(SYSINFO.bIsWow64)then
REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;
endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szKey = "SOFTWARE\\MyComp\\MyPrinter";
szIpName = "IpAddress";
if(RegDBSetKeyValueEx(szKey, szIpName, REGDB_STRING, szSelectedIP, -1) < 0) then
MessageBox("IpAddress set to registry failed", INFORMATION);
bDone = FALSE;
else
bDone = TRUE;
nResult = NEXT;
endif;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT);
if(SYSINFO.bIsWow64)then
REGDB_OPTIONS = REGDB_OPTIONS & ~REGDB_OPTION_WOW64_64KEY;
endif;
if MODE == RECORDMODE then
SdMakeName(svSection, "EthSearchDlg", "", nvIP);
SilentWriteData(svSection, "IpAddress", DATA_STRING, szSelectedIP,0);
endif;
endif;
bDone = TRUE;
endif;
endif;
case RES_PBUT_BACK:
nResult = BACK;
bDone = TRUE;
case RES_PBUT_SEARCH:
szButtonText = "";
GetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), szButtonText, 16 );
if( StrCompare( szButtonText, "&Search") == 0 ) then
SendMessage(hStartIPCtrl , IPM_GETADDRESS, 0, &nStartIP );
SendMessage(hEndIPCtrl , IPM_GETADDRESS, 0, &nEndIP );
if( nStartIP >= nEndIP ) then
MessageBox("Start IP address should be less than End IP address.", INFORMATION);
else
SetDiscoverRange( nStartIP, nEndIP );
PopulateDiscoveredPrinter( hWndDlg, hWndList, hIPCtrl );
SetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), "S&top" );
endif;
else
StopDiscoverPrinter();
SetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), "&Search" );
endif;
case RES_COMBO:
if( CtrlGetSubCommand (szDialogName) = -1005 ) then
CtrlGetCurSel (szDialogName, RES_COMBO, szSelAdapterName );
nCount = FindListString(lsAdapter, szSelAdapterName);
if( -1 != nCount ) then
GetDefaultDiscoveryRange( (nCount+1) , nStartIP, nEndIP);
SendMessage(hStartIPCtrl, IPM_SETADDRESS, 0, nStartIP);
SendMessage(hEndIPCtrl, IPM_SETADDRESS, 0, nEndIP);
endif;
endif;
case 1201:
if( CtrlGetSubCommand (szDialogName) = -999 ) then
SetSelectedIP( hWndList, hIPCtrl );
endif;
endswitch;
until bDone;
// Close the dialog box.
EndDialog (szDialogName);
// Free the dialog box from memory.
ReleaseDialog (szDialogName);
return nResult;
end;
Below is a code snippet that is using a helper DLL and creates a dialog that lists Ethernet printers and lets the user pick one that is getting installed.
Can this be done in IA?
function ShowDiscoverPrinterDlg(szTitle)
STRING szDialogName, szButtonText, szAdapterName[260], szSelAdapterName[260];
NUMBER nResult, nCmdValue, nStartIP, nEndIP, nItem, nIP;
BOOL bDone, b, bSearch;
LVCOLUMN lv;
LVITEM li;
STRING szCol1, szCol2, szCol3;
STRING szModel, szIP, szSerialNo, szSelectedIP, szIpName, szKey;
STRING szIPStart[16], szIPEnd[16], szDefIPStart, szDefIPEnd;
long lResult;
NUMBER nDllResult, nAdapterCnt, nCount;
HWND hWndDlg, hWndList, hStaticStartIP, hStaticEndIP, hStartIPCtrl, hEndIPCtrl, hStaticIP, hIPCtrl;
RECT rcStartIP, rcEndIP, rcIP;
POINT ptStartIP, ptEndIP, ptIP;
POINTER hGlobal, pBuffer;
LIST lsAdapter;
STRING svSection;
NUMBER nvIP;
begin
// list view column names
szCol1 = "IP Address";
szCol2 = "MAC Address";
szCol3 = "Serial No";
bSearch = TRUE;
// Specify a name to identify the custom dialog box in this installation.
szDialogName = "PrinterDiscoverDialog";
//nResult = EzDefineDialog (szDialogName, "", "", RES_DIALOG_ID);
nResult = DefineDialog (szDialogName, 0, "", RES_DIALOG_ID, "", 0, HWND_INSTALL, DLG_MSG_ALL|DLG_CENTERED);
if (nResult < 0) then
// Report an error; then terminate.
MessageBox ("Error in defining dialog box", SEVERE);
abort;
endif;
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done
repeat
// Display the dialog box and return the next dialog box event.
nCmdValue = WaitOnDialog(szDialogName);
// Respond to the event.
ChangeDirectory(SUPPORTDIR);
nDllResult = UseDLL (INSTALLERDLLNAME );
switch (nCmdValue)
case RES_PBUT_CLOSE:
// The user clicked the window's Close button.
Do (EXIT);
case DLG_CLOSE:
Do (EXIT);
case DLG_ERR:
MessageBox ("Unable to display dialog box. Setup canceled.", SEVERE);
abort;
case DLG_INIT:
// No initialization is required for this example.
hWndDlg = CmdGetHwndDlg( szDialogName );
SdGeneralInit( szDialogName, hWndDlg, STYLE_NORMAL, szSdProduct );
// -- Set Dialog Title and Header caption
SetWindowText(hWndDlg, szTitle);
SetWindowText(GetDlgItem(hWndDlg,50), "Search Ethernet Printers");
SetWindowText(GetDlgItem(hWndDlg,51), "Setup will search for the Ethernet printers in the network and display the available printers. You can select one of the available printers so that setup will install drivers for it.");
// -- Init ListView Columns
lv.mask = 6;
lv.Text = &szCol1;
lv.cx = 150;
lv.cchTextMax = 30;
hWndList = GetDlgItem(hWndDlg,1201);
lResult = SendMessage(hWndList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
nResult = lResult | LVS_EX_FULLROWSELECT;
SendMessage(hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, nResult);
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 0, &lv);
lv.mask = 6;
lv.Text = &szCol2;
lv.cx = 120;
lv.cchTextMax = 30;
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 1, &lv);
lv.mask = 6;
lv.Text = &szCol3;
lv.cx = 120;
lv.cchTextMax = 30;
nResult = SendMessage(hWndList, LVM_INSERTCOLUMN, 2, &lv);
// -- Init IP Control
//Get the static control place holder
hStaticIP = GetDlgItem(hWndDlg, RES_IP);
//Get the static control's coordinates
b = GetWindowRect(hStaticIP, &rcIP);
ptIP.x = rcIP.left;
ptIP.y = rcIP.top;
//Convert coordinates relative to dialog's coordinates
ScreenToClient(hWndDlg, &ptIP);
//Create the IPAddress control on top of static control placeholder
/*hStartIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptStartIP.x,
ptStartIP.y,
rcStartIP.right - rcStartIP.left,
rcStartIP.bottom - rcStartIP.top,
hWndDlg,
NULL,
NULL,
NULL
);
hEndIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptEndIP.x,
ptEndIP.y,
rcEndIP.right - rcEndIP.left,
rcEndIP.bottom - rcEndIP.top,
hWndDlg,
NULL,
NULL,
NULL
); */
hIPCtrl = CreateWindowExA(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_CLIENTEDGE,
WC_IPADDRESS,
"",
WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,
ptIP.x,
ptIP.y,
rcIP.right - rcIP.left,
rcIP.bottom - rcIP.top,
hWndDlg,
NULL,
NULL,
NULL
);
SdShowMsg(@IDS_ETHERNET_DISCOVERY_IN_PROGRESS, TRUE);
PopulatePrinterList( hWndList );
SdShowMsg("", FALSE);
// No initialization is required for this example.
case RES_PBUT_REFRESH:
SdShowMsg(@IDS_ETHERNET_DISCOVERY_IN_PROGRESS, TRUE);
PopulatePrinterList( hWndList );
SdShowMsg("", FALSE);
case RES_PBUT_CANCEL:
// The user clicked the Cancel button.
Do (EXIT);
case RES_PBUT_NEXT:
nIP = 0;
SendMessage(hIPCtrl , IPM_GETADDRESS, 0, &nIP );
if( nIP = 0 ) then
MessageBox("Please enter IP address (or) search for printer and select IP address", INFORMATION);
else
if(ValidateIP(nIP) == 0) then
MessageBox("Please enter valid IP address (or) search for printer and select IP address from displayed printers", INFORMATION);
else
szSelectedIP = "";
GetStringIPAddress( nIP, szSelectedIP );
if( StrLength( szSelectedIP ) > 0 ) then
if(SYSINFO.bIsWow64)then
REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;
endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szKey = "SOFTWARE\\MyComp\\MyPrinter";
szIpName = "IpAddress";
if(RegDBSetKeyValueEx(szKey, szIpName, REGDB_STRING, szSelectedIP, -1) < 0) then
MessageBox("IpAddress set to registry failed", INFORMATION);
bDone = FALSE;
else
bDone = TRUE;
nResult = NEXT;
endif;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT);
if(SYSINFO.bIsWow64)then
REGDB_OPTIONS = REGDB_OPTIONS & ~REGDB_OPTION_WOW64_64KEY;
endif;
if MODE == RECORDMODE then
SdMakeName(svSection, "EthSearchDlg", "", nvIP);
SilentWriteData(svSection, "IpAddress", DATA_STRING, szSelectedIP,0);
endif;
endif;
bDone = TRUE;
endif;
endif;
case RES_PBUT_BACK:
nResult = BACK;
bDone = TRUE;
case RES_PBUT_SEARCH:
szButtonText = "";
GetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), szButtonText, 16 );
if( StrCompare( szButtonText, "&Search") == 0 ) then
SendMessage(hStartIPCtrl , IPM_GETADDRESS, 0, &nStartIP );
SendMessage(hEndIPCtrl , IPM_GETADDRESS, 0, &nEndIP );
if( nStartIP >= nEndIP ) then
MessageBox("Start IP address should be less than End IP address.", INFORMATION);
else
SetDiscoverRange( nStartIP, nEndIP );
PopulateDiscoveredPrinter( hWndDlg, hWndList, hIPCtrl );
SetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), "S&top" );
endif;
else
StopDiscoverPrinter();
SetWindowText( GetDlgItem( hWndDlg, RES_PBUT_SEARCH ), "&Search" );
endif;
case RES_COMBO:
if( CtrlGetSubCommand (szDialogName) = -1005 ) then
CtrlGetCurSel (szDialogName, RES_COMBO, szSelAdapterName );
nCount = FindListString(lsAdapter, szSelAdapterName);
if( -1 != nCount ) then
GetDefaultDiscoveryRange( (nCount+1) , nStartIP, nEndIP);
SendMessage(hStartIPCtrl, IPM_SETADDRESS, 0, nStartIP);
SendMessage(hEndIPCtrl, IPM_SETADDRESS, 0, nEndIP);
endif;
endif;
case 1201:
if( CtrlGetSubCommand (szDialogName) = -999 ) then
SetSelectedIP( hWndList, hIPCtrl );
endif;
endswitch;
until bDone;
// Close the dialog box.
EndDialog (szDialogName);
// Free the dialog box from memory.
ReleaseDialog (szDialogName);
return nResult;
end;