在 C# csharp 中使用来自 ocx 控件的指针

发布于 2024-10-17 04:32:30 字数 245 浏览 5 评论 0原文

编辑: 我正在使用 C# 中的 ocx 控件。该控件具有包含数据缓冲区的长度和指向该缓冲区的指针的属性。如何通过 C# 中的某个点来访问/获取/使用该数据。我正在使用 Visual Studio 2008。

我使用 c# 中的 .ocx 控件。该 .ocx 有一个属性,其中包含数据缓冲区的 len 和指向数据缓冲区的指针。我如何在 C# 中使用该指针获取数据?我使用 VS C# 2008

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与风相奔跑 2024-10-24 04:32:30

您没有提供具体信息,因此这是根据您的信息进行的猜测。您可以在此处找到示例< /a>.我将引用(并简化)相关部分:

// 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);

编辑:用您的信息:

// .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));

至于到达事件:

// 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文