views:

29

answers:

2

I am trying to copy file into the setup target directory.

I am using this:

TCHAR destPath[ MAX_PATH ] = &L"[TARGETDIR]";
wcscat_s(destPath, L"[email protected]\\Capture.png");
CopyFile(L"C:\\Users\\waldek\\Desktop\\Capture.png", destPath, 0); 

if I use this:

CopyFile(L"C:\\Users\\waldek\\Desktop\\Capture.png", L"C:\\Program Files (x86)\\Microsoft\\Setup1\\[email protected]\\Capture.png", 0); 

it works, which is basically what destPath should evaluate to, I can see that it evaluates when I use PMSIHANDLE, it alerts the correct path...

How do I force CopyFile to evalue "[TARGETDIR]";

A: 
WCHAR vbuff [MAX_PATH] = {0};

DWORD vlen = MAX_PATH;
UINT gp = MsiGetPropertyW(hInstall, L"CustomActionData", vbuff, &vlen);

in the Install Custom Action in property CustomactionData, I just put [TARGETDIR]

vbuff is the target directory

then of course the concatenation and the FileCopy executed as expected...

this worked for me... but I still would like to know why, it didn't in the original question I posted, the strangest thing was that the PMSIHANDLE wrote out the correct path, but I guess there "translation" step was missing in passing it in the FileCopy function...

I am sure I am missing some theory on this.

A: 

Assuming this is part of a custom action, you can use MsiFormatRecord. Error handling omitted, it would look something like this:

PMSIHANDLE hRec = MsiCreateRecord(1);
MsiRecordSetString(hRec, 0, _T("[TARGETDIR][email protected]"));

TCHAR szPath[MAX_PATH] = {0};
DWORD cchPath = MAX_PATH;
MsiFormatRecord(hInstall, hRec, szPath, &cchPath);
Michael Urman

related questions