CustomAction成功开发计算机上,无法部署计算机上 [英] CustomAction succeeds on development computer, fails on deployment computer

查看:133
本文介绍了CustomAction成功开发计算机上,无法部署计算机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个WiX的安装程序来安装它连接到数据库的程序。为了解决这个问题,我创建了一个C DLL进行检查,看是否有服务器上存在SQL有一定的实例:

I'm creating a WiX installer to install a program which connects to a database. To help with this, I've created a C dll which checks to see if a certain instance of SQL exists on a server:

extern "C" UINT __stdcall DBConTest(MSIHANDLE hInstaller)

{

FILE *fp;
fp = fopen("dbcontestdll.txt", "w");
_ConnectionPtr pCon;
int iErrCode;
HRESULT hr;
UINT rc;
//init COM

fwprintf(fp, L"entering dbcontest\n");
if(FAILED(hr = CoInitializeEx(NULL,tagCOINIT::COINIT_APARTMENTTHREADED)))
    return ERROR_INVALID_DATA;

fwprintf(fp,L"did coinit\n");
if(FAILED(hr = pCon.CreateInstance(__uuidof(Connection))))
    return ERROR_INVALID_DATA;

fwprintf(fp,L"created instance of connection\n");
TCHAR constr[1024];
DWORD constrlen = sizeof(constr);
rc=MsiGetProperty(hInstaller,TEXT("DBCONNECTIONSTRING"), constr, &constrlen);

fwprintf(fp, L"dbconstring is: %s\n", constr);
TCHAR serverstr[1024];
DWORD serverstrlen = sizeof(serverstr);
rc = MsiGetProperty(hInstaller,TEXT("SQLINSTANCE"),serverstr,&serverstrlen);

fwprintf(fp, L"SQLINSTANCE is: %sl\n",serverstr);
TCHAR finalconstr[2048];
swprintf(finalconstr,L"%s; Data Source=%s;",constr,serverstr);
try{
    hr = pCon->Open(finalconstr,TEXT(""),TEXT(""),adConnectUnspecified);
}
catch(_com_error ce){

    fwprintf(fp, L"%s\n", msg);
    ::MessageBox(NULL,msg,NULL,NULL);
    CoUninitialize();
    MsiSetProperty(hInstaller,TEXT("DBCONNECTIONVALID"),TEXT("0"));
    return ERROR_SUCCESS;

}
if(FAILED(hr)){
    MsiSetProperty(hInstaller,TEXT("DBCONNECTIONVALID"),TEXT("0"));
    return ERROR_SUCCESS;

}
pCon->Close();
CoUninitialize();
MsiSetProperty(hInstaller,TEXT("DBCONNECTIONVALID"),TEXT("1"));
::MessageBox(NULL,TEXT("Successfully connected to the database!"),NULL,NULL);
fwprintf(fp, L"leaving...\n");
fclose(fp);
return ERROR_SUCCESS;

}

现在,当我建立这个功能为DLL,并将其添加到我的WiX的项目,这code工作我的开发机器上(具体而言,成功完成安装和文件dbcontestdll.txt的存在,并有它正确的数据) - 但是,当我一个全新安装的机器上运行它,安装失败,退出code 2896和dbcontestdll.txt不创建

Now, when I build this function into a dll and add it to my WiX project, this code works on my development machine (specifically, the installation successfully finishes and the file "dbcontestdll.txt" exists and has the correct data in it)--but, when I run it on a "fresh install" machine, the installation fails with exit code 2896 and the "dbcontestdll.txt" is not created.

是否有prerequisites在Windows安装程序使用基于C-的DLL,如C ++可再发行?

Are there prerequisites to using C-based dlls in a Windows Installer, such as the C++ redistributable?

推荐答案

有关自定义操作,我强烈建议静态链接到C运行时。自定义aciton DLL稍微大一点结束了,但你必须在自定义操作以外的文件少了一个依赖。

For custom actions, I highly recommend statically linking to the C run time. The custom aciton DLL ends up a little bigger but you'll have one less dependency on files outside the custom action.

这篇关于CustomAction成功开发计算机上,无法部署计算机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆