I have an application with a dependency on gdiplus.dll. However, on Windows 2000, since there is no gdiplus.dll (I don't want to ship with the app....asking the user to download is what i want), the exe throws an error (this looks like a system error) saying gdiplus.dll was not detected in the system in the std search paths.

Is there a way to detect and throw a custom dialog before this system error, asking the user to download gdiplus.dll and then try again?

Just search the PATH environment variable for it. In MS-Windows you can do it like this

#include <iostream>
#include <windows.h>
#include <string>
#include <cstdio>
#include <sstream>
using namespace std;

bool search(string path)
{
    WIN32_FIND_DATA data;
    path += "\\gdiplus.dll";
    HANDLE hFind = FindFirstFile(path.c_str(), &data);
    if(hFind != INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return true;
    }
    return false;
}

int main()
{
    char *buf = 0;
    size_t len = 0;
    errno_t err = _dupenv_s(&buf, &len, "PATH");
    if(err == -1)
    {
        cout << "Error getting PATH\n";
        return 1;
    }
    stringstream str(buf);
    string path;
    while( getline(str,path,';') )
    {
        if( search(path) )
        {
            cout << "Found at: \"" << path << "\"\n";
            break;
        }
    }
    free(buf);

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.