c#调用dll

举报
风吹稻花香 发表于 2021/06/04 23:07:25 2021/06/04
【摘要】 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using ...


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);

            }

        }

    }

}

 


文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/78700147

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。