c#调用dll


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

using System.Runtime.InteropServices;

using System.Threading;

 

namespace WindowsFormsApp1

{

 

    public partial class Form1 :Form

    {

        //typedef void (__stdcall* PreviewMsgCallback_V20)(long handle,void* pUser,int nMsg);

        //typedef void (__stdcall* StreamCallback_V20)(long handle,int iStreamType,const char* data,int size,void* pUser);

 

        public delegate void PreviewMsgCallback_V20(System.Int32 handle,  System.IntPtr pUser, int nMsg);

        public delegate void StreamCallback_V20(System.Int32 handle,int iStreamType, System.String data,int size, System.IntPtr pUser);

        //导入非托管dll

        //分配的库处理和连接到数控指定的IP地址或主机名。

        [DllImport("PlatformSDK.dll", EntryPoint ="Plat_Init", CallingConvention = CallingConvention.Cdecl)]

        private static extern Int16 Plat_Init();

 

        [DllImport("PlatformSDK.dll", EntryPoint ="Plat_GetLastError", CallingConvention =CallingConvention.Cdecl)]

        private static extern Int16 Plat_GetLastError();

 

        [DllImport("PlatformSDK.dll", EntryPoint ="Plat_LoginCMS_V20", CallingConvention =CallingConvention.Cdecl)]

        private static extern Int32 Plat_LoginCMS_V20(System.String pszCmsIp,int iCmsPort, System.String pszUserName, System.String pszPSW,int iLoginType = 0,int iMqPort = 61618);

        //short (const char *ipaddr, unsigned short port, long timeout, unsigned short *FlibHndl)

        //private static extern Int16 Plat_Init(ref String ip, UInt16 port, Int64 timeout, ref UInt16 flibHndl);

        [DllImport("PlatformSDK.dll", EntryPoint ="Plat_VSS_PlayVideo_V20", CallingConvention =CallingConvention.Cdecl)]

 

        private static extern Int16 Plat_VSS_PlayVideo_V20(int iUserHandle,  System.String pszCamIdx, System.Int32 hWnd,ref UInt16 puiHandle,

                                           StreamCallback_V20 fStreamCallback,PreviewMsgCallback_V20 fMsgNotify, System.IntPtr pUser);

        //private static extern Int16 Plat_VSS_PlayVideo_V20(int iUserHandle, System.String pszCamIdx, long hWnd, out unsigned int* puiHandle,

        //                                _IN_ StreamCallback_V20 fStreamCallback = 0, _IN_ PreviewMsgCallback_V20 fMsgNotify = 0, _IN_ void* pUser = 0);

        [DllImport("PlatformSDK.dll", EntryPoint ="Plat_VSS_CapPic_V20", CallingConvention =CallingConvention.Cdecl)]

 

        private static extern Int16 Plat_VSS_CapPic_V20(int iUserHandle,int hStream, System.String picname);

 

 

        public static void CallbackResult_Fun(StreamCallback_V20 image)

        {

            Console.WriteLine("CallbackResult_Fun\n");

        }

 

        public int g_iLogHandle;

        public UInt16 m_uiPlayHandle = 11;

        public Form1()

        {

          int aaa=  Plat_Init();

 

            string pszCmsIp = "121.1.21.12";

            string pszUserName = "user";

            string pszPSW = "pwd";

          g_iLogHandle  = Plat_LoginCMS_V20(pszCmsIp,85,pszUserName, pszPSW);

 

            string a = "a";

  

            int iRet = Plat_VSS_PlayVideo_V20(g_iLogHandle, a, 0,

               ref m_uiPlayHandle, null, null, IntPtr.Zero);

            int error = Plat_GetLastError();

 

            Thread thread2 = new Thread(down_pic);

           thread2.Start();

         

            InitializeComponent();

        }

 

        private void Form1_Load(object sender,EventArgs e)

        {

 

        }

        private void down_pic() {

            //int g_iLogHandle,int m_uiPlayHandle

            while (true)

            {

                string szTmpFile = "D:\\pic\\1.jpg";  // 图片有自己重命名

                int iRet = Plat_VSS_CapPic_V20(g_iLogHandle, m_uiPlayHandle, szTmpFile);

                Thread.Sleep(10);

            }

        }

    }

}

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值