#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Pinvoke c++/vb.net structure Issue


    I am having a bit of trouble working with a SDK for elo touchscreens. The SDK is in C++ and I am writing in vb.net (because I do not know C++ very well). I am trying to pull up the diagnostics info of the screens and cannot get all of the data to return. Here is the c++ function as described in the SDK:

    Code:
    Function Name: EloGetDiagnosticsData
    int EloGetDiagnosticsData(PSCREEN_PROPERTIES pData, UINT nScrNo)
    
    Parameters: 
    pData [in]: Pointer to SCREEN_PROPERTIES structure to receive the diagnostics for the touchscreen. Please see structure definition section for SCREEN_PROPERTIES.
    
    nScrNo [in]: 0 based touchscreen number.
    
    Return Values: Returns EloSucces if the call succeeds, it returns an error code otherwise. See Error Codes section for list of error values.
    
    Remarks:
    Gets the diagnostics for the specified touchscreen. This information is also displayed in the Elo Control panel>Properties tab.
    
    Requirements 
    Included in Version 4.20 and later.
    Header: Declared in EloInterface.h; include EloInterface.h.
    Library: Use EloPubIf.lib.
    I translated it into the dll import of EloPubIf.dll:

    Code:
     <DllImport("EloPubIf.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function EloGetDiagnosticsData(ByRef data As SCREEN_PROPERTIES, ByVal ScrNo As Int32) As Int32
        End Function
    The function itself seems to be working, but the structure "SCREEN_PROPERTIES" isn't populating all of the data I need. Here is SCREEN_PROPERTIES as described by the SDK:

    Code:
    Structure Name: SCREEN_PROPERTIES
    The SCREEN_PROPERTIES structure contains the diagnostics data for the touchscreen.
    typedef struct _SCREEN_PROPERTIES
    {
    
    int iWindowsMonNo ;
    ULONG Type; 
    char Port[256];
    char SerialNumber[18];
    DWORD HardwareHandshaking ; 
    CONTRL_STAT ctrl_status; 
    LONG BaudRate;
    char crevminor;
    char crevmajor;
    char trevminor;
    char trevmajor;
    char diagcodes[8]; 
    char id[8];
    char cnt_id[8]; 
    char driver_id[32]; 
    
    }SCREEN_PROPERTIES, *LPSCREEN_PROPERTIES ;
    
    Members
    
    iWindowsMonNo: Windows monitor number associated with the touchscreen. 
    
    Type: Defines the type of touchscreen. Expected values are 
    
    USB: 0x01 
    PNP_SERIAL: 0x02 
    NT_SERIAL: 0x04
    LEGACY_SERIAL: 0x08
    RESERVED: 0xFF
    
    Port:The serial port on which this serial touchscreen device is connected. This is blank for USB.
    
    SerialNumber: Serial number for connected touchscreen. Serial numbers uniquely identify a touchscreen.
    
    HardwareHandshaking: This is used only for serial touchscreens. If it is set to 1 hardware handshaking is turned on else if it is set to 0 it is turned off.
    
    ctrl_status: Controller status returned at the time of diagnostics. Please see constants definition for CONTRL_STAT.
    
    BaudRate: This specifies the baud rate for the serial port, valid only for serial touchscreens.
    
    crevminor: Minor revision of controller.
    
    crevmajor: Major revision of controller.
    
    trevminor: Unused.
    
    trevmajor: Unused.
    
    diagcodes: The response received for the diagnostics smartest command sent to the controller.
    
    id: Elo OEM identification returned from the controller.
    
    cnt_id: Contains the response to controller id smartest command to the controller.
    
    driver_id: Driver identification / version string.
    I translated part of this into:

    Code:
        <StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
        Public Structure SCREEN_PROPERTIES
            Public iWindowsMonNo As Int32
            Public Type As Int32
            Public Port() As Byte
            <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=18)> Public SerialNumber As String
            Public HardwareHandshaking As UInt32
            Public ctrl_status As String
            Public BaudRate As Int32
            Public crevminor As Byte
            Public crevmajor As Byte
            Public trevminor As Byte
            Public trevmajor As Byte
            <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=8)> Public diagcodes As String
            <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=8)> Public id As String
            <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=8)> Public cnt_id As String
            <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=32)> Public driver_id As String
        End Structure
    As you may have noticed, not all of the structure has been properly converted, but the function is not returning an error, but instead only populates a few fields. I am using USB, so not all the fields will populate, but here is what I have returned to me:

    Code:
    		BaudRate		0	Integer		
    		cnt_id			""	String
    		crevmajor		0	Byte
    		crevminor		0	Byte
    		ctrl_status		Nothing	String
    		diagcodes		""	String
    		driver_id		""	String
    		HardwareHandshaking	0	UInteger
    		id			""	String
    		iWindowsMonNo		0	Integer
    		Port			Nothing	Byte()
    		SerialNumber		""	String
    		trevmajor		0	Byte
    		trevminor		0	Byte
    		Type			1	Integer
    As far as I can tell, "Type" and "iWindowsMonNo" are the only ones that are being updated whereas I specifically need the SerialNumber and DriverID.

    Can anyone help with this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    In the C structure, port is defined as a block of 256 bytes. In your VB mapping you've defined it as a Byte() so every field after it is mapping to the wrong part of your structure. You need to use another MarshalAsAttribute to pull out an appropriate number of bytes.

    You have a similar problem with the ctrl_status field.

    (Or so my quick glance at your code says, I don't claim to have any experience with VB)
    Last edited by OmegaZero; March 3rd, 2011 at 04:20 PM.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0
    Originally Posted by OmegaZero
    In the C structure, port is defined as a block of 256 bytes. In your VB mapping you've defined it as a Byte() so every field after it is mapping to the wrong part of your structure. You need to use another MarshalAsAttribute to pull out an appropriate number of bytes.

    You have a similar problem with the ctrl_status field.

    (Or so my quick glance at your code says, I don't claim to have any experience with VB)
    INGENIOUS!
    I think I understand now why it is so important to get every part of the structure correct. This corrected my issue.

    Thanks for the help!

IMN logo majestic logo threadwatch logo seochat tools logo