gpt4 book ai didi

c++ 到 vb.net,回调函数的问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:44 25 4
gpt4 key购买 nike

我在这里很难找到解决我问题的方法。

我正在尝试将客户端 API 功能从 C++ 转换为 VB.NET,我认为回调函数存在一些问题。

部分C++代码:

类型定义结构{

BYTE    m_bRemoteChannel;
BYTE m_bSendMode;
BYTE m_nImgFormat; // =0 cif ; = 1 qcif
char *m_sIPAddress;
char *m_sUserName;
char *m_sUserPassword;
BOOL m_bUserCheck;
HWND m_hShowVideo;

}CLIENT_VIDEOINFO, *PCLIENT_VIDEOINFO;

CPLAYER_API LONG __stdcall MP4_ClientStart(PCLIENT_VIDEOINFO pClientinfo,void(CALLBACK *ReadDataCallBack)(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize));

void CALLBACK ReadDataCallBack(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize)

{ TRACE("%d\n",nPacketSize);

    .....
aa5.m_sUserName = "123";
aa5.m_sUserPassword="w";
aa5.m_bUserCheck = TRUE;

MP4_ClientSetTTL(64);
nn1 = MP4_ClientStart(&aa5,ReadDataCallBack);
if (nn1 == -1)
{
MessageBox("error");
return;
}

SDK 说明:

  1. MP4_ClientStart

这个函数启动一个连接。调用格式为:

LONG __stdcall MP4_ClientStart(PCLIENT_VIDEOINFO pClientinfo,void(*ReadDataCallBack)(DWORD nChannel,UCHAR *pPacketBuffer,DWORD nPacketSize))

参数pClientinfo 保存信息。这种联系。

nChannel 持有卡片的 channel 。

pPacketBuffer 持有指向接收缓冲区的指针。

nPacketSize 保存接收缓冲区的长度。

返回值如果函数成功,则返回值是此连接的上下文。如果函数失败,返回值为 -1。

备注

类型定义结构{

字节 m_bRemoteChannel;

字节 m_bSendMode;

字节 m_bImgFormat;

字符*m_sIP地址;

字符 *m_s用户名;

字符 *m_sUserPassword;

BOOL m_bUserCheck;

HWND m_hShowVideo;

} CLIENT_VIDEOINFO, * PCLIENT_VIDEOINFO;

m_bRemoteChannel 持有客户端想要连接的 channel 。

m_bSendMode 保存连接的网络模式。

m_bImgFormat : 图片格式,0为主 channel 视频,1为副 channel 视频

m_sIPAddress 保存服务器的 IP 地址。

m_sUserName 保存用户名。

m_sUserPassword 保存用户的密码。

m_bUserCheck 保存是否发送用户名和密码的值。

m_hShowVideo 持有此视频窗口的句柄。

如果m_hShowVideo为NULL,则客户端只录制不带解码器。

如果 m_bUserCheck 为 FALSE,我们将发送 m_sUserName 和 m_sUserPassword 作为 NULL,否则我们将每 50 个字节发送一次。

m_sIPAddress和m_sUserName的长度必须大于50字节。

ReadDataCallBack:当库从服务器接收到数据包时,调用此回调。


我的 VB.Net 代码:

导入 System.Runtime.InteropServices

公开课Form1

Const WM_USER = &H400

Public Structure CLIENT_VIDEOINFO
Public m_bRemoteChannel As Byte
Public m_bSendMode As Byte
Public m_bImgFormat As Byte
Public m_sIPAddress As String
Public m_sUserName As String
Public m_sUserPassword As String
Public m_bUserCheck As Boolean
Public m_hShowVideo As Long 'hWnd
End Structure


Public Declare Function MP4_ClientSetNetPort Lib "hikclient.dll" (ByVal dServerPort As Integer, ByVal dClientPort As Integer) As Boolean
Public Declare Function MP4_ClientStartup Lib "hikclient.dll" (ByVal nMessage As UInteger, ByVal hWnd As System.IntPtr) As Boolean


<DllImport("hikclient.dll")> Public Shared Function MP4_ClientStart(ByVal Clientinfo As CLIENT_VIDEOINFO, ByRef ReadDataCallBack As CALLBACKdel) As Long
End Function


Public Delegate Sub CALLBACKdel(ByVal nPort As Long, <MarshalAs(UnmanagedType.LPArray)> ByRef pPacketBuffer As Byte(), ByVal nPacketSize As Long)


Public Sub CALLBACK(ByVal nPort As Long, <MarshalAs(UnmanagedType.LPArray)> ByRef pPacketBuffer As Byte(), ByVal nPacketSize As Long)
End Sub


Public mydel As New CALLBACKdel(AddressOf CALLBACK)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Clientinfo As New CLIENT_VIDEOINFO()
Clientinfo.m_bRemoteChannel = 0
Clientinfo.m_bSendMode = 0
Clientinfo.m_bImgFormat = 0
Clientinfo.m_sIPAddress = "193.168.1.100"
Clientinfo.m_sUserName = "1"
Clientinfo.m_sUserPassword = "a"
Clientinfo.m_bUserCheck = False
Clientinfo.m_hShowVideo = Me.Handle 'Nothing


MP4_ClientSetNetPort(850, 850)
MP4_ClientStartup(WM_USER + 1, Me.Handle)

MP4_ClientStart(Clientinfo, mydel)
End Sub

下课


下面是一些其他的代码示例:

C#

http://blog.csdn.net/nenith1981/archive/2007/09/17/1787692.aspx

VB

://read.pudn.com/downloads70/sourcecode/graph/250633/MD%E5%AE%A2%E6%88%B7%E7%AB%AF%28VB%29/hikclient.bas__.htm

://read.pudn.com/downloads70/sourcecode/graph/250633/MD%E5%AE%A2%E6%88%B7%E7%AB%AF%28VB%29/Form1.frm__.htm

德尔福

://read.pudn.com/downloads91/sourcecode/multimedia/streaming/349759/Delphi_client/Unit1.pas__.htm

最佳答案

这不是您问题的完整解决方案,但我将从将 StructLayoutAttribute(Sequential) 添加到您的结构开始。

Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure CLIENT_VIDEOINFO

关于c++ 到 vb.net,回调函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2450557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com