February 02, 2008
"Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo0p7c$1tbq$1@digitalmars.com...
> Okay.
>
> Example "plugin" example.d:
>
> ---
> module example;
>
> extern (C)
> export int foo();

Ohhh, _there_ it is; I think this bit got cut out of the original post :)

> I don't have the Linux loader in front of me but it's almost exactly the same and works just fine (LoadLibraryA => dlopen, GetProcAddress => dlsym, FreeLibrary => dlclose, with some dlerror logic in there.)  But as stated, it appears that there's really no "reverse linking" of DLLs.

As in having DLLs link to symbols exported from the app?  Right, it's not possible without some hackery.  I'm not sure how to do it but apparently it can be done.  I think there are restrictions on it, though.

DLLs really *are* an awful approximation of SOs :(


February 02, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fo1ufl$11if$1@digitalmars.com...
> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo0p7c$1tbq$1@digitalmars.com...

>
> As in having DLLs link to symbols exported from the app?  Right, it's not possible without some hackery.  I'm not sure how to do it but apparently it can be done.  I think there are restrictions on it, though.
>
> DLLs really *are* an awful approximation of SOs :(

However there's hope: DDL.  http://www.dsource.org/projects/ddl

It's not entirely polished, but it's basically a sort of SO implementation for D on Windows, only it's entirely in userland rather than being part of the OS.  Some simple tests have shown that it's more or less able to do the same stuff you can do with SOs.  It takes a little more work but the end results are much, much better than DLLs could hope to be :)


February 02, 2008
Yes, I looked at that and tried it, but I'm afraid I may not have the time right now to port it from Mango to using Tango...

Thanks for the help and comments.

-[Unknown]


Jarrett Billingsley wrote:
> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fo1ufl$11if$1@digitalmars.com...
>> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo0p7c$1tbq$1@digitalmars.com...
> 
>> As in having DLLs link to symbols exported from the app?  Right, it's not possible without some hackery.  I'm not sure how to do it but apparently it can be done.  I think there are restrictions on it, though.
>>
>> DLLs really *are* an awful approximation of SOs :(
> 
> However there's hope: DDL.  http://www.dsource.org/projects/ddl
> 
> It's not entirely polished, but it's basically a sort of SO implementation for D on Windows, only it's entirely in userland rather than being part of the OS.  Some simple tests have shown that it's more or less able to do the same stuff you can do with SOs.  It takes a little more work but the end results are much, much better than DLLs could hope to be :) 
> 
> 
February 02, 2008
"Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo2i09$280r$1@digitalmars.com...
> Yes, I looked at that and tried it, but I'm afraid I may not have the time right now to port it from Mango to using Tango...

It already uses Tango, and doesn't depend on Mango anymore, AFAIK.  I was able to get it installed and working in a couple minutes.


February 02, 2008
Ah, that's good news.  I just did the download, and didn't think to check out the latest trunk.

Thanks again.

-[Unknown]

Jarrett Billingsley wrote:
> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo2i09$280r$1@digitalmars.com...
>> Yes, I looked at that and tried it, but I'm afraid I may not have the time right now to port it from Mango to using Tango...
> 
> It already uses Tango, and doesn't depend on Mango anymore, AFAIK.  I was able to get it installed and working in a couple minutes. 
> 
> 
February 04, 2008
Jarrett Billingsley wrote:
> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo0p7c$1tbq$1@digitalmars.com...
>> Okay.
>>
>> Example "plugin" example.d:
>>
>> ---
>> module example;
>>
>> extern (C)
>> export int foo();
> 
> Ohhh, _there_ it is; I think this bit got cut out of the original post :)
> 
>> I don't have the Linux loader in front of me but it's almost exactly the same and works just fine (LoadLibraryA => dlopen, GetProcAddress => dlsym, FreeLibrary => dlclose, with some dlerror logic in there.)  But as stated, it appears that there's really no "reverse linking" of DLLs.
> 
> As in having DLLs link to symbols exported from the app?  Right, it's not possible without some hackery.  I'm not sure how to do it but apparently it can be done.  I think there are restrictions on it, though.
> 
> DLLs really *are* an awful approximation of SOs :( 
> 
> 

Ive never had problems resolving an .exe's exported symbols at runtime. Dunno why it would be an issue doing it from inside a DLL.

x = GetModuleHandle(NULL); // handle to image that created the process
GetProcAddress(x, "foo_"); // or "foo" depending how the compiler generates C symbols
February 04, 2008
I'm not wanting to have to do that from the DLL.

Here's a practical example:

void plugin_function ()
{
	if (ask_host_for_something() != 42)
		tell_host_about_error("Oh no!");
}

I suppose you're suggesting I could either use GetModuleHandle(NULL) by passing it to the plugin, or from within the plugin (unclear but at least it makes this doable, though annoying.)  However, even then, .so files are simpler - it sets up the symbols for me.  I don't have to GetProcAddress any of them.

-[Unknown]


Neal Alexander wrote:
> Jarrett Billingsley wrote:
>> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo0p7c$1tbq$1@digitalmars.com...
>>> Okay.
>>>
>>> Example "plugin" example.d:
>>>
>>> ---
>>> module example;
>>>
>>> extern (C)
>>> export int foo();
>>
>> Ohhh, _there_ it is; I think this bit got cut out of the original post :)
>>
>>> I don't have the Linux loader in front of me but it's almost exactly the same and works just fine (LoadLibraryA => dlopen, GetProcAddress => dlsym, FreeLibrary => dlclose, with some dlerror logic in there.)  But as stated, it appears that there's really no "reverse linking" of DLLs.
>>
>> As in having DLLs link to symbols exported from the app?  Right, it's not possible without some hackery.  I'm not sure how to do it but apparently it can be done.  I think there are restrictions on it, though.
>>
>> DLLs really *are* an awful approximation of SOs :(
>>
> 
> Ive never had problems resolving an .exe's exported symbols at runtime. Dunno why it would be an issue doing it from inside a DLL.
> 
> x = GetModuleHandle(NULL); // handle to image that created the process
> GetProcAddress(x, "foo_"); // or "foo" depending how the compiler generates C symbols
February 04, 2008
Jarrett Billingsley:
> However there's hope: DDL.  http://www.dsource.org/projects/ddl

It looks really nice.
Regarding the Quick DDL Tutorial:
http://www.dsource.org/projects/ddl/wiki/Tutorial/UsingDDL/Quick
I think the interface may be eventually simplified to something like this (it may perform the "dmd -c plugin.d" too if needed):

import std.stdio, ddl;
void main(){
  auto plugin = dlink("plugin.d");
  if (plugin.hasFunction("helloWorld")) {
    auto hello = plugin.Func!(string function(), "helloWorld");
    writefln(hello());
  }
}

(Or/and equivalent for Tango).

Bye,
bearophile
February 05, 2008
Hello again,

I dont't suppose you might tell me what revision?  I couldn't get the latest trunk to work for me... I was getting the same pointer back from getDExport whether I linked and registered or not.  I was trying the host.d and mule.d example files... perhaps I did something wrong?

Thanks,
-[Unknown]


Jarrett Billingsley wrote:
> "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo2i09$280r$1@digitalmars.com...
>> Yes, I looked at that and tried it, but I'm afraid I may not have the time right now to port it from Mango to using Tango...
> 
> It already uses Tango, and doesn't depend on Mango anymore, AFAIK.  I was able to get it installed and working in a couple minutes. 
> 
> 
February 05, 2008
"Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:fo8t44$2v0j$1@digitalmars.com...
> Hello again,
>
> I dont't suppose you might tell me what revision?  I couldn't get the latest trunk to work for me... I was getting the same pointer back from getDExport whether I linked and registered or not.  I was trying the host.d and mule.d example files... perhaps I did something wrong?

I have 286.