PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Enum question

Reply

Enum question

 
Thread Tools Rate Thread
Old 08-09-2006, 09:38 PM   #1
Mario
Guest
 
Posts: n/a
Default Enum question


Hi,

I am having problems passing a correct argument that was using enum.
Hopefully someone can she some light.


// C++ enum from header file for the driver
typedef enum{
Port_A,
Port_B,
Port_C,
Port_D,
} G_PORTS;

//driver method signature
INT8 GetPortState(PORTHANDLE phandle, G_PORTS port, UINT32 signal)


//C# translation of the enum
public enum G_PORTS
{
Port_A,
Port_B,
Port_C,
Port_D
}

//C# P/Invoke
[DllImport("mylib.dll")]
public static extern UInt16 GetPortState(IntPtr phandle, G_PORTS port,
UINT32 signal);

//first implementation of the method call in application
SignalRead = GetPortState(phandle, G_PORTS.Port_D, 0x10000000);

After making the method call...I was not getting what I expected and I
stepped through the code to the driver. I found out that that
arguments that I passed as G_PORTS.Port_D was passed to the driver as
G_PORTS.Port_A. Could someone explain why is so? Thanks.

-- mario

  Reply With Quote
Old 08-09-2006, 10:46 PM   #2
Guest
 
Posts: n/a
Default Re: Enum question

Why is your return UInt16 when the driver returns an INT8. Based on the
name, I would think an INT8 was 8-bits.

Also, what is sizeof(G_PORTS)? Probably 32, but It would be important to
know.


"Mario" <alphatommy@hotmail.com> wrote in message
news:1157747890.734878.68570@i42g2000cwa.googlegroups.com...
> Hi,
>
> I am having problems passing a correct argument that was using enum.
> Hopefully someone can she some light.
>
>
> // C++ enum from header file for the driver
> typedef enum{
> Port_A,
> Port_B,
> Port_C,
> Port_D,
> } G_PORTS;
>
> //driver method signature
> INT8 GetPortState(PORTHANDLE phandle, G_PORTS port, UINT32 signal)
>
>
> //C# translation of the enum
> public enum G_PORTS
> {
> Port_A,
> Port_B,
> Port_C,
> Port_D
> }
>
> //C# P/Invoke
> [DllImport("mylib.dll")]
> public static extern UInt16 GetPortState(IntPtr phandle, G_PORTS port,
> UINT32 signal);
>
> //first implementation of the method call in application
> SignalRead = GetPortState(phandle, G_PORTS.Port_D, 0x10000000);
>
> After making the method call...I was not getting what I expected and I
> stepped through the code to the driver. I found out that that
> arguments that I passed as G_PORTS.Port_D was passed to the driver as
> G_PORTS.Port_A. Could someone explain why is so? Thanks.
>
> -- mario
>



  Reply With Quote
Old 08-09-2006, 11:34 PM   #3
Mario
Guest
 
Posts: n/a
Default Re: Enum question

Hi,

You are probably right in that INT8 is an 8-bits integer, and that I
err in that it should have been INT16. That is the closest thing that
C# has to an 8-bit integer or could byte be used in this case? As far
as the size, I get 0x04 when I run sizeof(G_PORTS) so that is 32-bits.
I am still baffled why the driver has the input of Port A regardless of
what arguments I used when calling the method. Again, thanks for your
input.

-- mario



<ctacke/> wrote:
> Why is your return UInt16 when the driver returns an INT8. Based on the
> name, I would think an INT8 was 8-bits.
>
> Also, what is sizeof(G_PORTS)? Probably 32, but It would be important to
> know.
>
>
> "Mario" <alphatommy@hotmail.com> wrote in message
> news:1157747890.734878.68570@i42g2000cwa.googlegroups.com...
> > Hi,
> >
> > I am having problems passing a correct argument that was using enum.
> > Hopefully someone can she some light.
> >
> >
> > // C++ enum from header file for the driver
> > typedef enum{
> > Port_A,
> > Port_B,
> > Port_C,
> > Port_D,
> > } G_PORTS;
> >
> > //driver method signature
> > INT8 GetPortState(PORTHANDLE phandle, G_PORTS port, UINT32 signal)
> >
> >
> > //C# translation of the enum
> > public enum G_PORTS
> > {
> > Port_A,
> > Port_B,
> > Port_C,
> > Port_D
> > }
> >
> > //C# P/Invoke
> > [DllImport("mylib.dll")]
> > public static extern UInt16 GetPortState(IntPtr phandle, G_PORTS port,
> > UINT32 signal);
> >
> > //first implementation of the method call in application
> > SignalRead = GetPortState(phandle, G_PORTS.Port_D, 0x10000000);
> >
> > After making the method call...I was not getting what I expected and I
> > stepped through the code to the driver. I found out that that
> > arguments that I passed as G_PORTS.Port_D was passed to the driver as
> > G_PORTS.Port_A. Could someone explain why is so? Thanks.
> >
> > -- mario
> >


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off