global-init.cxx 中代码,使用 QueueUserAPC, windows的异步线程调度方式,可以避免dllmain的限制。
Adds a user-mode asynchronous procedure call (APC) object to the APC queue of the specified thread.
Syntax
C++复制
DWORD QueueUserAPC(
PAPCFUNC pfnAPC,
HANDLE hThread,
ULONG_PTR dwData
);
Parameters
pfnAPC
A pointer to the application-supplied APC function to be called when the specified thread performs an alertable wait operation. For more information, see APCProc.
hThread
A handle to the thread. The handle must have the THREAD_SET_CONTEXT access right. For more information, see Synchronization Object Security and Access Rights.
dwData
A single value that is passed to the APC function pointed to by the pfnAPC parameter.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. Windows Server 2003 and Windows XP: There are no error values defined for this function that can be retrieved by calling GetLastError.