08-07-2007 04:15 AM
08-07-2007 10:02 AM
I'm not sure which part of the documentation recommends against extern "C", but I'm guessing it does that because if you don't use extern "C" in MSVC++ on a static function, TestStand might be able to decode the prototype from the MSVC++ mangled name decoration.
If you need to use extern "C" for cross compiler compatibility, that is fine. You'll just have to enter the prototype yourself in TestStand.
You can't always correctly determine the calling convention from a DLL export name, but fortunately TestStand does not need this information. TestStand always restores the stack pointer after a DLL call so that the stack is guaranteed to be cleaned up no matter which convention the code module uses.
08-07-2007 01:48 PM
Thanks James.
From where do you take the information that "TestStand always restores the stack pointer after a DLL call ..." ?
Guenter
08-07-2007 01:58 PM
I'm a developer on the TestStand team and I worked on that feature.
Maybe we should document that. On the other hand, since it is a low level detail and it works without the need to understand it, documenting it might create more confusion than it eliminates.
08-07-2007 02:09 PM
You are right, James. As TestStand now handles this calling convention issue properly I don't see any need to explicitely write it down in the documentation, either.
I got curious because some years ago I have been wasting hours on configuring the DLL adapter in TestStand 1 when dealing with DLLs created by different programmers.
Do you remember which version of TestStand introduced this calling convention check?
Guenter
08-07-2007 02:13 PM
08-07-2007 04:02 PM
08-08-2007 02:28 PM
cdecl and stdcall use the same order, right to left.
The pascal calling convention is the one that passes parameters left to right. However, it pretty much fell into disuse a long time ago after the transition from 16-bit to 32-bit Windows.
08-09-2007 12:52 AM
Ah, yes, thank you, I mixed that up. That clarifies the issue. Thanks again for your help!
Peter
12-11-2017 06:40 AM
I have a question possibly related to the DLL stack topic.
Recently I came across a case where a DLL function was called with a wrong parameter list. This seemed to have worked fine for years, but then there was a system where it crashed persistently with an 0xc0000471 exception (which is "unknown software exception").
The correct function prototype was
int Function(int);
and the call from TestStand was configured as
int Function();
Am I right to assume that the function then took some arbitrary value from the stack (which was OK as this parameter was actually obsolete) and that it worked fine most of the time because TestStand restored the stack pointer?
Regards
Peter