Is it possible that DllMain returns an error ??

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Is it possible that DllMain returns an error ??

Post by zmau »

Hello all,
I have a funny issue - On a Windows platform.
I have a DLL which uses wxWidgets - lets call it MyDll.dll (actually it only uses "xwbase30_vc" + "xwmsw30_core_vc").
There are 2 different applications :
  • Application_A - successfully loads MyDll.dll
  • Application_B - fails to load MyDll.dll
Both applications exist on the same directory of the same computer.

The only difference that I am aware of is this :
Application_A - automatically loads MyDll.dll (upon it's own loading).
Application_B - uses LoadLibrary() to load MyDll.dll (at some point during running).

The main explanation that I could come up with is that DllMain might return FALSE, and that Windows somehow treats the "FALSE" differently.

You can see the documentation of LoadLibrary in https://docs.microsoft.com/en-us/window ... adlibrarya.

But, I could not find DllMain in the sources, so I had decided to ask here.

Any clue ?


Thanks
zmau
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible that DllMain returns an error ??

Post by doublemax »

Application_A - successfully loads MyDll.dll
Application_B - fails to load MyDll.dll
Do both apps also use wxWidgets?
Do they both link to the same CRT as the DLL?

Try https://www.dependencywalker.com to check if there is any dependency that fails.
Use the source, Luke!
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

doublemax wrote: Sun Sep 19, 2021 9:15 pm Do both apps also use wxWidgets?
Both applications do not use wxWidgets (only MyDll.dll does that).
doublemax wrote: Sun Sep 19, 2021 9:15 pm Do they both link to the same CRT as the DLL?
NO.
Application_A (the one which succeeds) was built with the same Visual_Studio_2015
Application_B (the one which fails) was built with another Visual_Studio (this one also has a "million DLLs"

doublemax wrote: Sun Sep 19, 2021 9:15 pm Try https://www.dependencywalker.com to check if there is any dependency that fails.
Does not help - it shows that all of the "SubDlls" are found.


Thanks
zmau
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible that DllMain returns an error ??

Post by doublemax »

What's the error code you get from GetLastError()?
Use the source, Luke!
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Is it possible that DllMain returns an error ??

Post by stahta01 »

wxWidgets is an C++ library; C++ uses name mangling!

The two compiler likely uses different name mangling therefore the DLL will likely only work with the one with match name mangling.

Tim S.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it possible that DllMain returns an error ??

Post by ONEEYEMAN »

Hi,
Did you build both applications?
If you did - open both solutions open project properties and check whether you are linking with the same CRT. And make sure you build both applications with the same options.

Thank you.
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

doublemax wrote: Mon Sep 20, 2021 4:57 am What's the error code you get from GetLastError()?
I do not Know, I do not have that application's code :-(
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

ONEEYEMAN wrote: Mon Sep 20, 2021 12:20 pm Did you build both applications?
I had built everything that succeeds : wxWidgets, MyDll.Dll and "Application A" (the one which succeeds).
My problem is that I do not have the source of "Application B".
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

stahta01 wrote: Mon Sep 20, 2021 6:09 am wxWidgets is an C++ library; C++ uses name mangling!
The two compiler likely uses different name mangling therefore the DLL will likely only work with the one with match name mangling.
I think that this can not be the explanation, since MyDll.dd and wxWidgets where built by the same compiler.

Thanks anyway.
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

Thank you everybody for answering.
I think that this is enough for now.
The answer to my original question is probably "NO" - it is not possible that DllMain returns an error (otherwise people would have said something about it).
I am trying to approach the provider of "Application B". I will let you all know the results.

thanks
zmau
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

Hello all, once again.
Some progress had been made.

The problems now seems to be completely as a "wxWidgets problem" - but it is really funny.

The problem seems to be defined as follows :
  • If an application is trying to load MyDll.dll automatically - then every thing works just fine.
  • If an application is trying to load MyDll.dll via LoadLibrary() - then it fails with an access violation in "wxbase30_vc_custom.dll". This is true even if the application is a "one line application" (only LoadLibrary())
I am sorry, but it looks as simple as that.
A few more things :
  • MyDll.dll does not do anything that is related to wxWidgets except defining a pointer to wxProgressDialog and setting it to NULL.
  • If I completely remove all code which is relevant to wxWidgets from MyDll.dll - then everything works just fine.
  • I am using wxWidgets 3.03.

Any advice ?


thanks
zmau
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible that DllMain returns an error ??

Post by doublemax »

Please try the same with "my_dll" from the "dll" sample that comes with wxWidgets.
And read the "README.txt" in the same directory.
Use the source, Luke!
zmau
Knows some wx things
Knows some wx things
Posts: 47
Joined: Wed Jun 15, 2016 11:41 am

Re: Is it possible that DllMain returns an error ??

Post by zmau »

doublemax wrote: Thu Sep 30, 2021 3:56 pm And read the "README.txt" in the same directory.
Doing that would force me to change the project of "my_dll" from the "dll" sample (because that DLL uses the UNICODE versions of all of the wx Dlls, and "MyDll.dll" uses the NON-UNICODE versions of all of the wx Dlls). I am not sure how should I change the settings in order to achieve that.
doublemax wrote: Thu Sep 30, 2021 3:56 pm And read the "README.txt" in the same directory.
Didn't help me much (for example what is the purpose of the 3 projects (vc9_my_dll, vc9_sdk_exe & vc9_wx_exe))
But it gave an idea to test the idea of statically linking "MyDll.dll". How shall I do this ? I other words
  • How do I build WX so that it will create statically linked libraries ?
  • How do I point my workspace to link to the statically linked libraries ?
==========================================================
More progress on the matter (or going backwards...)

It seems that it is possible that the problem exists only on Win_XP (yes, it's still there).
On Windows_7 for example I could not see any problem to LoadLibraty(MyDll.dll).

So, the first thing that came up to me was to rebuild wxWidgets with (visual studio 6 - on a virtual machine).
I was happy to see that there are still project & workspace - but not all sources compile under visual studio 6 (so, I had to leave this direction).
Looking at the errors it seems that VC_6 really can not handle the new code. So, I would consider dropping the VC_6 stuff.

I had tried another direction :
I tried to rebuild all of the wx stuff to match Win_XP.
  • Go into All of the projects of WX, and set "Platform toolset" to "VisualStudio_2015 - Windows_XP (v140_xp)".
  • Delete *.obj from the already built tree
  • Open comandline windows (x86 & x64) and run the same command that I used before - to build wxWidgets (for example "nmake /f makefile.vc BUILD=release SHARED=1 UNICODE=0 TARGET_CPU=X64")
The result was bad - it did not change anything. Did I do this correctly ?


Thanks
zmau
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible that DllMain returns an error ??

Post by doublemax »

zmau wrote: Thu Sep 30, 2021 8:12 pm
  • Go into All of the projects of WX, and set "Platform toolset" to "VisualStudio_2015 - Windows_XP (v140_xp)".
  • Delete *.obj from the already built tree
  • Open comandline windows (x86 & x64) and run the same command that I used before - to build wxWidgets (for example "nmake /f makefile.vc BUILD=release SHARED=1 UNICODE=0 TARGET_CPU=X64")
The VS project files are not used when using nmake, so changing the toolset in VS doesn't work.

Try this:
https://stackoverflow.com/questions/331 ... with-nmake

BTW: Do you really need to build 64bit for XP? The 64bit version of XP was very rarely used.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it possible that DllMain returns an error ??

Post by ONEEYEMAN »

Hi,
WHat you do is (after building wxWidgets), go to the wxWidgets\sampoles\dll and issue exactly the same command you used to build the library,.

Then try to execute the sample.

Do you have any problems doing that?

If you built wxWidgets with UNICODE = 0 (why?) you can build the dll sample with the same setting.

Thank you.
Post Reply