Comments (16)
Can you give a reduced test case? What does dlerror
output?
from dlfcn-win32.
dlerror output is not complete for some reason, which makes it harder to
debug.
dlerror() shows "OpenCL.dll: T"
I don't know what that means.
On Tue, Apr 7, 2015 at 1:49 PM, Timothy Gu [email protected] wrote:
Can you give a reduced test case? What does dlerror output?
—
Reply to this email directly or view it on GitHub
#19 (comment)
.
from dlfcn-win32.
The code I used is:
void * handle = dlopen("C:\\Windows\\System32\\OpenCL.dll", RTLD_LAZY);
if( handle == NULL )
{
printf("Error code %s", dlerror());
return -1;
}
from dlfcn-win32.
What language is your Windows system running on? The message is supposed to be localized.
from dlfcn-win32.
Also, you shouldn't need to add the full path. Simply dlopen("OpenCL.dll")
should work.
from dlfcn-win32.
I think the problem might be because of the LPSTR
type cast before the lpFileName:
hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH );
While LoadLibraryEx
is defined as follows:
#ifdef UNICODE
#define LoadLibraryEx LoadLibraryExW
#else
#define LoadLibraryEx LoadLibraryExA
#endif // !UNICODE
The language setting of my Windows is English. The non-unicode language is English, see 1.png.
So in my VS2012 project, I chose "Use Unicode charset", see 2.png
then I got 126 error, and dlerror() reports "OpenCL.dll: T", see 3.png
Actually, when compiling, you will see the following warning:
1>c:\github\openclz\testdll\testdll\dlfcn.c(170): warning C4133: 'function' : incompatible types - from 'char *' to 'LPWSTR'
1>c:\github\openclz\testdll\testdll\dlfcn.c(260): warning C4133: 'function' : incompatible types - from 'LPSTR' to 'LPCWSTR'
If I change the VS2012 settings to "Use multi-byte charset", then the dll can be opened correctly.
So, it seems that the dlfcn library should be revised to support both unicode and wide char.
from dlfcn-win32.
Change
hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH );
to
#ifdef UNICODE
wchar_t wtext[1024];
mbstowcs(wtext, lpFileName, strlen(lpFileName) + 1);
LPWSTR lpwstr = wtext;
hModule = LoadLibraryEx(lpwstr, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH );
#else
hModule = LoadLibraryEx( (LPCSTR) lpFileName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH );
#endif
By using this, I can open the library in Unicode mode.
Except for LoadLibraryEx(), there is another place need to be changed. The following code gives error: dlfcn.c(170): warning C4133: 'function' : incompatible types - from 'char *' to 'LPWSTR'
pos += FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwMessageId,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
error_buffer+pos, sizeof(error_buffer)-pos, NULL );
from dlfcn-win32.
I can help fix these two place. Should I go ahead to start a pull request?
from dlfcn-win32.
Yes please!
from dlfcn-win32.
While at it you can change the default to unicode too.
from dlfcn-win32.
Sure. I will work on it tonight.
I will try to make as minimal changes as I can, but support both wchar and unicode.
from dlfcn-win32.
@robertwgh you know what you can just drop the support for multibyte. Nobody (should) use it anymore.
Also wchar_t
is Unicode in Windows IIRC.
from dlfcn-win32.
I think the current code works well for multibyte. We had better keep it
just in case someone need it for some legacy projects.
Plus, there are not much to modify. Probably just a few places.
Using #ifdef _UNICODE should be clean enough.
On Tue, Apr 7, 2015 at 4:25 PM, Timothy Gu [email protected] wrote:
@robertwgh https://github.com/robertwgh you know what you can just drop
the support for multibyte. Nobody (should) use it anymore.Also wchar_t is Unicode in Windows IIRC.
—
Reply to this email directly or view it on GitHub
#19 (comment)
.
from dlfcn-win32.
Ok sounds good.
from dlfcn-win32.
Should be fixed in aa1401b
from dlfcn-win32.
Solution in commit aa1401b is too long, complicated and adds lot of useless code. The main problem is that you should call LoadLibraryExA
for Unicode builds (not LoadLibraryEx
or LoadLibraryExW
). Similarly with FormatMessageA
. Fix is in pull request #50
from dlfcn-win32.
Related Issues (20)
- Understand why settting cmake_minimum_required to 3.20 make test fail HOT 1
- Use of LoadLibraryExA with LOAD_WITH_ALTERED_SEARCH_PATH flag HOT 9
- config.mak: No such file or directory HOT 5
- can I dlsym malloc function? HOT 5
- Add support and docs for using dlfcn-win32 using CMake's FetchContent module HOT 1
- Installation instructions HOT 7
- MAX_PATH restriction feasible after Windows dropped it for Win10? HOT 3
- ERROR Non-library file %TEMP%\temp.dll was processed via WINAPI: 18 From line 138 HOT 3
- Should common subset of ZDICT_cover_params_t and ZDICT_fastCover_params_t be moved into a separate struct and put it into the front of the struct, implementing inheritance this way? HOT 1
- UTF-8 path failes to dlopen HOT 11
- Add automatic tests with Dr. Memory
- dlsym multiple defintion HOT 2
- undefined reference to `GetModuleHandleExA' HOT 6
- AppVeyor test problems HOT 4
- Using dlfcn-win32 as a subproject of libbacktrace, gollvm HOT 3
- Write docs on how to use the dlfcn-win32 in a buildsystem agnostic way
- no RTLD_NOLOAD HOT 6
- Add support to dladdr() to inspect export table for additional symbols
- Release 1.3.0 HOT 7
- Testing i586-mingw32msvc-gcc builds via cmake HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dlfcn-win32.