Unified Touch driver dll implementation in c#

I have installed Unified Touch driver and after that I have create a program using c# to get touch coordinate. So now I want to pass these coordinate to Unified Touch driver dll from c# program.

Could you please provide me the correct way to import CreateFile and DeviceIoControl method from UnfdMultiTchDrv.dll which is located to Flashdisk/system after install the Unified Touch drive.

I have tried below code part :-

[DllImport(“UnfdMultiTchDrv.dll”, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int CreateFile(String lpFileName,
int dwDesiredAccess, int dwShareMode,
IntPtr lpSecurityAttributes, int dwCreationDisposition,
int dwFlagsAndAttributes, int hTemplateFile);

[DllImport("UnfdMultiTchDrv.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(
  int hDevice,
  int dwIoControlCode,
  byte[] InBuffer,
  int nInBufferSize,
  byte[] OutBuffer,
  int nOutBufferSize,
  ref int pBytesReturned,
  int pOverlapped);

But it is throwing exception due to definition of method is not correct.

I am waiting for your favorable response.

Those functions are exported by coredll.dll, not by the touch driver DLL.

Thanks for reply.

yes I have seen these functions in coredll.dll.
Could you please give me sample code to pass dummy touch coordinate (x,y) to DeviceIoControl function using c#.

And I am following “http://developer.toradex.com/knowledge-base/capacitive-multi-touch-solution”.
and here they have mentioned need to pass touch coordinate to unified touch driver (unfdtchdrv.dll).

I have got touch coordinate but I do’nt know how to pass these coordinate to next level to get completed touch.

Thanks

You can download C/C++ source code of some touch drivers here:
http://developer.toradex.com/knowledge-base/capacitive-multi-touch-solution-source-code

As you can see in hwadapt.c the driver call CreateFile to get an handle for the driver:

   hDS = CreateFile( TEXT("TCH1:"), GENERIC_READ|GENERIC_WRITE, 
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);

And then fills a data structure name CETCHINP_IOCTL with the information about touch point.
Struct is defined as follows (LONG is 32 bit signed int, DWORD is 32bit unsigned it, you can use that also for the HANDLE entry):

typedef struct {
    // Specifies the x coordinate of the touch point in 4ths of a pixel.
    LONG x;

    // Specifies the y coordinate of the touch point in 4ths of a pixel.
    LONG y;

    // Identifier of the touch input source. Reserved for use by the touch driver.
    HANDLE hSource;

    // Touch point identifier - this is the touch contact index. This ID must be
    // maintained for a contact from the time it goes down until the time it
    // goes up.
    DWORD dwID;

    // A set of bit flags that specify various aspects of touch point press /
    // release and motion.
    DWORD dwFlags;

    // A set of bit flags that specify which of the optional fields in the
    // structure contain valid values.
    DWORD dwMask;

    // Time stamp for the event, in milliseconds. If this parameter is 0,
    // the sample will be timestamped by GWES enroute to the gesture engine
    // and the TOUCHEVENTMASKF_TIMEFROMSYSTEM flag will be set in dwMask.
    DWORD dwTime;

    // Specifies the width of the touch contact area in 4ths of a pixel.
    DWORD cxContact;

    // Specifies the height of the touch contact area in 4ths of a pixel.
    DWORD cyContact;

    // Offset to an additional property structure which is associated
    // with this specific touch point. The offset is in bytes from
    // the begining of this TCHINPUT structure.
    DWORD dwPropertyOffset;

    // Size in bytes of the additional property structure.
    DWORD cbProperty;
} TCHINPUT, *PTCHINPUT;

And is passed to the touch intermediate via DeviceIoControl as you can see here:

DeviceIoControl( hDS, IOCTL_SET_TOUCH_EVENT, &CeTchInp, sizeof(CeTchInp), NULL, 0, &BytesHandled, NULL );

I suggest that you download the code of our driver here:
https://docs.toradex.com/104623-hwadapt-atmel-toradexcelibs.zip

To also get the values of the different const used in the snippets I posted.
You can use http://www.pinvoke.net/ to get C# code to reference APIs (CreateFile and DeviceIoControl from coredll, use the WindowsCE session of the website!)

Thanks again for reply.

Could you please know me the dll name of CTL_CODE(…) function from where it will import.

Thanks

It’s a macro:
https://msdn.microsoft.com/en-us/library/ee478525.aspx?f=255&MSPPError=-2147217396

Valter.tx Thanks for your efforts.

I have understand the concept but not able to convert all the code in c#.

Could you please provide me the sample code in c#.

Thank in Advance.

Sorry, but this is not something we could do with free support.