#include <iostream>
#include <dhnetsdk.h>
#include <dhconfigsdk.h>
#include <avglobal.h>
#include <string.h>
void CALLBACK DisConnectFunc(LONG lLoginID, char* pchDVRIP, LONG nDVRPort, DWORD
dwUser)
{
printf("Call DisConnectFunc: lLoginID[0x%x]/n", lLoginID);
}
void CALLBACK SnapRev(LLONG lLoginID, BYTE* pBuf, UINT RevLen, UINT EncodeType, DWORD CmdSerial, LDWORD dwUser)
{
std::cout << "recvice data" << std::endl;
FILE* stream;
if ((stream = fopen((const char*)"mpeg4.JPG", "wb")) != NULL)
{
int numwritten = fwrite(pBuf, sizeof(char), RevLen, stream);
fclose(stream);
}
}
#pragma comment(lib,"C:/Users/60551/source/repos/大华直连抓图/大华直连抓图/lib/dhnetsdk.lib")
#pragma comment(lib, "C:/Users/60551/source/repos/大华直连抓图/大华直连抓图/lib/dhconfigsdk.lib")
int main()
{
BOOL bNetSDKInitFlag = CLIENT_Init((fDisConnect)DisConnectFunc, 0);
if (FALSE == bNetSDKInitFlag)
{
printf("Initialize client SDK fail; /n");
return -1;
}
else {
printf("Initialize client SDK sucessful; /n");
}
NET_PARAM stuNetParm = { 0 };
stuNetParm.nConnectTime = 3000;
CLIENT_SetNetworkParam(&stuNetParm);
NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY stInparam;
memset(&stInparam, 0, sizeof(stInparam));
stInparam.dwSize = sizeof(stInparam);
stInparam.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
strncpy(stInparam.szIP, "0.0.00.00", sizeof(stInparam.szIP) - 1);
strncpy(stInparam.szUserName, "admin", sizeof(stInparam.szUserName) - 1);
strncpy(stInparam.szPassword, "123456", sizeof(stInparam.szPassword) - 1);
stInparam.nPort = 37777;
stInparam.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY stOutparam;
memset(&stOutparam, 0, sizeof(stOutparam));
stOutparam.dwSize = sizeof(stOutparam);z
LLONG LOGID = CLIENT_LoginWithHighLevelSecurity(&stInparam, &stOutparam);
if (LOGID != 0) {
std::cout << "login successfule!" << std::endl;
CLIENT_SetSnapRevCallBack(&SnapRev, NULL);
SNAP_PARAMS SnapCapture_params;
SnapCapture_params.Quality = 6;
SnapCapture_params.Channel = 24;
SnapCapture_params.mode = 0;
SnapCapture_params.CmdSerial = 0;
if (FALSE != CLIENT_SnapPictureEx(LOGID, &SnapCapture_params)) {
std::cout << "抓图成功!" << std::endl;
Sleep(30000);
}
else {
std::cout << "抓图失败!" << std::endl;
printf("Last Error[%x]\n", CLIENT_GetLastError());
}
}
else {
std::cout << "login code" << LOGID << std::endl;
std::cout << "登陆失败!" << std::endl;
}
if (TRUE == bNetSDKInitFlag)
{
CLIENT_Logout(LOGID);
CLIENT_Cleanup();
}
return 0;
}
|