Thread overview
Re: QtD 0.1 is out!
Feb 12, 2009
Eldar Insafutdinov
Feb 12, 2009
Max Samukha
Feb 12, 2009
Eldar Insafutdinov
Feb 15, 2009
Eldar Insafutdinov
February 12, 2009
Bill Baxter Wrote:

> On Fri, Feb 13, 2009 at 5:00 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
> > Bill Baxter Wrote:
> >
> >> On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
> >> > Can somebody help me with exporting functions from a DLL? I am defining functions in C++ like
> >> > extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
> >> > After compiling a DLL with MINGW and producing a lib file for it with implib I am trying to use them from D.
> >> > In D I declare them as
> >> > extern (C) void* __qtd_QObject_QObject_QObject(args);
> >> > And then compile it and link it to the .lib file made by implib for that DLL, but optlink complains that symbol is undefined. I tried to use that Cfunction from C++ and it worked. What I can do?
> >> >
> >>
> >> What's the implib command you're using?  Often you need to use the /system flag.
> >>
> >> --bb
> >
> > okay, second problem then - I need to be able to call extern (C) functions defined in D code from DLL. I tried to do getProcAddress(NULL, "__some_D_func");
> > but this doesn't work.
> 
> I think you may have to write some code to explicitly register your D
> functions with the DLL.
> You could write a mini getDCodeProcAddress kind of thing in your D
> code.  Then give a pointer to that function to the C code in the DLL
> at startup.  Then C code uses getDCodeProcAddress from there.
> 
> Maybe there's an easier way, but that's what I'd try.
> 
> --bb

This way won't really work because there are dozens of such a functions - that's for virtual dispatch. I have just solved it by declaring functions "export extern (C)" and adding "_" prefix to function name when calling GetProcAddress. So technically there are no issues to make qtd working on windows!
February 12, 2009
On Thu, 12 Feb 2009 15:48:07 -0500, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:

>Bill Baxter Wrote:
>
>> On Fri, Feb 13, 2009 at 5:00 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
>> > Bill Baxter Wrote:
>> >
>> >> On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
>> >> > Can somebody help me with exporting functions from a DLL? I am defining functions in C++ like
>> >> > extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
>> >> > After compiling a DLL with MINGW and producing a lib file for it with implib I am trying to use them from D.
>> >> > In D I declare them as
>> >> > extern (C) void* __qtd_QObject_QObject_QObject(args);
>> >> > And then compile it and link it to the .lib file made by implib for that DLL, but optlink complains that symbol is undefined. I tried to use that Cfunction from C++ and it worked. What I can do?
>> >> >
>> >>
>> >> What's the implib command you're using?  Often you need to use the /system flag.
>> >>
>> >> --bb
>> >
>> > okay, second problem then - I need to be able to call extern (C) functions defined in D code from DLL. I tried to do getProcAddress(NULL, "__some_D_func");
>> > but this doesn't work.
>> 
>> I think you may have to write some code to explicitly register your D
>> functions with the DLL.
>> You could write a mini getDCodeProcAddress kind of thing in your D
>> code.  Then give a pointer to that function to the C code in the DLL
>> at startup.  Then C code uses getDCodeProcAddress from there.
>> 
>> Maybe there's an easier way, but that's what I'd try.
>> 
>> --bb
>
>This way won't really work because there are dozens of such a functions - that's for virtual dispatch. I have just solved it by declaring functions "export extern (C)" and adding "_" prefix to function name when calling GetProcAddress. So technically there are no issues to make qtd working on windows!

You are a genius! ;)
February 12, 2009
Max Samukha Wrote:

> On Thu, 12 Feb 2009 15:48:07 -0500, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
> 
> >Bill Baxter Wrote:
> >
> >> On Fri, Feb 13, 2009 at 5:00 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
> >> > Bill Baxter Wrote:
> >> >
> >> >> On Fri, Feb 13, 2009 at 4:22 AM, Eldar Insafutdinov <e.insafutdinov@gmail.com> wrote:
> >> >> > Can somebody help me with exporting functions from a DLL? I am defining functions in C++ like
> >> >> > extern "C" __declspec(dllexport) void* __qtd_QObject_QObject_QObject(args)
> >> >> > After compiling a DLL with MINGW and producing a lib file for it with implib I am trying to use them from D.
> >> >> > In D I declare them as
> >> >> > extern (C) void* __qtd_QObject_QObject_QObject(args);
> >> >> > And then compile it and link it to the .lib file made by implib for that DLL, but optlink complains that symbol is undefined. I tried to use that Cfunction from C++ and it worked. What I can do?
> >> >> >
> >> >>
> >> >> What's the implib command you're using?  Often you need to use the /system flag.
> >> >>
> >> >> --bb
> >> >
> >> > okay, second problem then - I need to be able to call extern (C) functions defined in D code from DLL. I tried to do getProcAddress(NULL, "__some_D_func");
> >> > but this doesn't work.
> >> 
> >> I think you may have to write some code to explicitly register your D
> >> functions with the DLL.
> >> You could write a mini getDCodeProcAddress kind of thing in your D
> >> code.  Then give a pointer to that function to the C code in the DLL
> >> at startup.  Then C code uses getDCodeProcAddress from there.
> >> 
> >> Maybe there's an easier way, but that's what I'd try.
> >> 
> >> --bb
> >
> >This way won't really work because there are dozens of such a functions - that's for virtual dispatch. I have just solved it by declaring functions "export extern (C)" and adding "_" prefix to function name when calling GetProcAddress. So technically there are no issues to make qtd working on windows!
> 
> You are a genius! ;)

No, you are ;)
February 15, 2009
Eldar Insafutdinov Wrote:

> This way won't really work because there are dozens of such a functions - that's for virtual dispatch. I have just solved it by declaring functions "export extern (C)" and adding "_" prefix to function name when calling GetProcAddress. So technically there are no issues to make qtd working on windows!

So porting qtd to windows almost finished, but I experienced couple of new problems. One of them is that these callback functions that I declare on D side(as export extern C) of the binding and that should be called from C++ part which sits in DLL, they are not put by linker into executable if they are in a static library. If I compile module which contains them with the resulting executable - it works fine, functions are in executable. I tried -L/-L/NOPACKFUNCTIONS but it didn't help. What can solve this problem?
Thank you.