Danilo wrote:
AFAIK Str() relies on the MS Visual C Runtime (MSVCRT.dll), and it is possible this DLL is not initialized
for this new thread/DLL yet.
Thats not the problem. Even if you wait for the initialization to finish it crashes. And it crashes on unload, not on Str(). Str() works just fine.
I think srod was right, the problem is creating a thread before the TLS is initialized.
Without threadsafe activated it works without problems to create a thread and let it wait for the initialization to finish before it does anything else. I did that in GameFixer and all works fine. Even DirectDraw initialization works fine.
However, if i activate threadsafe it also gets unstable, just tested it.
So the rule is: Don't create threads in the AttachProcess procedure if you are using threadsafe.
I may change the way the thread in GameFixer is created, who knows what problems are still lurking related to that. ^^
I did it because it was the easiest way. Because the DLL is injected it's much more complicated to create the thread from the injector. Need to get the procedure address inside the games process and create another remote thread.
Thats how i wait for the initialization to finish:
Code:
Procedure InitCore(hAttachProcessThread.i)
;wait for AttachProcess thread to finish
WaitForSingleObject_(hAttachProcessThread, #INFINITE)
EndProcedure
ProcedureDLL AttachProcess(Instance.i)
Protected hAttachProcessThread.i
Protected hProcess.i
;get the handle to the thread to enable the init procedure to wait for it's termination
hProcess = GetCurrentProcess_()
DuplicateHandle_(hProcess, GetCurrentThread_(), hProcess, @hAttachProcessThread, 0, #False, #DUPLICATE_SAME_ACCESS)
CreateThread(@InitCore(), hAttachProcessThread)
EndProcedure