On Tuesday, 9 October 2012 at 10:21:58 UTC, Regan Heath wrote:
Does your dummy C host application also use gmodule to load the
dll.. that might be a useful experiment perhaps.
R
The problem has now been reduced to these two palatable programs.
bug.dll
-----------------------
import core.stdc.stdio;
string[] test;
void* test2;
void* test3 = cast(void*)1;
void* test4;
// This is here so that the next function
// becomes exported as "init" instead of "_init".
// The first exported symbol gets a preceeding underscore
// (Windows "system" convention) when using DMD/OPTLINK
// for some reason.
export extern(C) void _systemconvdummy() {}
export extern(C) void init()
{
printf("test = %p:%d\n", test.ptr, test.length);
printf("test2 = %p, test3 = %p, test4 = %p\n", test2, test3,
test4);
}
-----------------------
DllMain is as posted before. It can initialize the runtime or be
empty - the result is the same.
rundll.exe
-----------------------
#include <stdio.h>
// Comment this out to use the WinAPI directly.
#define USE_GLIB
#ifdef USE_GLIB
#include <gmodule.h>
#else
#include <Windows.h>
#endif
int main()
{
void (*init)();
#ifdef USE_GLIB
GModule* handle = g_module_open("bug.dll", 0);
#else
HMODULE handle = LoadLibrary(L"bug.dll");
#endif
printf("handle: %p\n", handle);
#ifdef USE_GLIB
g_module_symbol(handle, "init", &init);
#else
init = (void(*)())GetProcAddress(handle, "init");
#endif
printf("init: %p\n", init);
init();
return 0;
}
-----------------------
The glib headers and binaries all come from the GTK+ distribution
[1]. I'll try reducing it further by not using gmodule to see
exactly what the problem is, but it would be awesome if someone
could try to reproduce this on their machines.
[1] http://www.gtk.org/download/win32.php