Thread: Compile error by shlwapi library

  1. #1
    Registered User
    Join Date
    Mar 2010

    Compile error by shlwapi library


    I am getting a compile error in my Win32 C++ application & I believe its because I dont have the shlwapi library.

    First off do you agree that I am getting the below error because I dont have the library or is it something else

    [Linker error] undefined reference to '_imp_PathFileExistsA@4'
    [Linker error] undefined reference to '_imp_PathAppendA@8'
    Id returned 1 exit status
    [Build error] ["Find] Error 1
    And second is there another way to get the shlwapi library WITHOUT having to download the whole 1gig SDK from Microsoft? I realllly hope there is.

    Can you provide me with any advice on the directory path where I save the shlwapi lib file when/if I get it. This is a point I really struggle with, call it funny or really lame but I cant find the path to my Microsoft SDK on my computer(its vista).

    Here's my app below & I am coding in Dev C++:
    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    #include <vector>
    #include <string>
    #include <cstdlib>
    #include "Shlwapi.h" // necessary for PathFileExists()
    #include <shlobj.h>  // necessary for SHGetFolderPath()
    using namespace std;
    #define ID_FOLDERPATH1 1
    #define ID_FOLDERPATH2 2
    #define ID_FOLDERPATH3 3
    #define ID_GETPATH     4
    static HINSTANCE gInstance;
    // Functions List //
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    void displayRecentPaths(HWND hwnd, UINT controlMsg[]);
    void recordRecentPaths(HWND hwnd, UINT controlMsg[]);
    string getFolderPath(HWND hwnd);
    vector<string> readFile(string fileName);
    void writeFile(string fileName, vector<string> content);
    int WINAPI WinMain(HINSTANCE gInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
        //Step 1: Registering the Window Class
        wc.cbSize        = sizeof(WNDCLASSEX);         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = gInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(DKGRAY_BRUSH);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "My Class";
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
        // if registration of main class fails
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            "My Class",
            "Find Application Data",
            CW_USEDEFAULT, CW_USEDEFAULT, 600, 500,
            NULL, NULL, gInstance, NULL);
        if(hwnd == NULL)
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        ShowWindow(hwnd, nCmdShow);
        // Step 3: The Message Loop
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        return Msg.wParam;
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
            case WM_CREATE:
                 HWND hEdit = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                 HWND hEdit1 = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                 HWND hEdit2 = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                 HWND hButton = CreateWindowEx(0,"Button","Random",WS_VISIBLE|WS_CHILD|WS_BORDER|BS_PUSHBUTTON,
            case WM_COMMAND:
                switch (LOWORD(wParam)) {
                      case ID_GETPATH:
                      {    // Find the local computers path to the APP DATA folder regardless of
                           // of which version of windows the local system is using
                           string folderPath;
                           if( SHGetFolderPath(NULL,CSIDL_APPDATA,NULL,
                               0,(LPTSTR)folderPath.c_str()) == S_OK )  
                              HWND hEdit = GetDlgItem(hwnd,ID_FOLDERPATH1);
                              // The below uses the APP DATA path create & store a file in it.
                              // PathAppend(szPath, TEXT("New Doc.txt"));
                              // HANDLE hFile = CreateFile(szPath, ...);
            case WM_CLOSE:
            case WM_DESTROY:
            default: return DefWindowProc(hwnd, msg, wParam, lParam);
    void displayRecentPaths(HWND hwnd,UINT controlMsg[])
       // Post: Read data file for most recent directories accessed. If data file doesn't exist 
       //       then we create it.
       string appDataFile = getFolderPath(hwnd); // get file path
       // if APP DATA file exists: write paths to text file; ELSE create APP DATA file
       if (PathFileExists((LPTSTR)appDataFile.c_str()) == true) {
           vector <string> paths = readFile(appDataFile);
           // display most recent accessed directories in edit boxes
           for (int i=0; i<paths.size(); i++) {          
               HWND hEdit = GetDlgItem(hwnd,controlMsg[i]);
           paths.clear();  // erase paths data (VERY IMPORTANT)
       else {
            //HANDLE hFile = CreateFile((LPTSTR)appDataFile.c_str(), ...); // create file
    void recordRecentPaths(HWND hwnd, UINT controlMsg[])
       // Post: Saves the most recent folder directories accessed by application
       HWND hEdit;
       vector<string>paths; // SHOULD BE GLOBAL
       // Get folder paths
       for (int i=0; i<3; i++) {
           int len = GetWindowTextLength(GetDlgItem(hwnd,controlMsg[i]));
           // if window has text in it
           if (len > 0) {
               char buffer[len+2];
       string appDataFile; // = getFolderPath;
       // Save paths to folder
       if (paths.size() > 0) {
    string getFolderPath(HWND hwnd)
       // Post: Returns the path to specified folder
       string folderPath;
       if( SHGetFolderPath(NULL,CSIDL_APPDATA,NULL,0,(LPTSTR)folderPath.c_str()) == S_OK )  
          return folderPath;
       else {
          MessageBox(hwnd,"Failed to retrieve path to APP DATA folder","Error",MB_OK|MB_ICONERROR);
    vector<string> readFile(string fileName)
       // Post: Reads a file & stores contents line by line in vector
       ifstream infile;
       vector<string> result;        // vector to store contents of file in
       string tempStr;
       if (!infile) {
           MessageBox(NULL,"Failed to read randomPlaylistPathData.txt file","Error",
       while (!infile.eof()) {       
       return result;
    void writeFile(string fileName, vector<string> content)
       // Post: Write vector to text file(fileName) line by line
       ofstream outfile;
       if (!outfile) {
           MessageBox(NULL,"Failed to write to randomPlaylistPathData.txt file","Error",
       for (int i=0; i<content.size(); i++) {
            outfile << << "\n";

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The lib might not be part of your Dev-C++ library, but the DLL should be underneath your c:\windows directory somewhere.

    There is a dev-c++ tool (I can't remember the name) which allows you to create the appropriate lib (that dev-c++ can use), given an existing .dll file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help building/linking to static library
    By Kernel Sanders in forum C++ Programming
    Replies: 19
    Last Post: 08-17-2008, 04:35 PM
  2. Library Wrapper
    By cusavior in forum C Programming
    Replies: 3
    Last Post: 03-25-2008, 10:27 AM
  3. Need help with audio library on DOS...
    By Marton79 in forum C Programming
    Replies: 10
    Last Post: 08-25-2006, 12:32 AM
  4. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 02:32 AM