"Bad arg list in user block" error using MinGW gcc
Submitted by Joe on Thu, 06/13/2013 - 22:32
Hi,
A few years ago we created a .dll in Visual C++ to be used with visSim userFunction blocks. We are now moving all of our Visual C++ projects over to MinGW gcc.
After making a few changes to the code that builds in Visual C++ (see below) the dll builds in MinGW gcc and we can connect the resulting dll to a userFunction block.
The issue is this: When we click the green go button to start the simulation we get this error message box in VisSim:
'Bad arg list in user block C:...\libvisSimInterface.dll.readDP'.
Otherwise, after we click Ignore, the dll appears to be working. The second input is passed straight to the output as expected and is displayed in a display block connected to the output of the userFunction block.
What is causing this error message?
When we disconnect the display block from the output of the userFunction block the error message goes away.
Our sample code looks like this:
EXPORT32 void PASCAL readDP(double param[],double inSig[], double outSig[]) { outSig[0] = inSig[1]; // put the second input directly into the output return; }
Thanks for your help
Answers
-
Submitted by Anders89 on Thu, 06/13/2013 - 23:04.
VisSim uses __stdcall for user exported functions. This differs from the default '__cdecl'. If you use __cdecl, the VisSim stack will become corrupted. It may appear to work for a while, but eventually you will get an error. VisSim issues your error when it detects such stack corruption.
You mention that you changed the code. All you need to do is make sure that you define '_WIN32' and you should get __stdcall declarator via the VisSim vsuser.h file where it defines 'PASCAL' as __stdcall.0 -
Submitted by visSimilated on Thu, 06/13/2013 - 23:49.
Thanks for the response!
I made sure that _WIN32 is defined in my project and I changed my function prototypes back to how they build in Visual C++:
EXPORT32 void PASCAL readDP(double param[],double inSig[], double outSig[]){
Unfortunatly, now I'm back to the point where I get the 'Can't find 'readDP' in C:........\libvisSimInterface.dll'
0 -
Submitted by Anders89 on Sat, 06/22/2013 - 00:40.
OK, the problem is that MinGW uses a slightly different naming convention from MSVC. It does not prepend an '_' when decorating the function name. So the best way to get the interface to work with MinGW is to use the *__stdcall* attribute as you are doing, but apply the '--kill-at' ld option to remove the function decoration entirely.
0