Thread overview |
---|
November 27, 2013 dynamic use dll or so file error! | ||||
---|---|---|---|---|
| ||||
I want to access dynamic libraries on different platforms, but I still can not get the function, so do not write it? Where is wrong? import core.runtime; import std.stdio; import std.string; version(Windows) { import std.c.windows.windows; } else version(Posix) { import core.stdc.stdio; import core.stdc.stdlib; import core.sys.posix.dlfcn; } void* getSymbolAddress(void* handle, string name) { version(Windows) { FARPROC proc = GetProcAddress(cast(HMODULE)handle, name.ptr); if (proc is null) { writefln(": can't resolve symbol "~name); return null; } return cast(void*)proc; } else version(Posix) { auto cstr = toStringz(symbol); return dlsym(handle, cstr); } } struct Binder(T) { void opCall(string name, void* lib) { *fptr = getSymbolAddress(lib, name); writefln("111111111111111111111"~name); } private void** fptr; } template bindFunc(T) { Binder!(T) bindFunc(inout T a) { Binder!(T) res; res.fptr = cast(void**)&a; return res; } } extern (C) { void function() net_tcp_send; } void LoadPlatform(void* lib) { bindFunc(net_tcp_send)("net_tcp_send", lib); } int main() { void* hp = Runtime.loadLibrary("ShuNet.dll".dup); if(hp is null) { writefln("error loading ShuNet.dll"); return 1; } writefln("ShuNet.dll is loaded"); LoadPlatform(hp); printf("net_tcp_send=>%p", net_tcp_send); net_tcp_send(); // this error if(!Runtime.unloadLibrary(hp)) { writefln("error freeing ShuNet.dll"); return 1; } writefln("End..."); return 0; } |
November 27, 2013 Re: dynamic use dll or so file error! | ||||
---|---|---|---|---|
| ||||
Posted in reply to master | On Wednesday, 27 November 2013 at 14:33:21 UTC, master wrote:
> I want to access dynamic libraries on different platforms, but I still can not get the function, so do not write it? Where is wrong?
runtime.loadlibrary is not yet finished. use dlopen/LoadLibrary instead(forgot about loading D dll's though, its not going to work this way properly(i mean GC/Runtime attaching))
|
November 28, 2013 Re: dynamic use dll or so file error! | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | On Wednesday, 27 November 2013 at 15:09:45 UTC, evilrat wrote:
> On Wednesday, 27 November 2013 at 14:33:21 UTC, master wrote:
>> I want to access dynamic libraries on different platforms, but I still can not get the function, so do not write it? Where is wrong?
>
> runtime.loadlibrary is not yet finished. use dlopen/LoadLibrary instead(forgot about loading D dll's though, its not going to work this way properly(i mean GC/Runtime attaching))
Unfinished? Amount. . .
I am writing with reference to forward and, in theory, is finished.
Call Walter Bright old man!
|
November 28, 2013 Re: dynamic use dll or so file error! | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | On Wednesday, 27 November 2013 at 15:09:45 UTC, evilrat wrote: > On Wednesday, 27 November 2013 at 14:33:21 UTC, master wrote: >> I want to access dynamic libraries on different platforms, but I still can not get the function, so do not write it? Where is wrong? > > runtime.loadlibrary is not yet finished. use dlopen/LoadLibrary instead(forgot about loading D dll's though, its not going to work this way properly(i mean GC/Runtime attaching)) Unfinished? Amount. . . I am writing with reference to the http://dlang.org/dll-linux.html and http://dlang.org/dll.html, in theory, is finished. Calls Walter Bright old man! help me! |
November 28, 2013 Re: dynamic use dll or so file error! | ||||
---|---|---|---|---|
| ||||
Posted in reply to master | On Thursday, 28 November 2013 at 11:33:05 UTC, master wrote:
> On Wednesday, 27 November 2013 at 15:09:45 UTC, evilrat wrote:
>> On Wednesday, 27 November 2013 at 14:33:21 UTC, master wrote:
>>> I want to access dynamic libraries on different platforms, but I still can not get the function, so do not write it? Where is wrong?
>>
>> runtime.loadlibrary is not yet finished. use dlopen/LoadLibrary instead(forgot about loading D dll's though, its not going to work this way properly(i mean GC/Runtime attaching))
>
>
> Unfinished? Amount. . .
> I am writing with reference to the http://dlang.org/dll-linux.html and http://dlang.org/dll.html, in theory, is finished. Calls Walter Bright old man! help me!
haha!
Binder!(T) bindFunc(inout T a)
is inout error!
|
Copyright © 1999-2021 by the D Language Foundation