DLL calling its own functions?

Can a Windows DLL exported function call another exported function of the same DLL? For example:
__declspec(dllexport) int __cdecl Function1();
__declspec(dllexport) int __cdecl Function2();
....
__declspec(dllexport) int __cdecl Function1() { return Function2(); }
__declspec(dllexport) int __cdecl Function2() { return 102; }


Most importantly, if this IS allowed. Is the call made by Function1 to Function2 done directly, or would it be called via the current process's JMP table for the DLL.

Ratchetr2011-06-19T07:44:05Z

Favorite Answer

The answer to the first question is yes, no problem for a DLL to call it's exported functions.

There is no guarantee that the call will be made through the jump table (aka the IAT).

One scenario where it definitely won't call through the jump table is if the compiler decides to inline the call, which it is free to do.

If you compile the above code in release mode with VS2010, the generated code for Function1 is:
mov eax,102
ret

So, no call through the jump table there.