在 C++ 中设置项目自定义操作“[TARGETDIR]”

发布于 2024-09-08 19:19:52 字数 780 浏览 2 评论 0原文

我正在尝试将文件复制到安装目标目录中。

我正在使用这个:

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

如果我使用这个:

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

它可以工作,这基本上就是 destPath 应该评估的内容,我可以看到它在我使用 PMSIHANDLE 时进行评估,它会提醒正确的路径...

我如何强制 CopyFile 评估“[目标目录]";

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]";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2024-09-15 19:19:52
WCHAR vbuff [MAX_PATH] = {0};

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

在属性 CustomactionData 中的安装自定义操作中,我只是将 [TARGETDIR]

vbuff 放在目标目录中,

然后当然是按预期执行串联和 FileCopy...

这对我有用...但我仍然想知道为什么,它没有出现在我发布的原始问题中,最奇怪的是 PMSIHANDLE 写出了正确的路径,但我猜想在 FileCopy 函数中传递它时缺少“翻译”步骤......

我确信我错过了关于这一点的一些理论。

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.

秋叶绚丽 2024-09-15 19:19:52

假设这是自定义操作的一部分,您可以使用 MsiFormatRecord。省略了错误处理,它看起来像这样:

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文