简体   繁体   English

在C ++中获取执行目录

[英]Get executing directory in C++

I have a .CAB file that runs as part of an installer process on a Windows CE box. 我有一个.CAB文件作为Windows CE框上的安装程序进程的一部分运行。 The CAB is written in C++. CAB是用C ++编写的。

The CAB file is ran twice as part of an upgrade process but in different locations at different times. CAB文件作为升级过程的一部分运行两次,但在不同时间在不同位置运行。 How can I find out what directory the .CAB file is being executed from (executing directory) using C++ only? 如何才能使用C ++找出正在执行.CAB文件的目录(执行目录)?

Thanks 谢谢

If by "C++ only" you mean without using Windows API, I don't think the standard library has a function to do that. 如果仅使用“C ++”意味着不使用Windows API,我认为标准库没有这样做的功能。

If you can call a Win32 API, you just have to call GetModuleFileName() with NULL as the first parameter, and you will get the path of the current executable. 如果您可以调用Win32 API,则只需调用GetModuleFileName()并将NULL作为第一个参数,您将获得当前可执行文件的路径。

Now, the problem is: we you run the .CAB, what is the executable? 现在,问题是:我们运行.CAB,可执行文件是什么? The install DLL extracted from the .CAB, or the shell component that is running the .CAB? 从.CAB中提取的安装DLL,或运行.CAB的shell组件?

You can also try GetCommandLine() , as the first entry should be the executable path/name (it is actually the string passed to CreateProcess() , so you can't be 100% sure about it). 您也可以尝试GetCommandLine() ,因为第一个条目应该是可执行路径/名称(它实际上是传递给CreateProcess()的字符串,因此您无法100%确定它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM