博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
非托管代码的使用
阅读量:3698 次
发布时间:2019-05-21

本文共 1116 字,大约阅读时间需要 3 分钟。

public string DoSomething(string plain, string signatureAlgorithm)        {            int nRet = 0;            IntPtr hSE = new IntPtr();            byte[] bytes = Encoding.Default.GetBytes(plain);            int length = bytes.Length;            IntPtr destination = Marshal.AllocCoTaskMem(length);            Marshal.Copy(bytes, 0, destination, bytes.Length);            int cb = 0x800;            IntPtr signature = Marshal.AllocCoTaskMem(cb);            nRet = DO_SOMETHING(hSE, destination, length, signatureAlgorithm, signature, ref cb);            if (nRet != 0)            {                throw new Exception("NOT OK!", nRet);            }            byte[] buffer2 = new byte[cb];            Marshal.Copy(signature, buffer2, 0, cb);            Marshal.FreeCoTaskMem(destination);            Marshal.FreeCoTaskMem(signature);            return Convert.ToBase64String(buffer2);        }        [DllImport("some.dll", CallingConvention = CallingConvention.Cdecl)]        public static extern int DO_SOMETHING(IntPtr hSE, IntPtr plain, int plainLen, string signmethod, IntPtr signature, ref int signatureLen);

 

转载地址:http://gwucn.baihongyu.com/

你可能感兴趣的文章
Springboot项目集成jsp
查看>>
Vue的安装
查看>>
Oracle数据库错误Update数据恢复
查看>>
Sql Server数据库查询死锁和解决死锁
查看>>
Mysql实现乐观锁
查看>>
SpringBoot项目自定义Filter过滤器
查看>>
Springboot项目实现自定义拦截器
查看>>
德鲁伊后台监控配置
查看>>
正向代理和反向代理
查看>>
Stream常用方法使用案例
查看>>
Log4j日志的配置文件
查看>>
Slf4j和logback日志组合
查看>>
Mysql的读写分离和主从复制过程概述
查看>>
Java中的synchronized与lock的区别
查看>>
基于Springboot注解形式进行模糊查询
查看>>
通用Sql返回自增长insert后的id
查看>>
SQL返回Map集合或者对象
查看>>
GC垃圾回收机制----GC回收算法(GC机制必会知识点)
查看>>
SpringMVC工作执行流程详解
查看>>
【web框架】【 Cloud-Admin学习笔记(一)】【环境搭建】
查看>>