I'm not an expert C++ Programmer, but I don't understand where is my error. I have also seen all example in the help like SerialValidation and I think to have done the same, but it doesn't work correctly.
Here is the C++ DLL code:
Code: Select all
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <msi.h>
#include <MsiDefs.h>
#include <MsiQuery.h>
#include <tchar.h>
#include <stdlib.h>
using namespace std;
#define DLL extern "C" __declspec(dllexport)
DLL int writeProgramConfig(MSIHANDLE hInstall){
TCHAR pathProgramConfig[1000];
DWORD dwLen = sizeof(pathProgramConfig)/sizeof(pathProgramConfig[0]);
// Get the "Program.Config" path property
if(MsiGetProperty(hInstall, _T("WPC_PROGCONFIG"), pathProgramConfig, &dwLen) != ERROR_SUCCESS) return 1; //fail the installation
// Get the "K_Data" path property
TCHAR kdata[1000];
dwLen = sizeof(kdata)/sizeof(kdata[0]);
if(MsiGetProperty(hInstall, _T("PATH_KDATA"), kdata, &dwLen) != ERROR_SUCCESS) return 1; //fail the installation
// Get the "K_Data_s" path property
TCHAR kdatas[1000];
dwLen = sizeof(kdatas)/sizeof(kdatas[0]);
if(MsiGetProperty(hInstall, _T("PATH_KDATA_S"), kdatas, &dwLen) != ERROR_SUCCESS) wcscpy_s(kdatas, kdata); //K_DATA_S is K_DATA
//View if the strings are passed
ofstream myfile;
myfile.open ("C:\\Documents and Settings\\MyUser\\Desktop\\view.txt", ios::out);
myfile << "Path " << pathProgramConfig <<"\n";
myfile << "kdata " << kdata <<"\n";
myfile << "kdatas " << kdatas <<"\n";
myfile.close();
//writes the correct file
myfile.open (pathProgramConfig, ios::out);
myfile << "[WorkPathLocal]\n";
myfile << kdata;
myfile << "[WorkPathServer]\n";
myfile << kdatas;
myfile.close();
return 0;
}
PATH_KDATA is a Setup Property, it's a path to write into the file
PATH_KDATA_S is a Setup Property, it's a path to write into the file. If there isn't, then use the above with wcscpy_s function
Instead of create new Properties, can I use AI folders properties like [#Program.config]???
Or can I pass value into ActionData in Custom Actions? Have you an example?
I created an Attached Custom Action under Show Standard Action, Before Finalization, Install Files.
Sync execution, check return code.
Immediate execution.
When I launch the setup, it executes the DLL function but writes this:
Path 00C8F4F8
kdata 00C8E558
kdatas 00C8ED28
Instead I would like this one:
Path C:\ProgramFiles\Installdir\Program.config
kdata C:\KDATA_path
kdatas C:\KDATA_path
Any help?
Thank you very much in advance!