Allocating memory for function pointers [modified]
-
Hi, I am working in a porting project where i have to convert the thread local variables (declared with __declspec(thread)) to TLS allocations (using TLS APIs). I am able to do it for variables. How to do it for function pointers? (thread local function pointers) for example, I have a thread local function pointer declared as, __declspec(thread) BOOL (WINAPI *Test)(Short a, _TCHAR b, BOOL c); Is it possible to convert this by using TLS APIs? Is it possible to allocate the memory (4 bytes) for pointer "Test"? Any help is appreciated. Thanks.
Selva
-
Hi, I am working in a porting project where i have to convert the thread local variables (declared with __declspec(thread)) to TLS allocations (using TLS APIs). I am able to do it for variables. How to do it for function pointers? (thread local function pointers) for example, I have a thread local function pointer declared as, __declspec(thread) BOOL (WINAPI *Test)(Short a, _TCHAR b, BOOL c); Is it possible to convert this by using TLS APIs? Is it possible to allocate the memory (4 bytes) for pointer "Test"? Any help is appreciated. Thanks.
Selva
Test is just a variable with type:
BOOL (WINAPI *)(Short, _TCHAR, BOOL );
so all you need to do is cast the result of you TLS allocation to that type. If you use a quick typedef it's pretty trivial:
typedef BOOL (WINAPI *test_function_ptr)( Short, _TCHAR, BOOL );
test_function_ptr Test = (test_function_ptr)malloc( sizeof( test_function_ptr ) );
Replace malloc with what ever TLS function you're using and snip, snip, Bob's your Aunty. Cheers, Ash
-
Test is just a variable with type:
BOOL (WINAPI *)(Short, _TCHAR, BOOL );
so all you need to do is cast the result of you TLS allocation to that type. If you use a quick typedef it's pretty trivial:
typedef BOOL (WINAPI *test_function_ptr)( Short, _TCHAR, BOOL );
test_function_ptr Test = (test_function_ptr)malloc( sizeof( test_function_ptr ) );
Replace malloc with what ever TLS function you're using and snip, snip, Bob's your Aunty. Cheers, Ash