Let’s take our backup software for example. We want to backup the AD on a
Win2000 machine, but the API isn’t available on NT4, but we do want the sw
to run on NT4/2000 for the same binary. The solution is this:
m_hLibHandle = LoadLibrary(L"NTDSBCLI.DLL");
m_bInitialized = (m_hLibHandle != NULL);
if(m_bInitialized)
{
m_DsIsNTDSOnlineW =
(DsIsNTDSOnlineWFunc)GetProcAddress(m_hLibHandle, “DsIsNTDSOnlineW”);
}
Any place that you wish to call this function becomes:
if(m_bInitialized && m_DsIsNTDSOnlineW)
bFlag = m_DsIsNTDSOnlineW(…);
A real PITA to code.
The reason “why” this is necessary is that if you simply let the linker do
it’s job by using .LIBs is that it will fail to load on OSes where the
library does not contain the imports that are expected. It’s possible to
use the /DELAYLOAD switch in the linker, but this doesn’t deal with
functions that might be missing from DLLs that are expected to be present.
Eg. MoveFileWithProgress will only be found in kernel32.dll on Windows2000.
If there’s an elegant solution to this problem, “I’m all ears”!
Regards,
Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com
-----Original Message-----
From: Bill Casey [mailto:xxxxx@advstor.com]
Sent: Thursday, June 08, 2000 12:10 PM
To: NT Developers Interest List
Subject: [ntdev] RE: 2 DLL versions
Paul:
Can you elucidate why this “nasty coding” is necessary? Leave 3.51
and
Win9x out of the picture for now - just NT and 2000.
Bill
== SCSI Adapters & VirtualSCSI Target Mode Libs ==
-----Original Message-----
No. In fact it is possible to write a single binary that runs on
NT3.51,
4.0, Win9x and 2000. However, it does get a bit nasty coding all those
optional GetProcAddress calls for run-time loading. I believe it’s
possible
to mark imports as optional somehow, but I’ve never really researched
how to
implement that.
Regards,
Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com
-----Original Message-----
From: Bill Casey [mailto:xxxxx@advstor.com]
Sent: Thursday, June 08, 2000 9:44 AM
To: NT Developers Interest List
Subject: [ntdev] 2 DLL versions
I KNOW this is a relatively dumb question but if there are no OS
dependencies in my DLL code, do I need to maintain (i.e. compile)
different versions for NT and 2000? Or will the each binary work on the
opposite OS?