LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Enum declaration error message

I am trying to include a DLL from a 3rd party vendor and when I try to create the *.lib file from the dll and header file, I get the error message "found identifier, expecting ;". This DLL was created in VC++.
 
After further investigation, it appears the error messages is coming from a enum type declaration.
 
The header file for instance says:
 
enum STATUS { Pass = 1, Fail = 0 };
 
then it calls a function
 
Test_Status STATUS Get_Position(int x, int y);
 
The compile error occurs at the Get_Position call and when I change STATUS to an int it works fine, but I would like to keep the integraty of the DLL and use it as it is.
 
I just want to know what is the reason for the error message and what can I do to fix it?
 
Thanks
 
 
 
0 Kudos
Message 1 of 3
(3,721 Views)
geek -

Inconsistency in how enumerated types are handled is a known problem with DLL's. 

C and C++ treat enum types differently.  See H & S section 5.13.1.

CVI thinks an enum is a 4 byte integer.  I'm not sure what representation VC++ uses, C++ treats enum types as a separate type, but implicitly converts between enums and ints.  

NI pretty much says don't use enums as parameters / returned values that have to pass between your dll and your application if they've been implemented using different compilers 😉  See the "Compatability issues in DLLs" section of CVI help.

So I think changing the DLL to pass an int type is in line with how NI would say to solve this, though maybe someone from NI will answer your question better than I.

Menchar


0 Kudos
Message 2 of 3
(3,715 Views)
Geek,

Looking at the prototype for that function, I'm not sure what Test_Status is supposed to be.  It looks like the intent of the function is to simply return type STATUS. 

Assuming that is the case and that Test_Status is either erroneous or non-essential (perhaps typedef'ed as __cdecl or something), the prototype should work as

enum STATUS Get_Position(int x, int y);

Note that the keyword "enum" is required when using an enumerated variable to signify to a C compiler that the variable type is an enum.  If you would like to modify this so that you do not have to type "enum STATUS" for each instance, you can change the enum declaration to be typedef'ed.

typedef enum STATUS { Pass=1, Fail = 0 } VAR;

In this way, the prototype could read:

VAR Get_Position(int x, int y);
Thanks,

Andy McRorie
NI R&D
0 Kudos
Message 3 of 3
(3,691 Views)