Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi, i write a dll that is injected on game and return my localplayer and listArrayplayer on server. Ok work fine
code dll project:

C++
__int64 RerturnLocalPlayer() {

    __int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX is function that return my player
    return player;
}
in my main.h:
C++
extern "C" {

	__declspec(dllexport) __int64 RerturnLocalPlayer();
}
in my C# code:
C#
[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"));

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:

C++
__int64 RerturnLocalPlayer() {

		__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX is function that return my player
		return player;
	}

in my main.h:
C++
extern "C" {

	__declspec(dllexport) __int64 RerturnLocalPlayer();

}

C#
        [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"));
Posted
Updated 10-Nov-18 18:37pm
v2

1 solution

C#
Int64 localp = RerturnLocalPlayer();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900