Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Incompatibility of lib file imported in Win7/32 with Win10/64



Permlink Replies: 6 - Last Post: Feb 13, 2018 8:43 PM Last Post By: Alex Belo Threads: [ Previous | Next ]
Alex Belo

Posts: 599
Registered: 10/8/06
Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2018 3:46 AM
Hi all.

I am in process of migration of my development (still in RAD2007) from computer under Win7/32 to computer under Win10/64.

I use dwmapi.lib imorted from dwmapi.dll on Win7/32. All is OK but my program (old exe compiled on Win7/32 or new exe compiled and linked with old lib file on Win10/64) crashes on Win10/64. But after reimportation of the lib in question on Win10 (from Windows\SysWOW64\dwmapi.dll) the problem disappeared and application starts OK.

So the problem is: I can not run
- old exe on Win10 and
- new exe on Win7...

How it can be?..

--
Alex
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 11:15 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:

I use dwmapi.lib imorted from dwmapi.dll on Win7/32. All is OK but
my program (old exe compiled on Win7/32 or new exe compiled and
linked with old lib file on Win10/64) crashes on Win10/64.

Crashes in what way exactly? Please be more specific.

I can not run
- old exe on Win10

I seriously doubt that. Microsoft is very good about backwards
compatibility with old apps.

- new exe on Win7...

Does your code use any DWM APIs that don't exist on Win7?

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 599
Registered: 10/8/06
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 6:13 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Crashes in what way exactly?

Before my WinMain without any message.

Does your code use any DWM APIs that don't exist on Win7?

No, DwmIsCompositionEnabled is the only function I use from dwm.

--
Alex
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 6:35 PM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:

Before my WinMain without any message.

Then how do you know it is crashing? What debugging have you done so
far, if any, to diagnose the problem yourself?

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 599
Registered: 10/8/06
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2018 12:26 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Before my WinMain without any message.

Then how do you know it is crashing?

Without debugger it simply does not start.

Under IDE debugger there are endless AV in some "system" code.

What debugging have you done so far, if any, to diagnose the problem yourself?

From Windows logs:

APPCRASH
Exception code: 0xc0000005 (this is AV as we know)

tdump info.

Old lib:
000570 THEADR DwmIsCompositionEnabled
00058C COMENT Purge: Yes, List: Yes, Class: 160 (0A0h), SubClass: 1 (01h)
Dynamic link import (IMPDEF)
Imported by: ordinal
Internal Name: DwmIsCompositionEnabled
Module Name: dwmapi.dll
ordinal: 144
0005B9 COMENT Purge: Yes, List: Yes, Class: 251 (0FBh), SubClass: 3 (03h)
Hint:15
0005C2 MODEND

Newly imported lib:
000610 THEADR DwmIsCompositionEnabled
00062C COMENT Purge: Yes, List: Yes, Class: 160 (0A0h), SubClass: 1 (01h)
Dynamic link import (IMPDEF)
Imported by: ordinal
Internal Name: DwmIsCompositionEnabled
Module Name: dwmapi.dll
ordinal: 175
000659 COMENT Purge: Yes, List: Yes, Class: 251 (0FBh), SubClass: 3 (03h)
Hint:17
000662 MODEND

The only difference is ordinal number. I don't know if this matters ...

I use DwmIsCompositionEnabled in initialization part of some deplhi package.

--
Alex
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2018 10:15 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:

tdump info.

The only difference is ordinal number. I don't know if this matters

It matters very much. The ordinal values of exported Win32 API
functions can (and sometimes do!) change value between Windows
versions. For example:

Has ordinal index of functions in Windows API dlls ever changed?
https://stackoverflow.com/questions/4533185/

It is dangerous to import a DLL function by ordinal when you don't
control the DLL yourself.

As you can clearly see in your tdump log, the two .lib files you are
using are importing the DwmIsCompositionEnabled() function using
different ordinal values. That means your app's EXE will not work the
same on every Windows version.

I find it odd that the .lib files you are using are importing
DwmIsCompositionEnabled() by ordinal to begin with. There have only
been a very few cases over the years where this has actuallly been
required (for example, the Shell's SHChangeNotify(de)Register()
functions were originally undocumented and exported by ordinal only,
until XP SP1 when they were documented and updated to be exported by
name instead). The .lib files should be importing functions by name
instead. I suggest you regenerate the .lib files using the comand-line
IMPLIB tool, and be sure to enable its '-f' switch ("Force imports by
name").

--
Remy Lebeau (TeamB)
Alex Belo

Posts: 599
Registered: 10/8/06
Re: Incompatibility of lib file imported in Win7/32 with Win10/64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2018 8:43 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

It matters very much.

Ah, that's the answer to the mystery!

I find it odd that the .lib files you are using are importing
DwmIsCompositionEnabled() by ordinal to begin with.
...
I suggest you regenerate the .lib files using the comand-line
IMPLIB tool, and be sure to enable its '-f' switch ("Force imports by
name").

My bad, I just did not pay attention to additional switch.

Many thanks for your help.

--
Alex
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02