C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2010, 02:22 AM   #1
Registered User
 
Join Date: Mar 2010
Posts: 1
Compile error by shlwapi library

Hi

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

Quote:
[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++:
Code:
#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;
UINT controlMsgs[] = {ID_FOLDERPATH1,ID_FOLDERPATH2,ID_FOLDERPATH3};

// 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);
    wc.style         = 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
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        "My Class",
        "Find Application Data",
        WS_OVERLAPPEDWINDOW,
        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);
    UpdateWindow(hwnd);
    
    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    
    switch(msg)
    {
        case WM_CREATE:
        {      
             HWND hEdit = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                                         10,10,170,20,hwnd,(HMENU)ID_FOLDERPATH1,gInstance,NULL);
             
             HWND hEdit1 = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                                         10,35,170,20,hwnd,(HMENU)ID_FOLDERPATH2,gInstance,NULL);
             
             HWND hEdit2 = CreateWindowEx(0,"Edit","path captured here...",WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,
                                         10,60,170,20,hwnd,(HMENU)ID_FOLDERPATH3,gInstance,NULL);                                  
             
             HWND hButton = CreateWindowEx(0,"Button","Random",WS_VISIBLE|WS_CHILD|WS_BORDER|BS_PUSHBUTTON,
                                         60,85,120,20,hwnd,(HMENU)ID_GETPATH,gInstance,NULL);          
        }
        break;
        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);
                          SetWindowText(hEdit,folderPath.c_str());
                          // The below uses the APP DATA path create & store a file in it.
                          // PathAppend(szPath, TEXT("New Doc.txt"));
                          // HANDLE hFile = CreateFile(szPath, ...);
                       }
                       
                  }     
                  break;
                  default:
                  break; 
            } 
        }
        break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default: return DefWindowProc(hwnd, msg, wParam, lParam);
        break;
    }
}

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]);
           SetWindowText(hEdit,(LPTSTR)paths.at(i).c_str());
       }
       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];
           GetDlgItemText(hwnd,controlMsg[i],buffer,sizeof(buffer));
           paths.push_back((string)buffer);
       }
   }
   
   string appDataFile; // = getFolderPath;
   
   // Save paths to folder
   if (paths.size() > 0) {
       writeFile(appDataFile,paths);
   }
}

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 )  
   {
      PathAppend((LPTSTR)folderPath.c_str(),("RandomPlaylistPathData.txt"));
      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;
   
   infile.open(fileName.c_str());
   
   if (!infile) {
       MessageBox(NULL,"Failed to read randomPlaylistPathData.txt file","Error",
                  MB_OK|MB_ICONERROR);
   }
   
   while (!infile.eof()) {       
        getline(infile,tempStr,'\n');
        result.push_back(tempStr);
   }
   
   infile.close();
   
   return result;
}

void writeFile(string fileName, vector<string> content)
{
   // Post: Write vector to text file(fileName) line by line
   
   ofstream outfile;
       
   outfile.open((LPTSTR)fileName.c_str());
   
   if (!outfile) {
       MessageBox(NULL,"Failed to write to randomPlaylistPathData.txt file","Error",
                  MB_OK|MB_ICONERROR);
   }
       
   for (int i=0; i<content.size(); i++) {
           
        outfile << content.at(i) << "\n";
   }
       
   outfile.close();
}
gretty is offline   Reply With Quote
Old 03-16-2010, 10:56 AM   #2
and the hat of Destiny
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 22,495
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.

Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22