Search code examples
c++cvisual-studio-2012bluetoothwindows-server-2012

conditionally skipping dll dependencies


I'm writing a Win8 desktop app to monitor bluetooth status (among other functionalities) using Visual Studio 2012. I've specified Bthprops.lib in the project properties--> additional dependencies. I built a DLL with the bluetooth code and invoke it from a C# project.

Everything works well on Win8. However, when my app is ran on Windows Server 2012, at start-up I get the unable to load DLL because win server 2012 doesn't support bluetooth and doesn't have the dependent bthprops.cpl.

Since I want my app to work on multiple platforms (and don't want users to install additional components), in situations where the platform doesn't have the required dependent file, I want the app to be able to start, skip executing the bluetooth code, and perform the rest of the functionalities.

Is this possible? How would I achieve this?

Thank you


Solution

  • I fear you have to dynamically load the dll using LoadLibrary(). With that, you don't have the dependency on startup. Additionally, you can check whether loading succeded. If it didn't, the component is not installed. This makes it perferable to mis-using the delayloading mechanism.

    In that case, you don't use a library file. Instead, you simply use either a header file or you find the appropriate dll functions using GetProcAddress()