开发者

How to create a process by a "LPTHREAD_START_ROUTINE lpStartAddress" alike argument?

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 ?


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?


Perhaps look how cygwin implements fork(). Unix fork() is what you want here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜