zoukankan      html  css  js  c++  java
  • C++ DLL 获取 MSI Property

    VS2010 创建  C++, Win32 DLL工程C-TEST。

    Stdafx.h中,在<windows.h>之后 添加引用。

    #include <msi.h>
    #include <msiquery.h>

    C-TEST.cpp

     1 #include "stdafx.h"
     2 #include <tchar.h>
     3 
     4 UINT GetProperty(MSIHANDLE hInstall)
     5 {
     6     TCHAR* szValueBuf = NULL;
     7     DWORD cchValueBuf = 0;
     8     UINT uiStat =  MsiGetProperty(hInstall, TEXT("ProductName"), TEXT(""), &cchValueBuf);
     9     //cchValueBuf now contains the size of the property's string, without null termination
    10     if (ERROR_MORE_DATA == uiStat)
    11     {
    12         ++cchValueBuf; // add 1 for null termination
    13         szValueBuf = new TCHAR[cchValueBuf];
    14         if (szValueBuf)
    15         {
    16             uiStat = MsiGetProperty(hInstall, TEXT("ProductName"), szValueBuf, &cchValueBuf);
    17         }
    18     }
    19 
    20     MessageBox(NULL, szValueBuf, _T("Im GetProperty"), MB_OK);
    21 
    22     if (ERROR_SUCCESS != uiStat)
    23     {
    24         if (szValueBuf != NULL) {
    25             delete[] szValueBuf;
    26 
    27         }
    28         return ERROR_INSTALL_FAILURE;
    29     }
    30 
    31     delete[] szValueBuf;
    32 
    33     return ERROR_SUCCESS;
    34 
    35 }
    36 
    37 UINT _stdcall SampleFunction2(LPCTSTR productName, MSIHANDLE hInstall)
    38 {
    39     MessageBox(NULL, _T("Hello, welcome to C-TEST") ,_T("I'm Sample Function2's message"), MB_OK);
    40     MessageBox(NULL, productName ,_T("I'm Sample Function2's break point"), MB_OK);
    41     GetProperty(hInstall);
    42     return 0;
    43 }

    添加 C-TEST.def 文件

    LIBRARY "C-TEST"
    EXPORTS
    SampleFunction2

    编译,

    1) 如果没有 #include <tchar.h>,会出现 error C3861: '_T': identifier not found

    2)error LNK1120: 1 unresolved externals

    解决方案:

    工程右键 Property -> Configuration Properties -> Linker / Input / Additional Dependencies

    添加  msi.lib

    编译通过。

  • 相关阅读:
    大数据分析项目中的“最差”实践
    【Python】Python正则表达式使用指导
    大数据分析的5个方面
    你真的会python嘛?
    你是如何自学 Python 的?
    python中#!/usr/bin/python与#!/usr/bin/env python的区别
    [实验吧刷题]密码学部分
    [bugku]高阶web 综合帖
    [bugku]sqlmap部分
    【ctf第一次校赛】+不会的web/ +凉凉的省赛预赛 + 最后摸了 个二等。。
  • 原文地址:https://www.cnblogs.com/cindy-hu-23/p/3725794.html
Copyright © 2011-2022 走看看