I have added the following functionality to an existing native C++ application:
- A 3rd party DLL is loaded via LoadLibraryA(...)
- A function pointer is obtained from the DLL via GetProcAddress(...)
- The function is called
While this basically works (the function is called alight and produces the expected output) there is one major problem: the function call (in 3.) is extremely slow. It takes over 300ms (!) to execute, while it should be less than 1 ms.
So I created a new, blank C++ application and copied the code over. So steps 1 to 3 are executed exactly the same way as in the other application. The function does the same thing and produces the same results. But the execution is much faster: less than 1 ms, as expected.
Some more observations I made:
- Both results are 100% reproducible.
- Both applications seem to have the same compiler/linker settings.
- Threading/performance issues don't seem to be the problem, since in both applications the code is executed on the main thread during very low CPU usage (not much else is going on). Also the results are reproducibly, which rules out these kind of timing issues.
- Every call into the DLL takes at least 300ms in my first application, while it's fast in the other. Thus the behavior is not limited to a single function.
- It makes no difference if I use a debug or release build.
- Both applications and the 3rd party DLL are 32bit.
So now I'm looking for an idea what could be causing both applications to behave so differently when doing exactly the same thing.