转载?http://wglnngt-001.blog.163.com/blog/static/4077058420091114114652911/
How to use SQL Dialogs without Scripts??
Because?so?many?people?have?problems?with?InstallShieldX?using?SQL?Dialogs,?I?thought?I?might?make?this?brief?tutorial?so?users?can?get?up?and?running?without?reading?several?hundred?posts?online.?This?tutorial?can?be?used?for?InstallScript?MSI?Projects,?but?it?may?also?help?for?InstallScript?only?Projects?as?well.?
First,?I'd?like?to?note?that?you?should?download?the?attached?ZIP?file?which?contains?updated?SQLRT.dll?and?ISSQLSRV.dll?files.?No,?I?did?not?create?these,?they?were?given?to?me?from?InstallShield?as?a?fix?that?is?not?included?in?SP1?for?InstallShieldX.?They?update?a?couple?of?Issues?with?InstallShieldX?and?ADO?(such?as?timeouts,?etc.).?Also?included?is?the?updated?SQLCONV.h?file.?The?included?zip?file?contains?a?Batch?file?which?I?created?to?help?in?putting?these?files?in?the?correct?location.?You?can?run?this?batch?file?which?will?first?backup?your?existing?DLLs?before?overwriting?them.?
This?was?something?I?ended?up?finding?on?my?own.?There?seems?to?be?a?bug?in?the?ifx.h?header?file.?In?order?to?actually?use?the?SQL?Runtime?from?InstallShield?without?scripts,?you?need?to?invoke?a?call?to?SQLRTInitialize().?This?function?is?located?in?the?SQLRT.h?header?file.?No?big?deal?you?say,?just?include?that?file?in?the?Setup.rul!?It's?not?that?easy.?You?see,?there?are?two?ifx.h?files:?one?is?loacted?in?the?.\Script\Ifx\Include?and?the?other?in?.\Script\Iswi\Include\.?Which?one?your?Script?is?linked?to?depends?on?the?(.obl)?file?paths?in?Step?1.?
In?the?case?with?InstallScript?MSI?Projects,?the?Ifx.h?file?is?linked?from?the?.\Script\Iswi\Include\?directory.?If?we?open?that?Ifx.h?file,?we?can?see?that?InstallShield?tried?to?"think"?for?us?and?they?included?the?SQLCONV.h?(this?line:?#include?"..\..\SQLRuntime\Include\SQLConv.h")?file?automatically.?Why?is?this?bad?you?ask??Well,?we?need?to?include?the?SQLRT.h?file,?but?if?you?look?in?both?that?file?and?the?SQLCONV.h?file,?you?will?see?that?they?both?define?this?function:?external?prototype?LIST?SQLRTGetServers(?byval?BOOL?);!?So,?if?you?were?to?include?the?SQLRT.h?file?in?your?scripts?at?this?point,?you?would?get?the?following?error?trying?to?compile:?'SQLRTGetServers'?:?identifier?already?defined.?
So?how?do?we?get?around?this??Well,?we?only?need?the?SQLRTInitialize()?function?and?since?both?the?SQLRT.h?and?the?SQLCONV.h?both?use?the?SQLRT.dll?functions,?we?just?need?to?modify?the?SQLCONV.h?file?to?include?that?function!?So,?here?it?is,?what?you've?been?waiting?for...?
Code:?
//---------------------------------------------------------------------------?
//?OnSQLLogin?
//---------------------------------------------------------------------------?
function?number?OnSQLLogin(?nReturn?)?
string?sDLL,?sMessage;?
string?sHidden[MAX_PATH];?
string?sServer[MAX_PATH],?sUser[MAX_PATH],?sPassword[MAX_PATH],?sAuth[10],?sDB[MAX_PATH],?sTemp[MAX_PATH];?
number?nResult,?nSize,?nRetVal;?
BOOL???bWinAuth,?bDoneLogin;?
begin?
//?Extract?SQL?Runtime?dlls?
sDLL?=?SUPPORTDIR?^?"ISSQLSRV.DLL";?
nResult?=?StreamFileFromBinary(??ISMSI_HANDLE,?"ISSQLSRV.DLL",?sDLL?);?
if?(nResult?=?-1)?then?
MessageBox("The?\"ISSQLSRV.dll\"?could?not?be?extracted?from?the?Binary?Table.",?SEVERE);?
abort;?
endif;?
UseDLL(?sDLL?);?
sDLL?=?SUPPORTDIR?^?"SQLRT.DLL";?
nResult?=?StreamFileFromBinary(ISMSI_HANDLE,?"SQLRT.DLL",?sDLL);?
if?(nResult?=?-1)?then?
????MessageBox("The?\"SQLRT.DLL\"?could?not?be?extracted?from?the?Binary?Table.",?SEVERE);?
????abort;?
endif;?
UseDLL(?sDLL?);?
?????
SQLRTInitialize("");?
//?Add?the?Password?property?as?a?Hidden?property?so?no?passwords?accidentally?get?logged.?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"MsiHiddenProperties",?sHidden,?nSize?);?
if?(StrLength(sHidden)?>?0)?then?sHidden?=?sHidden?+?";";?endif;?
sHidden?=?sHidden?+?"IS_SQLSERVER_PASSWORD";?
MsiSetProperty(?ISMSI_HANDLE,?"MsiHiddenProperties",?sHidden?);?
//?Get?Default?properties?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_SERVER",?sServer,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_DATABASE",?sDB,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_USERNAME",?sUser,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_PASSWORD",?sPassword,?nSize?);?
nSize?=?10;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_AUTHENTICATION",?sAuth,?nSize?);?
if?(sAuth?=?"1")?then?
bWinAuth?=?FALSE;?
else?
bWinAuth?=?TRUE;?
endif;?
bDoneLogin?=?FALSE;?
while(?!bDoneLogin?)?
//?Show?login?dialog?
nReturn?=?SQLServerSelectLogin(?sServer,?sUser,?sPassword,?bWinAuth?);?
if?(nReturn?=?BACK)?then?
//?BACK?was?clicked,?so?we?don't?even?try?
bDoneLogin?=?TRUE;?
elseif?(nReturn?=?NEXT)?then?
//?Validate?Connection?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_SERVER",?sServer?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_USERNAME",?sUser?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_PASSWORD",?sPassword?);?
if?(bWinAuth?=?TRUE)?then?
sAuth?=?"0";?
else?
sAuth?=?"1";?
endif;?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_AUTHENTICATION",?sAuth?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_CA_SILENT",?"0"?);?
nRetVal?=?SQLRTServerValidate(?ISMSI_HANDLE?);?
???????????
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_STATUS",?sTemp,?nSize?);?
if(?sTemp?!=?"0"?)?then?
nSize?=?_MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_STATUS_ERROR",?sMessage,?nSize?);?
if?(nSize?=?0)?then?sMessage?=?SdLoadString(?IDS_IFX_SQL_ERROR_LOGIN_FAILED?);?endif;?
MessageBox(?sMessage,?MB_OK?);?
else?
//?Validation?Successful?
bDoneLogin?=?TRUE;?
endif;?
else?
????????MessageBox("General?Errors?Occured?showing?the?SQL?Server?Login?Dialog.",?SEVERE);?
????????abort;?
endif;?
endwhile;?
return?nReturn;?
end;?
Well,?I?think?that's?it.?I?tried?to?get?everything?in?here?as?concise?and?informative?as?possible.?If?anyone?has?problems?with?this,?let?me?know!
First,?I'd?like?to?note?that?you?should?download?the?attached?ZIP?file?which?contains?updated?SQLRT.dll?and?ISSQLSRV.dll?files.?No,?I?did?not?create?these,?they?were?given?to?me?from?InstallShield?as?a?fix?that?is?not?included?in?SP1?for?InstallShieldX.?They?update?a?couple?of?Issues?with?InstallShieldX?and?ADO?(such?as?timeouts,?etc.).?Also?included?is?the?updated?SQLCONV.h?file.?The?included?zip?file?contains?a?Batch?file?which?I?created?to?help?in?putting?these?files?in?the?correct?location.?You?can?run?this?batch?file?which?will?first?backup?your?existing?DLLs?before?overwriting?them.?
- Add?the?(.obl)?Libraries?On?the?Build?menu,?click?on?Settings.?On?the?Compile/Link?tab,?add?the?following?(.obl)?Libraries?(seperated?by?commas)?if?they?do?not?exist:?
- <ISProductFolder>\Script\SQLRuntime\Lib\SQLRT.obl?
- <ISProductFolder>\Script\SQLRuntime\Lib\SQLCONV.obl
- Add?the?required?DLLs?to?the?Binary?Table?Now,?go?to?the?Direct?Editor?and?find?the?Binary?table.?Here?we?need?to?add?the?SQL?DLLs?that?normally?get?included?automatically?when?adding?Scripts?to?an?InstallShield?Project.?Add?a?new?Item?in?the?Binary?table?(where?it?says?"Click?here?to?add?a?new?Item").?Add?the?Following?information:?
- For?the?1st?Item,?enter?the?Name?as?ISSQLSRV.DLL.?Now,?when?you?click?in?the?Data?column,?a?dialog?will?popup?asking?what?to?do?with?the?data.?You?want?the?Read?binary?from?filename?option.?Click?Browse?and?browse?to?<ProgramFiles>\InstallShieldX\Redist\Language?Independent\i386\ISSQLSrv.dll.?Next?Click?Open?then?Ok?and?the?DLL?will?be?added?to?the?Binary?table.?
- For?the?2nd?Item,?enter?the?Name?as?SQLRT.DLL.?For?the?Data,?browse?to?<ProgramFiles>\InstallShieldX\Redist\Compressed?Files\Language?Independent\Intel?32\SQLRT.dll.
- Modify?the?"SQLConv.h"?Header?File?NOTE:?All?script?/?header?files?talked?about?are?located?in?<ProgramFiles>\InstallShieldX\Script.
This?was?something?I?ended?up?finding?on?my?own.?There?seems?to?be?a?bug?in?the?ifx.h?header?file.?In?order?to?actually?use?the?SQL?Runtime?from?InstallShield?without?scripts,?you?need?to?invoke?a?call?to?SQLRTInitialize().?This?function?is?located?in?the?SQLRT.h?header?file.?No?big?deal?you?say,?just?include?that?file?in?the?Setup.rul!?It's?not?that?easy.?You?see,?there?are?two?ifx.h?files:?one?is?loacted?in?the?.\Script\Ifx\Include?and?the?other?in?.\Script\Iswi\Include\.?Which?one?your?Script?is?linked?to?depends?on?the?(.obl)?file?paths?in?Step?1.?
In?the?case?with?InstallScript?MSI?Projects,?the?Ifx.h?file?is?linked?from?the?.\Script\Iswi\Include\?directory.?If?we?open?that?Ifx.h?file,?we?can?see?that?InstallShield?tried?to?"think"?for?us?and?they?included?the?SQLCONV.h?(this?line:?#include?"..\..\SQLRuntime\Include\SQLConv.h")?file?automatically.?Why?is?this?bad?you?ask??Well,?we?need?to?include?the?SQLRT.h?file,?but?if?you?look?in?both?that?file?and?the?SQLCONV.h?file,?you?will?see?that?they?both?define?this?function:?external?prototype?LIST?SQLRTGetServers(?byval?BOOL?);!?So,?if?you?were?to?include?the?SQLRT.h?file?in?your?scripts?at?this?point,?you?would?get?the?following?error?trying?to?compile:?'SQLRTGetServers'?:?identifier?already?defined.?
So?how?do?we?get?around?this??Well,?we?only?need?the?SQLRTInitialize()?function?and?since?both?the?SQLRT.h?and?the?SQLCONV.h?both?use?the?SQLRT.dll?functions,?we?just?need?to?modify?the?SQLCONV.h?file?to?include?that?function!?So,?here?it?is,?what?you've?been?waiting?for...?
- Add?this?line?to?the?SQLCONV.h?file:?external?prototype?void?SQLRTInitialize(?byval?string?);.?It?doesn't?really?matter?where,?but?I?put?it?just?above?the?other?SQL?functions.
- Modify?the?"OnSQLLogin()"?Function?Well,?here?it?is,?the?last?step.?We?need?to?modify?the?OnSQLLogin?function.?Why??Well,?this?function?displays?the?SQLLogin?Dialog.?But?it?does?more?than?that,?it?extracts?the?DLLs?from?the?Binary?table?and?loads?them?into?memory.?Now,?I?give?InstallShield?credit?for?initially?writing?this?script,?but?lets?face?it,?they're?not?the?best?at?writing?concise?code?!?Please?keep?in?mind?that?you?could?write?your?own?functions?to?extract?the?DLLs?once?and?then?call?multiple?SQL?Dialogs,?but?I?am?just?trying?to?keep?this?simple?for?now.
Code:?
//---------------------------------------------------------------------------?
//?OnSQLLogin?
//---------------------------------------------------------------------------?
function?number?OnSQLLogin(?nReturn?)?
string?sDLL,?sMessage;?
string?sHidden[MAX_PATH];?
string?sServer[MAX_PATH],?sUser[MAX_PATH],?sPassword[MAX_PATH],?sAuth[10],?sDB[MAX_PATH],?sTemp[MAX_PATH];?
number?nResult,?nSize,?nRetVal;?
BOOL???bWinAuth,?bDoneLogin;?
begin?
//?Extract?SQL?Runtime?dlls?
sDLL?=?SUPPORTDIR?^?"ISSQLSRV.DLL";?
nResult?=?StreamFileFromBinary(??ISMSI_HANDLE,?"ISSQLSRV.DLL",?sDLL?);?
if?(nResult?=?-1)?then?
MessageBox("The?\"ISSQLSRV.dll\"?could?not?be?extracted?from?the?Binary?Table.",?SEVERE);?
abort;?
endif;?
UseDLL(?sDLL?);?
sDLL?=?SUPPORTDIR?^?"SQLRT.DLL";?
nResult?=?StreamFileFromBinary(ISMSI_HANDLE,?"SQLRT.DLL",?sDLL);?
if?(nResult?=?-1)?then?
????MessageBox("The?\"SQLRT.DLL\"?could?not?be?extracted?from?the?Binary?Table.",?SEVERE);?
????abort;?
endif;?
UseDLL(?sDLL?);?
?????
SQLRTInitialize("");?
//?Add?the?Password?property?as?a?Hidden?property?so?no?passwords?accidentally?get?logged.?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"MsiHiddenProperties",?sHidden,?nSize?);?
if?(StrLength(sHidden)?>?0)?then?sHidden?=?sHidden?+?";";?endif;?
sHidden?=?sHidden?+?"IS_SQLSERVER_PASSWORD";?
MsiSetProperty(?ISMSI_HANDLE,?"MsiHiddenProperties",?sHidden?);?
//?Get?Default?properties?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_SERVER",?sServer,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_DATABASE",?sDB,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_USERNAME",?sUser,?nSize?);?
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_PASSWORD",?sPassword,?nSize?);?
nSize?=?10;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_AUTHENTICATION",?sAuth,?nSize?);?
if?(sAuth?=?"1")?then?
bWinAuth?=?FALSE;?
else?
bWinAuth?=?TRUE;?
endif;?
bDoneLogin?=?FALSE;?
while(?!bDoneLogin?)?
//?Show?login?dialog?
nReturn?=?SQLServerSelectLogin(?sServer,?sUser,?sPassword,?bWinAuth?);?
if?(nReturn?=?BACK)?then?
//?BACK?was?clicked,?so?we?don't?even?try?
bDoneLogin?=?TRUE;?
elseif?(nReturn?=?NEXT)?then?
//?Validate?Connection?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_SERVER",?sServer?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_USERNAME",?sUser?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_PASSWORD",?sPassword?);?
if?(bWinAuth?=?TRUE)?then?
sAuth?=?"0";?
else?
sAuth?=?"1";?
endif;?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_AUTHENTICATION",?sAuth?);?
MsiSetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_CA_SILENT",?"0"?);?
nRetVal?=?SQLRTServerValidate(?ISMSI_HANDLE?);?
???????????
nSize?=?MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_STATUS",?sTemp,?nSize?);?
if(?sTemp?!=?"0"?)?then?
nSize?=?_MAX_PATH;?MsiGetProperty(?ISMSI_HANDLE,?"IS_SQLSERVER_STATUS_ERROR",?sMessage,?nSize?);?
if?(nSize?=?0)?then?sMessage?=?SdLoadString(?IDS_IFX_SQL_ERROR_LOGIN_FAILED?);?endif;?
MessageBox(?sMessage,?MB_OK?);?
else?
//?Validation?Successful?
bDoneLogin?=?TRUE;?
endif;?
else?
????????MessageBox("General?Errors?Occured?showing?the?SQL?Server?Login?Dialog.",?SEVERE);?
????????abort;?
endif;?
endwhile;?
return?nReturn;?
end;?
Well,?I?think?that's?it.?I?tried?to?get?everything?in?here?as?concise?and?informative?as?possible.?If?anyone?has?problems?with?this,?let?me?know!