May 17, 2006
Using a shared DLL and a client Executable, both written in D, I'd like to be able to use std.gc.setGCHandle, as mentioned in the Win32 DLL example. However, I am getting an Access Violation Error, right when the call to std.gc.setHandle is made.

Does anyone know about this problem, and how to solve it?

This is the code setting the GC handler on the DLL side:

extern(C) export void libraryInit(void * gc) {
	MessageBoxA(null, "Library Initializing", "Library", MB_OK);
	std.gc.setGCHandle(gc);
	_minit();
	_moduleCtor();
}

This is the code, on the Executable side:

alias void function(void * gc) LibraryInitFP;

...

fp = GetProcAddress(mod.h, "libraryInit");
if(fp != null) {
    mod.libraryInitFP = cast(LibraryInitFP)(fp);
}

if(mod.libraryInitFP != null) {
    (*mod.libraryInitFP)(std.gc.getGCHandle());
}

Regards,
Sjoerd
May 18, 2006
I'm doing this in some code:

extern (C)
export void initialize(void* gc)
{
	std.gc.setGCHandle(gc);
	_minit();
	_moduleCtor();
	_moduleUnitTests();
}

And then to load it:

alias void function(void*) initialize_fp;
initialize_fp init_f;

init_f = GetLibraryFunction!(initialize_fp)(module, "initialize");

init_f(std.gc.getGCHandle());

And I haven't had any problems.  That said, I haven't yet updated to the latest latest DMD version.

-[Unknown]


> Using a shared DLL and a client Executable, both written in D, I'd like to be able to use std.gc.setGCHandle, as mentioned in the Win32 DLL example. However, I am getting an Access Violation Error, right when the call to std.gc.setHandle is made.
> 
> Does anyone know about this problem, and how to solve it?
> 
> This is the code setting the GC handler on the DLL side:
> 
> extern(C) export void libraryInit(void * gc) {
>     MessageBoxA(null, "Library Initializing", "Library", MB_OK);
>     std.gc.setGCHandle(gc);
>     _minit();
>     _moduleCtor();
> }
> 
> This is the code, on the Executable side:
> 
> alias void function(void * gc) LibraryInitFP;
> 
> ...
> 
> fp = GetProcAddress(mod.h, "libraryInit");
> if(fp != null) {
>     mod.libraryInitFP = cast(LibraryInitFP)(fp);
> }
> 
> if(mod.libraryInitFP != null) {
>     (*mod.libraryInitFP)(std.gc.getGCHandle());
> }
> 
> Regards,
> Sjoerd
May 18, 2006
As far as I know, my implementation isn't much different. The init method is properly called, there is a value passed to it. But I still get the same problem.

Regards,
Sjoerd

Unknown W. Brackets schreef:
> I'm doing this in some code:
> 
> extern (C)
> export void initialize(void* gc)
> {
>     std.gc.setGCHandle(gc);
>     _minit();
>     _moduleCtor();
>     _moduleUnitTests();
> }
> 
> And then to load it:
> 
> alias void function(void*) initialize_fp;
> initialize_fp init_f;
> 
> init_f = GetLibraryFunction!(initialize_fp)(module, "initialize");
> 
> init_f(std.gc.getGCHandle());
> 
> And I haven't had any problems.  That said, I haven't yet updated to the latest latest DMD version.
> 
> -[Unknown]
> 
> 
>> Using a shared DLL and a client Executable, both written in D, I'd like to be able to use std.gc.setGCHandle, as mentioned in the Win32 DLL example. However, I am getting an Access Violation Error, right when the call to std.gc.setHandle is made.
>>
>> Does anyone know about this problem, and how to solve it?
>>
>> This is the code setting the GC handler on the DLL side:
>>
>> extern(C) export void libraryInit(void * gc) {
>>     MessageBoxA(null, "Library Initializing", "Library", MB_OK);
>>     std.gc.setGCHandle(gc);
>>     _minit();
>>     _moduleCtor();
>> }
>>
>> This is the code, on the Executable side:
>>
>> alias void function(void * gc) LibraryInitFP;
>>
>> ...
>>
>> fp = GetProcAddress(mod.h, "libraryInit");
>> if(fp != null) {
>>     mod.libraryInitFP = cast(LibraryInitFP)(fp);
>> }
>>
>> if(mod.libraryInitFP != null) {
>>     (*mod.libraryInitFP)(std.gc.getGCHandle());
>> }
>>
>> Regards,
>> Sjoerd
May 18, 2006
Sjoerd van Leent wrote:
> Using a shared DLL and a client Executable, both written in D, I'd like to be able to use std.gc.setGCHandle, as mentioned in the Win32 DLL example. However, I am getting an Access Violation Error, right when the call to std.gc.setHandle is made.
> 
> Does anyone know about this problem, and how to solve it?

I'd try using windbg on it.
May 25, 2006
Walter Bright schreef:
> Sjoerd van Leent wrote:
>> Using a shared DLL and a client Executable, both written in D, I'd like to be able to use std.gc.setGCHandle, as mentioned in the Win32 DLL example. However, I am getting an Access Violation Error, right when the call to std.gc.setHandle is made.
>>
>> Does anyone know about this problem, and how to solve it?
> 
> I'd try using windbg on it.

It's a linkage problem, probably a corrupted stack. Using ordinary D linkage (together with the mangled names) works fine. Seems that I've got to dive into std.demangle...

Regards,
Sjoerd
Top | Discussion index | About this forum | D home