首页 > 编程语言 >C#调用C++动态库接口函数和回调函数方法 后续

C#调用C++动态库接口函数和回调函数方法 后续

时间:2023-11-16 15:36:23浏览次数:36  
标签:VoiceTextbyte string C# C++ int CallingConvention StartSWithRec public 接口函数

声明回调委托,C#的委托可以实现C#调用C++的回调,操作函数以后的回调

//定义委托,CallingConvention.StdCall可以,CallingConvention.Cdecl不行,参考https://www.it1352.com/1792610.html
 //[UnmanagedFunctionPointer(CallingConvention.Cdecl)] //不需要要添加该句话,具体参考 //https://blog.csdn.net/weixin_30786657/article/details/98678227
 public delegate int CallBackGWQStartSWithRec(int ErrorCode, string SignPdfBase64, string SignNameBase64, string FingerPrintBase64, string XML, string endTime);

注意:
其中WINAPI也称为StdCall不像大多数C / C ++库通常使用的Cdecl。CallingConvention默认是CallingConvention.StdCall

动态库声明

public class GWQDllHidDevice
    {
        [DllImport("GWQDll.dll", EntryPoint = "GWQ_StartSWithRec")]
        public extern static int GWQ_StartSWithRec(string PDFPath, int SignType, string Location, string VideoPath, int Timeout, int FPWidth, int SignWidth, CallBackGWQStartSWithRec Q_StartSignWithRec, byte[] VoiceText, int VoiceTextLen);
    }

 

使用

public class  GWQDevice {
 public static int CallBackSWithRec(int ErrorCode, string SPdfBase64, string SNameBase64, string FPBase64, string XML, string endTime)
        {
//处理回调内容 try { if (ErrorCode == 0) { if (!string.IsNullOrEmpty(SPdfBase64)) { var bytes = Convert.FromBase64String(SPdfBase64); using (FileStream fs = new FileStream("signPDFmerge.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { fs.Write(bytes, 0, bytes.Length); Console.WriteLine("sPDFmerge.pdf 写入当前目录"); } var spdfBase64 = SPdfBase64; } } } catch (Exception ex) { logger.Error($"操作以后回调失败,原因:{ex}"); }return ErrorCode; } public int GWQStartSignWithRecAsync(string PDFPath, string Location, string VideoPath, int Timeout, int FPWidth, int SignWidth, string VoiceText, int SignType = 1) { int ret = 0; try { byte[] VoiceTextbyte = null; if (string.IsNullOrWhiteSpace(VoiceText)) { VoiceTextbyte = default;// new byte[]; } else { VoiceTextbyte = Encoding.GetEncoding("GB18030").GetBytes(VoiceText); } CallBackGWQStartSWithRec Q_StartSWithRec = new CallBackGWQStartSWithRec(CallBackSWithRec); ret = GWQDllHidDevice.GWQ_StartSWithRec(PDFPath, SignType, Location, VideoPath, Timeout, FPWidth, SignWidth, Q_StartSWithRec, VoiceTextbyte, VoiceTextbyte.Length); } catch { } finally { //Finished(); } return ret; } }

 

标签:VoiceTextbyte,string,C#,C++,int,CallingConvention,StartSWithRec,public,接口函数
From: https://www.cnblogs.com/1175429393wljblog/p/17836370.html

相关文章

  • 把bsc的合约代码部署到opbnb
    1.找到bsc已经正式部署的合约https://bscscan.com/ 2.拷贝ContractSourceCode把文件导出为xxx.sol 3.把导出的sol文件导入remix编辑器打开remix编辑器https://remix.ethereum.org/#lang=en&optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.18+com......
  • error DatabaseException(disk I/O error (code 1802)) sql 'PRAGMA user_version' ar
    问题描述errorDatabaseException(diskI/Oerror(code1802))sql'PRAGMAuser_version'args[]duringopen,c问题分析错误消息"DatabaseException(diskI/Oerror(code1802))"表示在尝试打开SQLite数据库时发生了磁盘I/O错误。这可能有几种原因:数据库文件路径......
  • git clone报错SSL connect error
    解决CentOS6.6上Git操作引发的SSL连接错误问题最近在处理一个CentOS6.6服务器上的问题时,遇到了一个比较棘手的问题。我的小伙伴在操作Git时,发现无法执行gitpull命令,提示找不到Git组件。在这篇文章中,我会详细介绍我们是如何定位和解决这个问题的。问题描述在一个已经很久没有......
  • php封装的curl请求方法
    get请求function curlGet($url, array $header = array(), $timeout = 5){    $ch = curl_init();//初始化    curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页    curl_setopt($ch, CURLOPT_HEADER, 0);//是否显示头信息,1显示,0不显示    ......
  • TCP乱序产生的原因
    网络拥塞:当网络拥塞时,数据包可能会在传输过程中因为网络负载过重而延迟或丢失,导致乱序数据的产生。路由选择:路由选择可以使数据包在传输过程中经过不同路径,这也可能导致乱序数据的产生。分段重组:由于网络链路的限制,数据包可能会被分段发送,接收端需要对这些分......
  • [Mac软件]Infuse 7 PRO v7.6.3 一个强大的视频播放器(激活版)
    使用Infuse制作您的视频内容,这是在iPhone、iPad、AppleTV和Mac上观看几乎任何格式的视频的好方法。无需转换文件!Infuse针对macOS12进行了优化,具有强大的流媒体选项、Trakt同步以及对AirPlay和字幕的无与伦比的支持。华丽的界面。精确控制。和丝般光滑的繁殖。播放更多类型的视频......
  • Oracle数据库日常巡检指令
    Oracle数据库的日常巡检内容包括:(1)Oracle数据库基本状况检查;(2)Oracle相关资源的使用情况检查;(3)Oracle数据库性能检查;(4)数据库服务器cpu、mem和I/O性能检查;(5)数据库服务器安全性及其他事项检查。需要指出的是这些巡检指令不仅在巡检过程中用得上,某些故障的诊断场景中同样可以利用,还是比较......
  • iOS开发 重要通知(critical-alerts)
    重要警报(critical-alerts)是iOS12和watchOS5.0中的一种新型选择加入通知,允许绕过“请勿打扰”和静音开关。他的本意是出现紧急情况,需要用户立即关注的关键事件。一、适用程序苹果不允许通过重要通知来推送营销信息,因此,此类通知仅限于医疗或健康相关应用程序、公共安全......
  • DCMTK3.6.5编译说明(ChatGPT翻译)
    DICOM工具包(DCMTK)安装先决条件DICOM工具包(DCMTK)需要使用C++编译器进行编译。我们建议使用GNUC++编译器的版本高于4.2.1(在此版本的开发中,大部分工作是在DebianLinux上使用GNUC++6.3.0完成的)。该软件也已知可以使用SUNProC++编译器、Clang和MicrosoftVisualStudio进行编译......
  • 开源一套快速部署程序的工具(CI/CD)
    随着微服务越写越多,程序发布就成了一个麻烦事,所以写了一个部署工具Vela,只要填写一个git地址、编译命令等简单信息,就能自动完成程序的部署。Vela特性:代码可在任意一台电脑自动完成编译,再自动上传至服务器可指定程序以Docker容器方式运行编译命令采用终端运行,理论支持......