调用C++动态链接库出现错误

解决方式:将托管 System.String 中的内容复制到非托管内存(Marshal.StringToHGlobalAnsi)

class
HttpsSend { [DllImport("httpsSend.dll")] public static extern IntPtr markInvoice(IntPtr url, IntPtr input); public static string Send(string url, string content) { IntPtr urlPtr = Marshal.StringToHGlobalAnsi(url); IntPtr contentPtr = Marshal.StringToHGlobalAnsi(content); IntPtr outPutIntPtr = markInvoice(urlPtr, contentPtr); string outPut = Marshal.PtrToStringAnsi(outPutIntPtr); return outPut; } }
原文地址:https://www.cnblogs.com/xiaoyu369/p/6090284.html