Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ to vb.net , problems with callback function
    primarykey
    data
    text
    <p>I'm having a hard time here trying to find a solution for my problem.</p> <p>I'm trying to convert a client API funktion from C++ to VB.NET, and i think have some problems with the callback function.</p> <p>parts of the C++ code:</p> <p>typedef struct{</p> <pre><code>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; </code></pre> <p>}CLIENT_VIDEOINFO, *PCLIENT_VIDEOINFO;</p> <p>CPLAYER_API LONG __stdcall MP4_ClientStart(PCLIENT_VIDEOINFO pClientinfo,void(CALLBACK *ReadDataCallBack)(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize));</p> <p>void CALLBACK ReadDataCallBack(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize)</p> <p>{ TRACE("%d\n",nPacketSize); }</p> <pre><code> ..... aa5.m_sUserName = "123"; aa5.m_sUserPassword="w"; aa5.m_bUserCheck = TRUE; MP4_ClientSetTTL(64); nn1 = MP4_ClientStart(&amp;aa5,ReadDataCallBack); if (nn1 == -1) { MessageBox("error"); return; } </code></pre> <hr> <p>SDK description:</p> <ol start="3"> <li>MP4_ClientStart</li> </ol> <p>This function starts a connection. The format of the call is:</p> <p>LONG __stdcall MP4_ClientStart(PCLIENT_VIDEOINFO pClientinfo, void(*ReadDataCallBack)(DWORD nChannel,UCHAR *pPacketBuffer,DWORD nPacketSize))</p> <p>Parameters pClientinfo holds the information. of this connection.</p> <p>nChannel holds the channel of card.</p> <p>pPacketBuffer holds the pointer to the receive buffer.</p> <p>nPacketSize holds the length of the receive buffer.</p> <p>Return Values If the function succeeds the return value is the context of this connection. If the function fails the return value is -1.</p> <p>Remarks</p> <p>typedef struct{</p> <p>BYTE m_bRemoteChannel;</p> <p>BYTE m_bSendMode;</p> <p>BYTE m_bImgFormat;</p> <p>char *m_sIPAddress;</p> <p>char *m_sUserName;</p> <p>char *m_sUserPassword;</p> <p>BOOL m_bUserCheck;</p> <p>HWND m_hShowVideo;</p> <p>} CLIENT_VIDEOINFO, * PCLIENT_VIDEOINFO;</p> <p>m_bRemoteChannel holds the channel which the client wants to connect to.</p> <p>m_bSendMode holds the network mode of the connection.</p> <p>m_bImgFormat : Image format, 0 is main channel video, 1 is sub channel video</p> <p>m_sIPAddress holds the IP address of the server.</p> <p>m_sUserName holds the user’s name.</p> <p>m_sUserPassword holds the user’s password.</p> <p>m_bUserCheck holds the value whether sends the user’s name and password or not.</p> <p>m_hShowVideo holds Handle for this video window.</p> <p>If m_hShowVideo holds NULL, the client can be record only without decoder.</p> <p>If m_bUserCheck is FALSE, we will send m_sUserName and m_sUserPassword as NULL, else we will send each 50 bytes.</p> <p>The length of m_sIPAddress and m_sUserName must be more than 50 bytes.</p> <p>ReadDataCallBack: When the library receives a packet from a server, this callback is called.</p> <hr> <p>My VB.Net code:</p> <p>Imports System.Runtime.InteropServices</p> <p>Public Class Form1</p> <pre><code>Const WM_USER = &amp;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 &lt;DllImport("hikclient.dll")&gt; 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, &lt;MarshalAs(UnmanagedType.LPArray)&gt; ByRef pPacketBuffer As Byte(), ByVal nPacketSize As Long) Public Sub CALLBACK(ByVal nPort As Long, &lt;MarshalAs(UnmanagedType.LPArray)&gt; 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 </code></pre> <p>End Class</p> <hr> <p>here is some other examples of the code in:</p> <p>C#</p> <p><a href="http://blog.csdn.net/nenith1981/archive/2007/09/17/1787692.aspx" rel="nofollow noreferrer">http://blog.csdn.net/nenith1981/archive/2007/09/17/1787692.aspx</a></p> <p>VB</p> <p>://read.pudn.com/downloads70/sourcecode/graph/250633/MD%E5%AE%A2%E6%88%B7%E7%AB%AF%28VB%29/hikclient.bas__.htm</p> <p>://read.pudn.com/downloads70/sourcecode/graph/250633/MD%E5%AE%A2%E6%88%B7%E7%AB%AF%28VB%29/Form1.frm__.htm</p> <p>Delphi</p> <p>://read.pudn.com/downloads91/sourcecode/multimedia/streaming/349759/Delphi_client/Unit1.pas__.htm</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload