Skip to content

Commit

Permalink
loadLib return bool
Browse files Browse the repository at this point in the history
  • Loading branch information
dushibaiyu committed Aug 14, 2017
1 parent 5084b4b commit 7de19b7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/yu/tools/sharedlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@ nothrow:

@property bool isValid() const { return _handle !is null; }

void loadLib(string name)
bool loadLib(string name)
{
unloadLib();
if(name.length == 0)
return;
return false;
version(Posix){
auto str = CStr!Mallocator(name);
_handle = dlopen(str.ptr,RTLD_LAZY);
} else {
import core.stdc.stddef;
auto len = MultiByteToWideChar(CP_UTF8, 0, name.ptr, cast(int)name.length, null, 0);
if (len == 0) return;
if (len == 0) return false;
auto buf = cast(wchar_t[])Mallocator.instance.allocate((len+1) * wchar_t.sizeof);
if (buf.ptr is null) return;
if (buf.ptr is null) return false;
scope(exit) Mallocator.instance.deallocate(buf);
len = MultiByteToWideChar(CP_UTF8, 0, name.ptr, cast(int)name.length, buf.ptr, len);
if (len == 0) return;
if (len == 0) return false;
buf[len] = '\0';
_handle = LoadLibraryW(buf.ptr);
}
return isValid();
}

void unloadLib()
Expand Down

0 comments on commit 7de19b7

Please sign in to comment.