如何通过“LPTHREAD_START_ROUTINE lpStartAddress”创建进程相似的论点?
我想创建一个进程,其语法类似于以下内容,但我不想创建线程:
hThread = CreateThread(
NULL, // no security attribute
0, // default stack size
InstanceThread, // thread proc
(LPVOID) hPipe, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
但我检查了CreateProcess
和示例:
BOOL result = ::CreateProcess(
L"C:\\Windows\\NOTEPAD.exe",
NULL,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startupInfo,
&processInformation
);
看来我必须指定一个现有的可执行文件来创建进程?如何通过类似于 InstanceThread
的回调创建一个?
I want to create a process with syntax similar to the following,except that I don't want to create a thread:
hThread = CreateThread(
NULL, // no security attribute
0, // default stack size
InstanceThread, // thread proc
(LPVOID) hPipe, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
But I've checked the reference for CreateProcess
and a sample :
BOOL result = ::CreateProcess(
L"C:\\Windows\\NOTEPAD.exe",
NULL,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startupInfo,
&processInformation
);
It seems I must specify an existing executable to create a process? How can I create one by a callback similar to InstanceThread
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能这样做。进程和线程是不同的。您不能仅通过在可执行文件中给出函数的地址来创建进程。
但是,您可以使用进程读取的一些命令行参数来创建进程,然后使用该参数来调用您想要的目标函数。
你想达到什么目的?
You cannot do this. Processes and threads are different. You cannot create a process by just giving the address of a function in your executable.
You could, however, create your process with some command-line argument that your process reads and then uses to call the target function you want.
What are you trying to achieve?
也许看看 cygwin 如何实现 fork() 。 Unix
fork()
就是您想要的。Perhaps look how cygwin implements
fork()
. Unixfork()
is what you want here.