C++ dll 分别 给c# c++使用

一、C# 

自己写2D 3D算法库都要给别人用,所以好几年没有用过c# 了,调用一些

1、建立c++ 项目

 

 .h 文件

#pragma once
#ifdef __DLLEXPORT
#define __DLL_EXP _declspec(dllexport) 
#else
#define __DLL_EXP _declspec(dllimport) 
#endif 

extern "C" __DLL_EXP int add(int a, int b);

.cpp

#include<stdio.h>
#include "myCppdll.h"


int add(int a, int b)
{
	return a + b;
}

 

 生成

2、C# 程序

using System;
using System.Runtime.InteropServices;

namespace ConsoleApp1
{
    class Program
    {
        [DllImport(".\\MyDLL\\x64\\Release\\MyDLL.dll")]
        public extern static int add(int a, int b);
        static void Main(string[] args)
        {
            int a = add(2, 3);
            Console.WriteLine(a);
            Console.WriteLine("ssss ");
            Console.ReadKey();
        }
    }
}

test

 

 二、c++

相关推荐

  1. 使用.cc域名的优势

    2024-04-24 08:24:01       34 阅读
  2. 【已解决】npm ERR! cb() never called!

    2024-04-24 08:24:01       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-24 08:24:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-24 08:24:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-24 08:24:01       82 阅读
  4. Python语言-面向对象

    2024-04-24 08:24:01       91 阅读

热门阅读

  1. LeetCode //C - 29. Divide Two Integers

    2024-04-24 08:24:01       37 阅读
  2. 关于上传自己本地项目到GitHub的相关命令

    2024-04-24 08:24:01       34 阅读
  3. Unity UI擦除效果

    2024-04-24 08:24:01       37 阅读
  4. Rust:遍历 BinaryHeap

    2024-04-24 08:24:01       36 阅读
  5. 使用Python实现语音识别与处理模型

    2024-04-24 08:24:01       32 阅读
  6. Rust 和 Go 哪个更好?

    2024-04-24 08:24:01       78 阅读
  7. 【MySql】MySQL查询中的笛卡尔积现象解析

    2024-04-24 08:24:01       44 阅读
  8. vscode 如何debug python torchrun deepspeed

    2024-04-24 08:24:01       111 阅读
  9. 4. HTTPS通信(握手)过程

    2024-04-24 08:24:01       37 阅读
  10. 无人机类型有哪些?

    2024-04-24 08:24:01       32 阅读