博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 调用C++链接库与回调
阅读量:1982 次
发布时间:2019-04-27

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

***********************************************************************************************************
C++部分
//MyTest.h
#ifdef  _WIN32_#ifdef  MY_TEST_EXPORTS#define MY_TEST_API __declspec(dllexport)#define API_STDCALL __stdcall#else#define MY_TEST_API __declspec(dllimport)#endif#else#define MY_TEST_API#define CALLBACK#define API_STDCALL#endif#ifndef _MY_TEST_H_#define _MY_TEST_H_#endif
//MyTest.cpp
#include "MyTest.h"#include 
typedef void (CALLBACK *MyTestCallBack)(char *szBuffer);MyTestCallBack m_myTestCallBack;extern "C" MY_TEST_API void TestApi(const char* str,MyTestCallBack callback){ callback("hello,I recv your str:"+str);}
***********************************************************************************************************
C#部分
using System.Collections;using System.Runtime.InteropServices;using System;using System.Collections.Generic;using UnityEngine;public class CSTest{public delegate void Cpp2CsCallBack(string str);#if UNITY_ANDROID[DllImport("u3dmydll")]public static extern void CallCppDllApi(string str,Cpp2CsCallBack cb);#else[DllImport("u3dmydll.dll")]public static extern void CallCppDllApi(string str,Cpp2CsCallBack cb);#endifpublic static void onDllCallBack(string str){Debug.Log(str);}}
调用:
CSTest.CallCppDllApi("hello dll",CSTest.onDllCallBack);

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

你可能感兴趣的文章
【解决错误】复现RCAN的时候遇到了ImportError: cannot import name ‘_update_worker_pids’ from ‘torch._C’
查看>>
【解决错误】ModuleNotFoundError: No module named ‘skimage‘
查看>>
【深度学习笔记】pytorch的点乘(dot product)
查看>>
【深度学习笔记】残差
查看>>
【错误解决】cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\sr
查看>>
【python学习笔记】读取指定文件夹中的图片,结合边缘保留滤波EPF
查看>>
【工具和环境】Linux下安装pycharm
查看>>
【Accumulation】The last two sentences of the abstract
查看>>
【Accumulation】The definition of SISR
查看>>
【工具与环境】Windows下安装Sublime Text 3
查看>>
【解决错误】ValueError: some of the strides of a given numpy array are negative.
查看>>
【工具与环境】Excel中批量插入行
查看>>
【个人实验注意事项】
查看>>
【解决错误】ModuleNotFoundError: No module named ‘tqdm‘
查看>>
【解决错误】ModuleNotFoundError: No module named ‘PIL‘
查看>>
【学习笔记】对vanilla的一些个人理解
查看>>
【解决错误】json.decoder.JSONDecodeError: Expecting value: line 11 column 14 (char 82)
查看>>
【解决错误】The size of tensor a (8) must match the size of tensor b (64) at non-singleton dimension 1
查看>>
word文档中实现目录索引中标题加粗,前导符和页码不加粗
查看>>
“学硕” VS “专硕”
查看>>