On Sun, 26 May 2019 19:26:04 +0200, Mike Wey wrote:

On 26-05-2019 00:44, Alex X wrote:

When compiling for x86 my code crashes when initing gtk. Works for x64.

public static void init(ref string[] argv)
{
	int argc = cast(int)argv.length;
	char** outargv = Str.toStringzArray(argv);

// Crashes here. Access violation.

gtk_init(&argc, &outargv);

argv = Str.toStringArray(outargv, argc);

}

I modified it to take null arguments but it still crashes. It may have something to do with my gtk install but I have no idea because I have no idea what the error is.

It all works in x64.

Im not able to reproduce your issue, where did you get your copy op GTK?

I think this was my fault... trying to fix that bad keyboard handler and I made an error in versioning(WIN64 vs win64) and so ret was not properly returned... then when initing would call the corrupted function and crash. This was when I decided to add it for x86 so I could do some x86 testing.

static extern (Windows) void KBHook(int, HOOKPROC, HINSTANCE, DWORD)
{		
	version(X86)
	{
		asm
		{
			naked;
			ret [0x10];
		}
	}			
	version(Win64)
	{
		asm
		{
			naked;
			ret;
		}
	}
}
DWORD old;
auto hModule = LoadLibrary("User32.dll");
auto proc = cast(SetWindowsHookExAProc)GetProcAddress(hModule, "SetWindowsHookExA");
VirtualProtect(proc, 40, PAGE_EXECUTE_READWRITE, &old);

memcpy(proc, &KBHook, 4);


(the ret[0x10]) works for x86 by properly handling the stack but hard coded so may be invalid