Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active February 23, 2025 07:34
Show Gist options
  • Save baobao/02d100a89dc1daaded470d024df4a2d1 to your computer and use it in GitHub Desktop.
Save baobao/02d100a89dc1daaded470d024df4a2d1 to your computer and use it in GitHub Desktop.
C#とC++間でint型データを送りあう方法サンプルコード https://shibuya24.info/entry/unity-cs-cpp-int
// C#とC++間でint型データを送り合うC#コード
using System.Runtime.InteropServices;
using UnityEngine;
public class InvokeCpp : MonoBehaviour
{
[DllImport("TestDll.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int Additive(int a, int b);
void Awake()
{
var result = Additive(10, 24);
Debug.Log(result);
}
}
// C#とC++間でint型データを送り合うC++コード
#include <iostream>
extern "C" __declspec(dllexport) int Additive(int a, int b)
{
return a + b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment