PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Enum question
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Enum question
![]() |
Enum question |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

