Choosing DLL to use depending on OS version

Started by
12 comments, last by DividedByZero 5 years, 5 months ago

Hi Guys,

I have a scenario where I am trying to call a function from a DLL but the problem is Microsoft has put the function in different DLL's depending on what OS is used.

'MFCreateDXGIDeviceManager' is in mshtmlmedia.dll in Windows 7 and Vista but is in mfplat.dll in Windows 8 and above.

I can figure out easily enough what OS my application is running on, but I don't know how to tell it to reference the correct DLL given the OS.

Is there a way to choose the correct DLL at run-time?

This one has had me stumped for several years now, but the time has come where I have to revisit the problem. In this occasion having two separate exe's (i.e. a Win 7 and Win 8+) is not really an option unfortunately.

Many thanks in advance. :)

 

Advertisement

You can load the Library manually with the LoadLibraryA/LoadLibraryW function. With the handle of the loaded library, you can get a pointer to your function with GetProcAddress. All three are located in Kernel32.dll. More information you can find in the Windows-documentation: https://docs.microsoft.com/de-at/windows/desktop/Dlls/using-run-time-dynamic-linking

The difference between the LoadLibraryA and LoadLibraryW function is how the library-filename is encoded. The A-version takes regular ASCII characters and the W-version takes wchar_t which is a 2-byte character.

Dynamically load the DLL using LoadLibrary and get the function address using GetProcAddress

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

This is the problem with using unsupported functionality. MFCreateDXGIDeviceManager is supported in Win8+, and not really guaranteed to even remain exposed in the DLL you're using it from in Win7.

If you do indeed want to use it, then yes, LoadLibrary()/GetProcAddress() is the way to do it. I would suggest finding a different way of solving the problem you're trying to solve if you indeed want to support Win7 though.

If you look at the documentation it mentions that the minimum client support is windows 8 which means you should not be using this in Windows 7 at all.

Besides writing your own device manager is not that hard and requires about 100 lines of code.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Thanks for the replies guys, I will take this all on board.

 

7 minutes ago, NightCreature83 said:

If you look at the documentation it mentions that the minimum client support is windows 8 which means you should not be using this in Windows 7 at all.

Besides writing your own device manager is not that hard and requires about 100 lines of code.

Any hints on where I would start with such a task? 

I have googled it but it keeps bouncing me back to the unsupported IMFDXGIDeviceManager.

Essentially, if I can figure out how to get the pointer to the video texture using MMF then I'd have no problems sorting out the locking / unlocking of the memory etc.

Thanks again.

Why are you using MMF where you really want to use DirectX?

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

1 hour ago, NightCreature83 said:

Why are you using MMF where you really want to use DirectX?

Not sure how you have come to this conclusion.

DirectX has no knowledge of video codecs, audio codecs, frame decompression, etc...

45 minutes ago, DividedByZero said:

Not sure how you have come to this conclusion.

DirectX has no knowledge of video codecs, audio codecs, frame decompression, etc...

Well this is the first time you mention you need the codecs in this thread so I could not have guessed that, this is gamedevelopment after all and in most cases you would just need the D3D api.

You are using the wrong sections out of the Media Foundation library to support windows 7. And if you are not developing a store app, you can just use the windows 7 api on win 8 and 10.

 

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

1 hour ago, DividedByZero said:

Not sure how you have come to this conclusion.

DirectX has no knowledge of video codecs, audio codecs, frame decompression, etc...

What are you trying to do? I have done quite a bunch of video-related stuff recently, and may be able to help.

This topic is closed to new replies.

Advertisement