首页 > 编程 > C++ > 正文

C#调用c++ dll

2019-11-08 18:46:03
字体:
来源:转载
供稿:网友

c++代码

#include "stdafx.h"extern "C" _declspec(dllexport) char* GetJson(char* pStr){	return "abcdefg";}c#代码

    public class CC    {        [DllImport("Win32PRoject1.dll", EntryPoint = "GetJson", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]        public static extern IntPtr GetSnrJson([MarshalAs(UnmanagedType.LPStr)]string temp);        public void Do()        {            StringBuilder sb = new StringBuilder(@"test");            IntPtr pStr = GetSnrJson(sb.ToString());            string json = Marshal.PtrToStringAnsi(pStr);            Console.ReadLine();        }    }

输出:


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选