Closed

''C'' DllImport in Managed Code C# FIXED

This project received 4 bids from talented freelancers with an average bid price of $697 USD.

Get free quotes for a project like this
Employer working
Project Budget
N/A
Total Bids
4
Project Description

The "C" programmer and I worked through the DllImport issue.

## Deliverables

"C" DllImport in Managed Code C# FIXED

?

UPDATE:

The "C" programmer and I worked through the DllImport issue. The main method call looks like this:

? ? ? ? ? ? ? [DllImport("[url removed, login to view]")]

? ? ? ? ? ? ? public static extern bool SendVirtualInput(IntPtr Handle, [MarshalAs([url removed, login to view], SizeConst = 1)] INPUT_DATA[] input, Int32 bufferLength);

?

And here is the struct:

[StructLayout([url removed, login to view])]

? ? ? public struct INPUT_DATA

? ? ? {

? ? ? ? ? ? ? [FieldOffset(0)]

? ? ? ? ? ? ? public byte bType;

?

? ? ? ? ? ? ? [FieldOffset(1)]

? ? ? ? ? ? ? public byte bFlag;

?

? ? ? ? ? ? ? [FieldOffset(2)]

? ? ? ? ? ? ? public byte xCoordinate;

?

? ? ? ? ? ? ? [FieldOffset(2)]

? ? ? ? ? ? ? public byte bKeyboard1;

?

? ? ? ? ? ? ? [FieldOffset(3)]

? ? ? ? ? ? ? public byte yCoordinate;

?

? ? ? ? ? ? ? [FieldOffset(3)]

? ? ? ? ? ? ? public byte bKeyboard2;

?

? ? ? ? ? ? ? [FieldOffset(4)]

? ? ? ? ? ? ? public byte bKeyboard3;

?

? ? ? ? ? ? ? [FieldOffset(5)]

? ? ? ? ? ? ? public byte bKeyboard4;

?

? ? ? ? ? ? ? [FieldOffset(6)]

? ? ? ? ? ? ? public byte bKeyboard5;

?

? ? ? ? ? ? ? [FieldOffset(7)]

? ? ? ? ? ? ? public byte bKeyboard6;

? ? ? }

}

?

Finally the method call:

// Key down

INPUT_DATA[] theData = new INPUT_DATA[1];

theData[0].bType = StansAPI.VIRTUAL_INPUT_TYPE_KEYBOARD;

theData[0].bFlag = StansAPI.VIRTUAL_LEFT_SHIFT;

theData[0].bKeyboard1 = 0x10;

theData[0].bKeyboard2 = 0x0;

theData[0].bKeyboard3 = 0x0;

theData[0].bKeyboard4 = 0x0;

theData[0].bKeyboard5 = 0x0;

theData[0].bKeyboard6 = 0x0;

Int32 bufferLength = [url removed, login to view](theData[0]);

bool result = SendVirtualInput(busHandle, theData, bufferLength);

// key up

?

___________________________________________________

I am working with a "C" developer that has never programmed with managed code C#.? I don't have much experience working with DllImport and I am having a difficult time bridging the gap. In the past when I did work with DllImport I had plenty of examples in C# to make any method call I wanted to in my code. I need help bridging the gap so I can consume the custom "C" dll. I am working with OS Windows 7 x64.

?

·? ? ? ? ? ? ? ? I would like assistance validating the DllImport setup.

·? ? ? ? ? ? ? ? The C# application/dll must consume and work with the "C" dll.

?

From the vinput.c file I find these methods:

HANDLE OpenBusInterface()

?

void CloseBusInterface(__in HANDLE FileHandle)

?

BOOL SendVirtualInput(__in HANDLE FileHandle, __in VIRTUAL_INPUT_DATA *VirtualInput, __in ULONG BufferLength)

___________________________________________

These statements seem to work as I get a handle back BUT am I missing anything important? Additional attributes?

[DllImport("[url removed, login to view]")]

public static extern IntPtr OpenBusInterface();

?

[DllImport("[url removed, login to view]")]

public static extern void CloseBusInterface(IntPtr FileHandle);

?

I need help setting up structs in C# so I can use in the SendVirtualInput method. Here is the "C" struct. I can send you what I built when needed but you might build something more elegant in C#.

// "C code"

typedef struct _VIRTUAL_INPUT_DATA {

? ? ? ? ? ? UCHAR? bType;

? ? ? ? ? ? UCHAR? bFlags;

?

? ? ? ? ? ? union {

? ? ? ? ? ? ? ? ? ? ? ? ? struct {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UCHAR xCoordinate;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UCHAR yCoordinate;

? ? ? ? ? ? ? ? ? ? ? ? ? } MouseData;

?

? ? ? ? ? ? ? ? ? ? ? ? ? UCHAR KeyboardData[6];

? ? ? ? ? ? }ReportData;

} VIRTUAL_INPUT_DATA, *PVIRTUAL_INPUT_DATA;

?

?

Again, once I have the proper structs set up in C# I need the correct signature with SendVirtualInput. My guess is the parameters are incorrect.

[DllImport("[url removed, login to view]")]

public static extern bool SendVirtualInput(

? ? ? ? ? ? ? ? ? ? ? IntPtr FileHandle,

? ? ? ? ? ? ? ? ? ? ? INPUT_DATA[] InputBuffer,? ? ? ?

? ? ? ? ? ? ? ? ? ? ? int BufferLength);

?

The project will be complete when I have the source code working with the C dll.

This must run on Windows 7 x64 OS.

?

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online