C # Wrapper SDK gets the camera's horizontal and vertical angles

Source: Internet
Author: User

Recently need to do a C # version of the control terminal, control the camera, get the camera's horizontal angle and vertical angle

To get the angle of the current camera, you need to call a function of type bool named Net_dvr_getdvrconfig

In C + +, function definition: net_dvr_getdvrconfig (LONG Luserid, DWORD Dwcommand,long Lchannel, LPVoid lpOutBuffer, DWORD dwoutbuffersize , Lpdword lpbytesreturned)

In the C # encapsulation process, the function changes to:

[DllImport (@ "HCNetSDK.dll")]
public static extern bool Net_dvr_getdvrconfig (int luserid, uint dwcommand, int lchannel, IntPtr lpoutbuffer, uint DWOUTBU Ffersize, ref uint lpbytesreturned);

In the process of the call, the conversion of the fourth parameter was encountered with a problem

First look at the function usage inside the C++demo:

1Net_dvr_ptzpos M_ptzpos = {0};2 DWORD dwreturned;3BOOL BRet = Net_dvr_getdvrconfig (M_luserid[m_struslavecameracond.byid], Net_dvr_get_ptzpos,0, &m_ptzpos,sizeof(Net_dvr_ptzpos), &dwreturned);4     if(!BRet)5     {6G_pmaindlg->addlog (M_ideviceindex, operation_fail_t,"Net_dvr_get_ptzpos");7         return;8     }9 Ten     intM_IPARA1 =HEXTODECMA (m_ptzpos.wpanpos); One     intM_ipara2 =HEXTODECMA (m_ptzpos.wtiltpos); A     intM_IPARA3 = HEXTODECMA (M_ptzpos.wzoompos);
C + + get angle

First, the struct is instantiated, passed in the corresponding parameter, returns the value of type bool, the value is true, gets the value inside the struct body

In C #, the type of the fourth parameter passed is converted by the LPVOID type to IntPtr type

First two documents: Marshal.structuretoptr method, Marshal.PtrToStructure method

Understanding the transformation between the IntPtr and the architecture, it's good to deal with the code as follows:

1   //first get the length of the current structure2             intNSIZEOFPTZ =marshal.sizeof (Ptz);3             //define a IntPtr type of data4IntPtr IntPtr =Marshal.allochglobal (NSIZEOFPTZ);5Devideangle = Chcnetsdk.net_dvr_getdvrconfig (_mluserid, Chcnetsdk.net_dvr_get_ptzpos,0, IntPtr, (UINT) NSIZEOFPTZ,refdwreturned);6             //convert IntPtr data into struct structure7Ptz = (chcnetsdk.net_dvr_ptzpos) marshal.ptrtostructure (INTPTR,typeof(Chcnetsdk.net_dvr_ptzpos));8Pan =HEXTODECMA (ptz.wpanpos);9Tit = HEXTODECMA (ptz.wtiltpos);
C # Get Angle

C # Wrapper SDK gets the camera's horizontal and vertical angles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.