Thanks everyone for their help.

It is a 32bit dll into a 32 bit process.

I am calling setwindowshookex in my exe not dll.

If i change the threadId to 0 (i assume you mean do a global system hook), then setwindowshookex does not return null but only injects the hook into some processes not all of them.

To test this I changed the threadid in setwindowshookex to my running visual studio exe and everything worked fine (meaning setwindowshookex did not return null) . But as soon as I changed it back to myapp.exe threadid setwindowshookex returns null again. I also tried changing my threadid to google chrome and setwindowshookex still returns null. It seems to work with some processes like visual studio but not others like chrome.

I assume the reason why it wont inject into myapp is the same as why it wont inject into chrome. Whatever that may be.

Thanks