Hello Bobby,
Hi Srinivas,
The link does not seem to work.My problem is that the call back function is not working.Please see my code below
[DllImport("HCNetSDK.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int NET_DVR_RealPlay_V30(int lUserID, ref NET_DVR_CLIENTINFO lpClientInfo, RealDataCallBack_V30 fRealDataCallBack_V30, int pUser, bool bBlocked);
public delegate void RealDataCallBack_V30(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser);
...
I guess i can help with that if it's not too late now. Just took a look on this forum 1,5h ago. Probably type of pBuffer was an issue in ur case since u used it as IntPtr i did byte[] in my program but i can be wrong i simply made my own solution based on ur step and what you wanted to archive.
here is my test class for ur problem. I ran it and it worked fine. Callback method works also but it's not necessary to see the stream in fact it was even disturbing but you will check it on ur own.
I also added the stoping method. If you will have any trouble let me know I will try to help.
public class Test
{
public Result RealPlayTest(IntPtr phWnd)
{
Result result = new Result(true);
//tt = WrapperClass.NET_DVR_Init();
SDKMethods.NET_DVR_Init();
//tt = WrapperClass.NET_DVR_SetConnectTime((DWORD)9001, (DWORD)5);
SDKMethods.NET_DVR_SetConnectTime(2000, 1);
//tt = WrapperClass.NET_DVR_SetReconnect(10000, true);
SDKMethods.NET_DVR_SetConnectTime(10000, 5);
//NET_DVR_DEVICEINFO_V30 cc = new NET_DVR_DEVICEINFO_V30();
//NET_DVR_CLIENTINFO lpClientInfo = new NET_DVR_CLIENTINFO();
//int tt1 = 0;
//tt1 = WrapperClass.NET_DVR_Login_V30("61.1.227.204", 8000, "admin", "mfin1028", out cc);
//tt1 = (int)WrapperClass.NET_DVR_GetLastError();
int lUserID;
NET_DVR_DEVICEINFO_V30 struDeviceInfo = new NET_DVR_DEVICEINFO_V30();
string ip = "192.168.1.240";
ushort port = 8000;
string user = "user";
string password = "password";
lUserID = SDKMethods.NET_DVR_Login_V30(ip, port, user, password, ref struDeviceInfo);
if (lUserID < 0)
{
result.AddError(string.Format("Login failed, error code: {0}\n", SDKMethods.NET_DVR_GetLastError()));
result.IsSuccessful = false;
SDKMethods.NET_DVR_Cleanup();
return result;
}
NET_DVR_CLIENTINFO lpClientInfo = new NET_DVR_CLIENTINFO();
lpClientInfo.lChannel = 36; //IMPORTANT!! to get video or life stream u need to connect to digital channels not analog one, in my case digital channels starts with 33 but i am using '3rd' camera
//lpClientInfo.hPlayWnd = pictureBox1.Handle.ToString();
lpClientInfo.hPlayWnd = phWnd; // pictureBox1.Handle.ToString();
lpClientInfo.lLinkMode = 0;
//(int lRealHandle, uint dwDataType, byte[] pBuffer, uint dwBufSize, IntPtr pUser);
SDKMethods.fRealDataCallBack_V30 callback = new SDKMethods.fRealDataCallBack_V30(g_RealDataCallBack_V30);
//Marshal.GetFunctionPointerForDelegate(g_RealDataCallBack_V);
IntPtr userPtr = new IntPtr();
int realPlayId = 0;
realPlayId = SDKMethods.NET_DVR_RealPlay_V30(lUserID, ref lpClientInfo, callback, userPtr, false);
if (realPlayId < 0)
{
string message = string.Format("RealPlay failed, error code: {0}\n", SDKMethods.NET_DVR_GetLastError());
Console.WriteLine(message);
result.AddError(message);
result.IsSuccessful = false;
SDKMethods.NET_DVR_Cleanup();
return result;
}
//Streaming by ~10 seconds
int counter = 0;
while (counter < 10)
{
System.Threading.Thread.Sleep(1000);
counter++;
}
if (!SDKMethods.NET_DVR_StopRealPlay(realPlayId))
{
string message = string.Format("RealPlay failed, error code: {0}\n", SDKMethods.NET_DVR_GetLastError());
Console.WriteLine(message);
result.AddError(message);
result.IsSuccessful = false;
SDKMethods.NET_DVR_Cleanup();
return result;
}
return result;
}
//public void g_RealDataCallBack_V30(int lRealHandle, uint dwDataType, byte[] pBuffer, uint dwBufSize, IntPtr pUser)
public void g_RealDataCallBack_V30(int lRealHandle, uint dwDataType, byte[] pBuffer, uint dwBufSize, IntPtr pUser)
{
//Debugger.Break();
Console.WriteLine("Hello from g_RealDataCallBack_V30");
//MessageBox.Show("Test");
}
}
here my C++ functions import (just limited myself to those new ones since I believe your Init, reconnect and login methods are working fine) If u will have some problems let me know so I will put missing parts as well if you will point them for me.
public delegate void fRealDataCallBack_V30(int lRealHandle, uint dwDataType, byte[] pBuffer, uint dwBufSize, IntPtr pUser);
[DllImport(@"D:\Projekty\Hik\Hikvision\EN-HCNetSDK(Windows32)V5.2.7.5_build20170217\lib\HCNetSDK.dll", EntryPoint = "NET_DVR_RealPlay_V30")]
public static extern int NET_DVR_RealPlay_V30(int lUserID, ref NET_DVR_CLIENTINFO lpClientInfo, fRealDataCallBack_V30 cbRealDataCallBack, IntPtr pUser, bool bBlocked);
[DllImport(@"D:\Projekty\Hik\Hikvision\EN-HCNetSDK(Windows32)V5.2.7.5_build20170217\lib\HCNetSDK.dll", EntryPoint = "NET_DVR_StopRealPlay")]
public static extern bool NET_DVR_StopRealPlay(int lRealHandle);
and of course calling this all. I am using console app but i think it's not a problem
static void Main(string[] args)
{
Test test = new Test();
IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; //for console application
//IntPtr hWnd = this.Handle; //for winforms application
test.RealPlayTest(hWnd);
Console.ReadKey();
}
Best regards