LAVA Forums Buy cool LAVA gear Forums RSS Feed

Welcome Guest ( Log In | Register )

Tags
This content has not been tagged yet

> Related links

Visit our LabVIEW Wiki External Code Portal.


 
Reply to this topic Start new topic
> How to call a dll that has an ENUM definition
george seifert
post Apr 3 2008, 08:32 PM
Post #1


Very Active
***

Member
Posts: 220
Joined: 19-August 05
From: Minneapolis, MN
Member No.: 2786
Using LabVIEW Since:1995
LV:8.20 ,. ,.
United States Nothing Selected Nothing Selected


I'm calling a dll that has an ENUM in the definition. I've included a snippet of the code example they sent for Visual Basic. What I can't figure out is what size to declare for the ENUM. Is it 8, 16 or 32 bits?

' Set Measurement Mode
Public Enum LKIF_MEASUREMODE
LKIF_MEASUREMODE_NORMAL ' normal
LKIF_MEASUREMODE_HALF_T ' translucent object
LKIF_MEASUREMDOE_TRAN_1 ' transparent object
End Enum

Public Declare Function LKIF_GetMeasureMode Lib "LkIF.dll" (ByVal HeadNo As Long, ByRef MeasureMode As LKIF_MEASUREMODE) As Long

George


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Ad
post Apr 3 2008, 08:32 PM
Post #















Tags
This content has not been tagged yet
Go to the top of the page
Quote Post
ned
post Apr 3 2008, 09:36 PM
Post #2


Very Active
***

Member
Posts: 120
Joined: 26-January 06
From: Cambridge, MA
Member No.: 3989
Using LabVIEW Since:1999
LV:8.5 ,8.6 ,.
United States us_massachusetts Nothing Selected


According to this MSDN page, "If no underlying type is explicitly declared, Int32 (Integer in Visual Basic) is used implicitly."


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
george seifert
post Apr 4 2008, 02:09 PM
Post #3


Very Active
***

Member
Posts: 220
Joined: 19-August 05
From: Minneapolis, MN
Member No.: 2786
Using LabVIEW Since:1995
LV:8.20 ,. ,.
United States Nothing Selected Nothing Selected


QUOTE (ned @ Apr 3 2008, 04:36 PM) *
According to this MSDN page, "If no underlying type is explicitly declared, Int32 (Integer in Visual Basic) is used implicitly."


Nice to know it's mostly guess work when it comes to ENUMs. I tried guessing Int32 and it worked. Thanks.

George


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Apr 4 2008, 07:38 PM
Post #4


LV R&D Envoy
*****

NI
Posts: 1203
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (ned @ Apr 3 2008, 04:36 PM) *
According to this MSDN page, "If no underlying type is explicitly declared, Int32 (Integer in Visual Basic) is used implicitly."

That's true only on a 32-bit system. I'm pretty certain that on a 64-bit system, the default would be int64. And that's only with the MSVC++ compiler. I'm pretty sure that the c++ standard doesn't require any particular standard when the size isn't defined, so some compilers may not conform to this. You'd need to know the compiler used to build the DLL.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
rolfk
post Apr 7 2008, 07:30 AM
Post #5


Extremely Active
****

Premium Member
Posts: 978
Joined: 9-April 04
From: Rotterdam
Member No.: 349
Using LabVIEW Since:1992
LV:8.5.1 ,8.2.1 ,7.1.1
Netherlands Switzerland Nothing Selected


QUOTE (Aristos Queue @ Apr 4 2008, 02:38 PM) *
That's true only on a 32-bit system. I'm pretty certain that on a 64-bit system, the default would be int64. And that's only with the MSVC++ compiler. I'm pretty sure that the c++ standard doesn't require any particular standard when the size isn't defined, so some compilers may not conform to this. You'd need to know the compiler used to build the DLL.


Actually Standard C uses normally the smallest integer that can contain the highest valued enum.
Maybe C++ changed that in favor for the int dataype.

So

typedef enum {
zero,
one,
two,
three
};

will usually be an int8

To force a specific int size one often defines a dummy value:

typedef enum {
zero,
one,
two,
three,
maxsize = 66000
};

will make sure it is an int32

Rolf Kalbermatter


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
ned
post Apr 7 2008, 03:08 PM
Post #6


Very Active
***

Member
Posts: 120
Joined: 26-January 06
From: Cambridge, MA
Member No.: 3989
Using LabVIEW Since:1999
LV:8.5 ,8.6 ,.
United States us_massachusetts Nothing Selected


QUOTE (george seifert @ Apr 4 2008, 10:09 AM) *
Nice to know it's mostly guess work when it comes to ENUMs. I tried guessing Int32 and it worked. Thanks.


It shouldn't need to be guesswork; VisualBasic provides a way to explicitly specify the representation, using the "Public Enum [Name] as [Type]" syntax. Since the VisualBasic enum definition you provided doesn't specify a type, it's safe to assume it's an I32.


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Apr 7 2008, 03:19 PM
Post #7


LV R&D Envoy
*****

NI
Posts: 1203
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (ned @ Apr 7 2008, 10:08 AM) *
Since the VisualBasic enum definition you provided doesn't specify a type,

DOH! Everyone on the thread just assumed that text meant C++. I didn't even really think about the syntax there -- just assumed you had some interesting macros. Important tip: When posting code from a non-LV language, make sure to tell everyone really loud which language it is you're posting! :-)

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
rolfk
post Apr 9 2008, 06:46 AM
Post #8


Extremely Active
****

Premium Member
Posts: 978
Joined: 9-April 04
From: Rotterdam
Member No.: 349
Using LabVIEW Since:1992
LV:8.5.1 ,8.2.1 ,7.1.1
Netherlands Switzerland Nothing Selected


QUOTE (rolfk @ Apr 7 2008, 03:30 AM) *
Actually Standard C uses normally the smallest integer that can contain the highest valued enum.
Maybe C++ changed that in favor for the int dataype.

So

typedef enum {
zero,
one,
two,
three
};

will usually be an int8

To force a specific int size one often defines a dummy value:

typedef enum {
zero,
one,
two,
three,
maxsize = 66000
};

will make sure it is an int32


There is actually one other aspect here that is important. While C and I do believe C++ will use the smallest integer that can hold the biggest enum value, there is also something called padding. This means skalar elements inside a struct will be aligned to a multiple of the element data size or the data alignment specified through a #pragma statement or passed to the C compiler as parameter, whichever is smaller.

So in the case of above enum type which would result in an int8 and following structure

struct {
enum one_three elm;
float something;
}

"something" will be aligned to a 32 bit boundary with all modern C compilers when using the default alignment (usually 8 bytes).

So the C compiler will in fact create a struct containing an 8 bit integer, 3 padding filler bytes and then a 32 bit float. Treating the enum as int32 in that case will be only correct if the memory was first initialized to be all 0 before the (external code) filled in the values and also only on little endian machines (Intel x86).

Rolf Kalbermatter


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   1 seckley 5501 20th December 2002 - 04:36 AM
Last post by: Michael_Aivaliotis
No New Posts   1 Ruud 1600 8th September 2004 - 02:33 PM
Last post by: Jim Kring
No New Posts   4 m3nth 1863 27th June 2005 - 08:00 AM
Last post by: rolfk
No New Posts   3 Azazel 1633 2nd December 2004 - 06:57 AM
Last post by: didierj


Reply to this topicStart new topic

 




Time is now: 16th October 2008 - 08:20 PM