[wix-users] calling 3rd part library calls using custom action in c++

Hanumanthaiah, ShashikalaX shashikalax.hanumanthaiah at intel.com
Tue Mar 5 00:08:50 PST 2019


Hi,

    I have created a DLL which just creates a file. Iam trying call this Createnewfile API through custom action in wix cpp.
    My compilation went fine but when I run the msi , The file is not getting created after the installation. Iam attaching the snippet for reference.
   Could you please guide me where Iam going wrong .

   Custionaction.cpp
#include "Testdll.h"

UINT __stdcall Createfile(
       MSIHANDLE hInstall
       )
{
       HRESULT hr = S_OK;
       UINT er = ERROR_SUCCESS;

       hr = WcaInitialize(hInstall, "Createfile");
       ExitOnFailure(hr, "Failed to initialize");

       //const char* filepath="C://shashi.txt";
       //const char * Mode = "W";
       //wsprintfA(filepath, "%S",L"Name");
       //wsprintfA(Mode, "%S", L"Name");
       //LPWSTR filepath;
       //LPWSTR Mode;

//hr = WcaGetProperty(L"Name", &filepath);
//hr = WcaGetProperty(L"Mode", &Mode);
       WcaLog(LOGMSG_STANDARD, "Initialized.");
       Createnewfile("C://shashi.txt", "w");

       // TODO: Add your custom action code here.


LExit:
       er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
       return WcaFinalize(er);
}

product.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="Testapp" Language="1033" Version="1.0.0.0" Manufacturer="Intel" UpgradeCode="37b2e1fe-dc59-41d8-9ee8-c5601dc4e1d9">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." Schedule="afterInstallFinalize"/>
    <Media Id="1" Cabinet="Product.cab" EmbedCab="yes" />
   </Product>

    <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="Testapp" >
          <Component Id="ProductComponent" Guid="19bf71c2-30e3-4e57-8dec-11889b81bab3">
            <File Id="Testapp" Name="Testapp.exe" Source="..\Testapp\Debug\Testapp.exe" KeyPath="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>
    </Fragment>

  <Fragment>
    <Binary Id='CustomCreateBinary' SourceFile='..\Testappcustomaction\bin\Debug\Testappcustomaction.dll'/>
    <CustomAction Id='CustomCreate' BinaryKey='CustomCreateBinary' DllEntry='Createfile' Execute='immediate'   Return='check'/>
  </Fragment>

  <Fragment>
  <InstallUISequence>
    <Custom Action="CustomCreate" After="InstallFiles"></Custom>
  </InstallUISequence>
  <InstallExecuteSequence>
    <Custom Action="CustomCreate" After="InstallFiles"></Custom>
  </InstallExecuteSequence>
  </Fragment>
</Wix>


Thanks and Regards,
Shashikala



More information about the wix-users mailing list