高级安装程序串行验证DLL

时间:2013-06-25 11:47:55

标签: c++ dll serial-number advanced-installer

我正在使用Advanced Installer 10.2中的安装程序项目。我发现我可以使用DLL进行串行验证,然后在他们的网站上找到了this资源。

我成功构建了DLL,这是我的代码:

// SerialValidationLib.cpp:定义DLL应用程序的导出函数。 //

#include "stdafx.h"
#include "SerialValidationLib.h"
#include <Msi.h>
#include <MsiQuery.h>
#include <MsiDefs.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;

    HMODULE hModule = ::GetModuleHandle(NULL);

    if (hModule != NULL)
    {
        // initialize MFC and print and error on failure
        if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
        {
            // TODO: change error code to suit your needs
            _tprintf(_T("Fatal Error: MFC initialization failed\n"));
            nRetCode = 1;
        }
        else
        {
            // TODO: code your application's behavior here.
        }
    }
    else
    {
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
        nRetCode = 1;
    }

    return nRetCode;
}



UINT __stdcall ValidateSerial_Sample(MSIHANDLE hInstall) 
{
    TCHAR szPidKey[256]; 
    DWORD dwLen = sizeof(szPidKey)/sizeof(szPidKey[0]); 
    //retrive the text entered by the user 
    UINT res = MsiGetProperty(hInstall, _T("PIDKEY"), szPidKey, &dwLen); 
    if(res != ERROR_SUCCESS) 
    {
        //fail the installation 
        return 1; 
    }
    bool snIsValid = false; 
    //validate the text from szPidKey according to your algorithm 
    //put the result in snIsValid 
    TCHAR * serialValid; 
    if(snIsValid) 
        serialValid = _T("TRUE"); 
    else 
    {
        //eventually say something to the user 
        MessageBox(0, _T("Serial invalid!"), _T("Message"), MB_ICONSTOP); 
        serialValid = _T("FALSE"); 
    }
    res = MsiSetProperty(hInstall, _T("SERIAL_VALIDATION"), serialValid); 
    if(res != ERROR_SUCCESS) 
    {
        return 1; 
    } 
    //the validation succeeded - even the serial is wrong 
    //if the SERIAL_VALIDATION was set to FALSE the installation 
    //will not continue 
    return 0; 
}

我也将它导入Advanced Installer,请看这里:

enter image description here

但是当我运行安装程序并尝试继续安装时,在串行插入点之后,我收到此错误消息:

enter image description here

我的错误在哪里?有人知道这方面的好教程吗?我在互联网上搜索,但没有任何帮助我...

1 个答案:

答案 0 :(得分:1)

你可能有两个问题:

  • 要么输入了方法名称,要么从Advanced Installer加载的组合中选择方法名称。在这种情况下,安装程序无法从DLL调用该方法,因为它无法找到它。

  • 或者,您的代码存在问题,在这种情况下,您需要对其进行调试,就像使用正常的自定义操作一样,从VS附加(在其后添加一个带有断点的信息框)。 / p>