Click here to Skip to main content
15,034,986 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 8:01
Memberzezba900019-Sep-19 8:01 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 8:28
mvahoney the codewitch19-Sep-19 8:28 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 8:37
Memberzezba900019-Sep-19 8:37 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 8:41
mvahoney the codewitch19-Sep-19 8:41 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 9:05
Memberzezba900019-Sep-19 9:05 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 9:13
mvahoney the codewitch19-Sep-19 9:13 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 9:18
mvahoney the codewitch19-Sep-19 9:18 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 9:43
Memberzezba900019-Sep-19 9:43 
lol yes there is. You didn't read anything I said.

As I said before. C# pointers are the same as C/C++. Look at the example below.
I literally just compiled and ran this on my computer with zero errors.

using System;
using System.Runtime.InteropServices;

using SIZE_T = System.IntPtr;
using DWORD = System.UInt32;

namespace TestNet
{
	[StructLayout(LayoutKind.Sequential)]
	struct Foo
	{
		public int bar;
	}

	static class Program
	{
		[DllImport("Kernel32.dll")]
		private static unsafe extern void* VirtualAlloc(void* lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);

		private const DWORD MEM_COMMIT = 0x00001000;
		private const DWORD PAGE_READWRITE = 0x04;

		static unsafe void Main(string[] args)
		{
			Foo* pfoo = (Foo*)VirtualAlloc((void*)0, (SIZE_T)sizeof(Foo), MEM_COMMIT, PAGE_READWRITE);
			pfoo->bar = 1; // writes to disk
			Console.WriteLine(pfoo->bar.ToString()); // reads from disk.
		}
	}
}


Make a C# console app and paste that code in. WaLa!!
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 9:45
mvahoney the codewitch19-Sep-19 9:45 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 9:47
Memberzezba900019-Sep-19 9:47 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
TheGreatAndPowerfulOz20-Sep-19 5:02
MemberTheGreatAndPowerfulOz20-Sep-19 5:02 
GeneralThought of the Day Pin
OriginalGriff18-Sep-19 4:45
mveOriginalGriff18-Sep-19 4:45 
GeneralRe: Thought of the Day Pin
W Balboos, GHB18-Sep-19 4:58
mveW Balboos, GHB18-Sep-19 4:58 
GeneralRe: Thought of the Day Pin
PeejayAdams18-Sep-19 5:16
MemberPeejayAdams18-Sep-19 5:16 
GeneralRe: Thought of the Day Pin
honey the codewitch18-Sep-19 5:19
mvahoney the codewitch18-Sep-19 5:19 
GeneralRe: Thought of the Day Pin
lopatir18-Sep-19 5:26
Memberlopatir18-Sep-19 5:26 
GeneralRe: Thought of the Day Pin
honey the codewitch18-Sep-19 5:27
mvahoney the codewitch18-Sep-19 5:27 
GeneralRe: Thought of the Day Pin
DRHuff18-Sep-19 6:22
MemberDRHuff18-Sep-19 6:22 
PraiseRe: Thought of the Day Pin
honey the codewitch18-Sep-19 6:23
mvahoney the codewitch18-Sep-19 6:23 
GeneralRe: Thought of the Day Pin
PeejayAdams18-Sep-19 5:29
MemberPeejayAdams18-Sep-19 5:29 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer18-Sep-19 7:14
professionalDaniel Pfeffer18-Sep-19 7:14 
AdminTo those wishing to push the boundaries Pin
Chris Maunder18-Sep-19 4:10
cofounderChris Maunder18-Sep-19 4:10 
GeneralRe: To those wishing to push the boundaries Pin
honey the codewitch18-Sep-19 4:14
mvahoney the codewitch18-Sep-19 4:14 
GeneralRe: To those wishing to push the boundaries Pin
Chris Maunder18-Sep-19 4:17
cofounderChris Maunder18-Sep-19 4:17 
GeneralRe: To those wishing to push the boundaries Pin
honey the codewitch18-Sep-19 4:18
mvahoney the codewitch18-Sep-19 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.