|
Boost : |
From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-08-01 12:10:32
Here is version working on MSVC6. It uses definition of
IMAGE_TLS_DIRECTORY structure as defined in Platform SDK installed
together with MSVC6 (later on it has been updated to contain just 6
DWORDs). I received this code from Holger Grund, tweaked it to run with
old Platform SDK headers, added Beeps and second thread and finally
tested with MSVC6. I think that definition of _tls_used (from Holger) is
something new and useful :>
B.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef unsigned long ULONG_PTR;
namespace StaticTlsSection
{
void NTAPI tls_thread_callback( void*, DWORD dwReason, void* )
{
if(dwReason == DLL_THREAD_DETACH)
Beep(440, 100);
else if(dwReason == DLL_PROCESS_DETACH)
Beep(880, 50);
}
ULONG tls_index;
const char data_template[1] = { 0 };
//const void (NTAPI *callback_array[1])(
PIMAGE_TLS_CALLBACK callback_array[2] =
{
&tls_thread_callback,
NULL
};
extern "C" const IMAGE_TLS_DIRECTORY _tls_used;
const IMAGE_TLS_DIRECTORY _tls_used =
{
reinterpret_cast<DWORD> ( &data_template ),
reinterpret_cast<DWORD> ( (&data_template) + 1 ),
reinterpret_cast<PDWORD> ( &tls_index ),
reinterpret_cast<PIMAGE_TLS_CALLBACK *> ( &callback_array ),
0,
0
};
}
DWORD WINAPI f(void *)
{
Sleep(500);
return 0;
}
int main(int argc, char* argv[])
{
DWORD id;
HANDLE h = CreateThread(NULL, 0, &f, 0, 0, &id);
WaitForSingleObject(h, INFINITE);
CloseHandle(h);
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk