views:

63

answers:

2

I have a function with the prototype

DWORD WINAPI blah(LPVOID arg);

Which was meant to be used with CreateThread for a threaded app.

I call it with CreateThread with no problem. But then somewhere else in the code, I call it normally, just by blah(NULL). When it gets to this part, it crashes. Is this because the WINAPI part makes it __stdcall and you can't just call __stdcall functions like that?

A: 

The only problem would be if blah() specifically calls TerminateThread(self) to end, instead of just returning off the bottom. The CreateThread call sets up the return address such that when blah() returns, it calls TerminateThread.

If blah() doesn't have any code like that, then an examination of the code is needed to see if it somehow does something thread specific which makes it fail. Offhand, I can't think of anything else (besides TerminateThread()) which might cause code written to be a thread which would prevent it from being called directly.

wallyk
+2  A: 

It is not because of __stdcall. Start your program in the debugger and check which line of the code gives you a crash.

Kirill V. Lyadvinsky