Please tell me how make this work irrespective of 32 bit or 64-bit process.
Why do you need this? There is the documented approach which tells - create a separate 64 bit app which will interact with 64 bit app. You could to create a thread from a 32 bit app as well but this is quite complex and i don't see the reason to provide the code which can be used to write malicious app.