Closed

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

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.

?

Skills: Engineering, Microsoft, MySQL, PHP, Project Management, Software Architecture, Software Testing, Windows Desktop

See more: union find, set union, php examples with source code, my code, i need help in programmer, find programmer code, find php programmer wanted, find a windows programmer, find a windows application developer, application developer wanted, x64, programmer help wanted, managed, fixed, code c, c guess, c dll, c developer, bridging, bool, signature dll, byte time, source code build, source code missing, extern

About the Employer:
( 2 reviews ) United States

Project ID: #3345900

4 freelancers are bidding on average $697 for this job

gmit2

See private message.

$170 USD in 14 days
(82 Reviews)
7.7
canlevw

See private message.

$2550 USD in 14 days
(55 Reviews)
6.8
savager

See private message.

$51 USD in 14 days
(97 Reviews)
6.6
jo0lsvw

See private message.

$17 USD in 14 days
(3 Reviews)
1.5