1,221
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
unsigned int iLastErr = 0;
int m_lUserID = -1;
bool m_bInitSDK = false;
bool m_bRecord = false;
int m_lRealHandle = -1;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
m_bInitSDK = NET_DVR_Init() ;
if (m_bInitSDK == false)
{
ShowMessage("NET_DVR_Init error!") ;
}
else
{
//保存SDK日志 To save the SDK log
NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true) ;
}
}
//---------------------------------------------------------------------------
//登录
void __fastcall TfrmMain::btnLoginClick(TObject *Sender)
{
if (edtIP->Text==""||edtPort->Text==""||edtUser->Text==""||edtPsw->Text=="")
{
ShowMessage("请输入设备地址、端口、用户名和密码!") ;
return ;
}
if (m_lUserID < 0)
{
String DVRIPAddress = edtIP->Text ; //设备IP地址或者域名
int DVRPortNumber = edtPort->Text.ToInt() ; //设备服务端口号
String DVRUserName = edtUser->Text ; //设备登录用户名
String DVRPassword = edtPsw->Text ; //设备登录密码
NET_DVR_DEVICEINFO_V30 DeviceInfo ;
//登录设备
m_lUserID = NET_DVR_Login_V30(DVRIPAddress.c_str(), DVRPortNumber, DVRUserName.c_str(), DVRPassword.c_str(), &DeviceInfo) ;
if (m_lUserID < 0)
{
iLastErr = NET_DVR_GetLastError() ;
str = "NET_DVR_Login_V30 failed, error code= " + iLastErr ; //登录失败,输出错误号
ShowMessage(str) ;
return ;
}
else
{
//登录成功
ShowMessage("Login Success!") ;
btnLogin->Caption = "Logout" ;
}
}
else
{
//注销登录 Logout the device
if (m_lRealHandle >= 0)
{
ShowMessage("Please stop live view firstly") ;
return ;
}
if (!NET_DVR_Logout(m_lUserID))
{
iLastErr = NET_DVR_GetLastError() ;
str = "NET_DVR_Logout failed, error code= " + iLastErr ;
ShowMessage(str) ;
return ;
}
m_lUserID = -1 ;
btnLogin->Caption = "Login" ;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
#include <StdCtrls.hpp>
#include "HCNetSDK.h"
//---------------------------------------------------------------------------
class TfrmMain : public TForm
{
__published: // IDE-managed Components
TImage *imgPreview;
TPanel *pnlPreview;
TLabel *lblIP;
TEdit *edtIP;
TEdit *edtPort;
TLabel *lblPort;
TEdit *edtUser;
TLabel *lblUser;
TEdit *edtPsw;
TLabel *lblPsw;
TButton *btnLogin;
TButton *btnPreview;
TLabel *lblChannel;
TEdit *edtChannel;
void __fastcall FormCreate(TObject *Sender);
void __fastcall btnLoginClick(TObject *Sender);
void __fastcall btnPreviewClick(TObject *Sender);
private: // User declarations
String str ;
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
//---------------------------------------------------------------------------
#endif
/********************************SDK接口函数声明*********************************/
NET_DVR_API BOOL __stdcall NET_DVR_Init();
NET_DVR_API BOOL __stdcall NET_DVR_Cleanup();
//NET_DVR_SetDVRMessage的扩展
#ifdef _WIN32
NET_DVR_API BOOL __stdcall NET_DVR_SetDVRMessage(UINT nMessage,HWND hWnd);
NET_DVR_API BOOL __stdcall NET_DVR_SetExceptionCallBack_V30(UINT nMessage, HWND hWnd, void (CALLBACK* fExceptionCallBack)(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser), void *pUser);
#elif defined(__linux__) || defined(__APPLE__)
NET_DVR_API BOOL __stdcall NET_DVR_SetExceptionCallBack_V30(UINT reserved1, void* reserved2, void (CALLBACK* fExceptionCallBack)(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser), void *pUser);
/*Linux专有 */
#if defined(__linux__)
NET_DVR_API BOOL NET_DVR_DrawAreaInit(INITINFO InitInfo, DWORD iUseSDL = 1);
NET_DVR_API BOOL NET_DVR_DrawAreaRelease();
#endif
#endif
Project->add to project,添加HCNetSDK.lib