将函数int64 C ++返回到C#项目 [英] Return function int64 C++ to a C# project
本文介绍了将函数int64 C ++返回到C#项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个在游戏中注入的dll,并在服务器上返回我的localplayer和listArrayplayer。好的工作正常
代码dll项目:
Hi, i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:
__int64 RerturnLocalPlayer() {
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX is function that return my player
return player;
}
:
in my main.h:
extern "C" {
__declspec(dllexport) __int64 RerturnLocalPlayer();
}
在我的C#代码中:
in my C# code:
[System.Runtime.InteropServices.DllImportAttribute("my.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
// and try return:
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
问题是当我运行我的c#应用程序我的控制台打开并关闭3秒后有时会出错:
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: "
"Attempt to read or write to protected memory. Usually, this is an indication that another memory is damaged.".
我尝试过:
"
What I have tried:
__int64 RerturnLocalPlayer() {
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX is function that return my player
return player;
}
:
in my main.h:
extern "C" {
__declspec(dllexport) __int64 RerturnLocalPlayer();
}
[System.Runtime.InteropServices.DllImportAttribute("my.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
// and try return:
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
推荐答案
Int64 localp = RerturnLocalPlayer();
这篇关于将函数int64 C ++返回到C#项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文