subhajit mondal subhajit mondal - 2 months ago 12
C++ Question

pegrp32c.dll and pegrp32d.dll loading in different types of windows

I want to load pegrp32c.dll for WINXP OS version and pegrp32d.dll for WIN7 version. How I can achieve this?
Also i dont have any idea about the above mention third party dll.
someone please expalain what it is how load difference version of dll to different version of windows

Answer

Well, you have to determine current Windows version first using Version Helper functions. Then load a dll using LoadLibrary method. Since you have not mentioned Windows Vista, I assume, that Windows XP rules will be applied for it.

#include <versionhelper.h>
///...
HMODULE hLib = NULL;
if(IsWindows7OrGreater())
{
   hLib = LoadLibrary(L"pegrp32d.dll");
}else
{
   hLib = LoadLibrary(L"pegrp32c.dll");
}

if(!hLib)
   //report an error

If you want to link statically against this libraries, you have to create different versions of your application for Windows XP and Windows 7. You could use WINVER macro to determine target platform and #pragma comment instruction to select lib file to link against.

#if WINVER >= _WIN32_WINNT_WIN7
#pragma comment(lib, "pegrp32d.lib")
#else
#pragma comment(lib, "pegrp32c.lib")
#endif

References:

MSDN Version helper API

MSDN WINVER macro

If you use old version of the Visual Studio you could install latest Platform SDK, or use GetVersion API call, declared in the windows.h. Be advised however, that this method could be unavailable since Windows 8.1 so that approach is not recommended.