working with pointers from an ocx control in c# csharp

936 views Asked by At

Edit: I'm working with an ocx control in C#. This contrl has properties which contain the length of a data buffer and a pointer to that buffer. How can access/get/use that data with possibly a point in C#. I'm using Visual Studio 2008.

i work with .ocx control in c#. That .ocx have a properties which contains len of data buffer and pointer to data buffer. How i can get data, using that pointer in c#? I use VS C# 2008

2

There are 2 answers

3
Daniel Rose On BEST ANSWER

You didn't give exact details, so this is a guess based on your info. You can find an example here. I'll quote (and simplify) the relevant parts:

// C/C++
int ncWrite(unsigned long DataSize, void* DataPtr)

// C#
[DllImport("Nican.dll")]
unsafe static extern int ncWrite(uint DataSize, byte[] DataPtr);

byte[] DataWrite = {0x23, 0x23, 0x30, 0x03, 0x78, 0xEC, 0xFF, 0xFF };
int status = ncWrite(Marshal.SizeOf(DataWrite), DataWrite);

EDIT: With your info:

// .ocx
Public Function WriteData(ByVal devIndex As Long, ByVal lpOutData As Long, ByVal cntData As Long) As Long

// C#
[DllImport("TheOcxControl.dll")]
static extern int WriteData(int index, byte[] outputData, int outputDataLength);

byte[] DataToWrite = {0x23, 0x23, 0x30, 0x03, 0x78, 0xEC, 0xFF, 0xFF };
int status = WriteData(index, DataToWrite, Marshal.SizeOf(DataToWrite));

As for the arrival event:

// the e variable have devIndex, lenDataBufer, lpDataBufer properties.
// lenDataBufer is size of buffer, lpDataBufer is pointer to data array.
byte[] destination;
Marshal.Copy(lpDataBufer, destination, 0, lenDataBufer);
0
Mubashir Khan On