I am using IPC for shared memory.
我正在使用IPC来共享内存。
I need to turn on another program with IPC, but I want to know how to pass arguments.
我需要用IPC打开另一个程序,但我想知道如何传递参数。
Below is a execute function for my IPC class.
下面是我的IPC类的执行函数。
int execute(std::string exePath, std::string exeName, int console = 1)
{
SHELLEXECUTEINFOA p_info;
ZeroMemory(&p_info, sizeof(SHELLEXECUTEINFOA)); //초기화
p_info.cbSize = sizeof(SHELLEXECUTEINFOA);
p_info.lpFile = exeName.c_str(); // 파일 이름
p_info.lpDirectory = exePath.c_str(); //파일 위치
p_info.nShow = console; //콘솔 show
p_info.fMask = SEE_MASK_NOCLOSEPROCESS;
return ShellExecuteEx(&p_info);
};
1 个解决方案
#1
2
Arguments are passed using the lpParameters
member of SHELLEXECUTEINFO
.
使用SHELLEXECUTEINFO的lpParameters成员传递参数。
Some other comments:
其他一些评论:
- Since you are explicitly using the ANSI version of the struct,
SHELLEXECUTEINFOA
, it would be appropriate to do the same for the function call and useShellExecuteExA
. - 由于您明确使用结构的ANSI版本SHELLEXECUTEINFOA,因此对函数调用执行相同操作并使用ShellExecuteExA是合适的。
- Avoid the call to
ZeroMemory
by initialising the struct as part of the declaration:SHELLEXECUTEINFOA p_info = { 0 };
- 通过初始化结构作为声明的一部分来避免调用ZeroMemory:SHELLEXECUTEINFOA p_info = {0};
- You use
SEE_MASK_NOCLOSEPROCESS
but then fail to close the process handle. This is a handle leak. - 您使用SEE_MASK_NOCLOSEPROCESS但无法关闭进程句柄。这是一个手柄泄漏。
- Unless you use
ShellExecuteEx
with therunas
verb to elevate the process, it would seem more appropriate to callCreateProcess
. Why askShellExecuteEx
to callCreateProcess
when you can do so directly? - 除非您使用带有runas谓词的ShellExecuteEx来提升进程,否则调用CreateProcess似乎更合适。为什么要在可以直接执行此操作时请求ShellExecuteEx调用CreateProcess?
#1
2
Arguments are passed using the lpParameters
member of SHELLEXECUTEINFO
.
使用SHELLEXECUTEINFO的lpParameters成员传递参数。
Some other comments:
其他一些评论:
- Since you are explicitly using the ANSI version of the struct,
SHELLEXECUTEINFOA
, it would be appropriate to do the same for the function call and useShellExecuteExA
. - 由于您明确使用结构的ANSI版本SHELLEXECUTEINFOA,因此对函数调用执行相同操作并使用ShellExecuteExA是合适的。
- Avoid the call to
ZeroMemory
by initialising the struct as part of the declaration:SHELLEXECUTEINFOA p_info = { 0 };
- 通过初始化结构作为声明的一部分来避免调用ZeroMemory:SHELLEXECUTEINFOA p_info = {0};
- You use
SEE_MASK_NOCLOSEPROCESS
but then fail to close the process handle. This is a handle leak. - 您使用SEE_MASK_NOCLOSEPROCESS但无法关闭进程句柄。这是一个手柄泄漏。
- Unless you use
ShellExecuteEx
with therunas
verb to elevate the process, it would seem more appropriate to callCreateProcess
. Why askShellExecuteEx
to callCreateProcess
when you can do so directly? - 除非您使用带有runas谓词的ShellExecuteEx来提升进程,否则调用CreateProcess似乎更合适。为什么要在可以直接执行此操作时请求ShellExecuteEx调用CreateProcess?