linker errors?

This is a discussion on linker errors? within the C++ Programming forums, part of the General Programming Boards category; I am using this code: Code: #include "dll.h" #include <windows.h> #include <string.h> #include <windows.h> #include <objidl.h> #include <ShlObj.h> #if defined(_MSC_VER) ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    7

    linker errors?

    I am using this code:
    Code:
    #include "dll.h"
    #include <windows.h>
    #include <string.h>
    #include <windows.h>
    #include <objidl.h>
    #include <ShlObj.h>
    
    #if defined(_MSC_VER)
    #pragma comment(lib, "ole32.lib")
    #pragma comment(lib, "uuid.lib")
    #endif
    
    // CreateLink - uses the Shell's IShellLink and IPersistFile interfaces 
    //              to create and store a shortcut to the specified object. 
    //
    // Returns the result of calling the member functions of the interfaces. 
    //
    // Parameters:
    // lpszPathObj  - address of a buffer containing the path of the object. 
    // lpszPathLink - address of a buffer containing the path where the 
    //                Shell link is to be stored. 
    // lpszDesc     - address of a buffer containing the description of the 
    //                Shell link. 
    //lpszDir       - Working Directory for the file.
    HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszDir) 
    { 
        CoInitialize(NULL);
        HRESULT hres; 
        IShellLink* psl; 
        // Get a pointer to the IShellLink interface. 
        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); 
        if (SUCCEEDED(hres)) 
        { 
            IPersistFile* ppf; 
     
            // Set the path to the shortcut target and add the description. 
            psl->SetPath(lpszPathObj); 
            psl->SetDescription(lpszDesc); 
            psl->SetWorkingDirectory(lpszDir);
     
            // Query IShellLink for the IPersistFile interface for saving the 
            // shortcut in persistent storage. 
            hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); 
     
            if (SUCCEEDED(hres)) 
            { 
                WCHAR wsz[MAX_PATH]; 
     
                // Ensure that the string is Unicode. 
                MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); 
    			
                // Add code here to check return value from MultiByteWideChar 
                // for success.
     
                // Save the link by calling IPersistFile::Save. 
                hres = ppf->Save(wsz, TRUE); 
                ppf->Release(); 
            } 
            psl->Release(); 
        } 
        return hres; 
    }
    export bool makeShortCut(LPCTSTR exeName, LPCTSTR lnkName, LPCTSTR description, LPCTSTR workingDir)
    {
        LPCTSTR lpszFileName = lnkName;
        LPCTSTR lpszShortcutDesc = exeName;
        LPCTSTR lpszShortcutPath = description;
        LPCTSTR pszDir= workingDir;
        return(CreateLink(lpszFileName, lpszShortcutDesc, lpszShortcutPath, pszDir));
    }
    and I am getting:
    [Linker error] undefined reference to `CoInitialize@4'
    [Linker error] undefined reference to `CoCreateInstance@20'
    [Linker error] undefined reference to `IID_IPersistFile'
    ld returned 1 exit status
    C:\Dev-Cpp\Projects\TestDLL\Makefile.win [Build Error] [Test.dll] Error 1
    I am using Dev-C++ anybody no what I did wrong?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    From the Dev-C++ menu: Project -> Project Options -> Parameters tab -> Add Library or Object
    Navigate to the "lib" folder within the Dev-C++ installation folder.
    Add the files libole32.a and libuuid.a.

    gg

  3. #3
    msp
    msp is offline
    Registered User msp's Avatar
    Join Date
    Jul 2007
    Location
    in
    Posts
    31
    Hi Codeplug!
    But what these lines are doing in his code?
    I think they are supposed to have the same effect?
    Code:
    #if defined(_MSC_VER)
    #pragma comment(lib, "ole32.lib")
    #pragma comment(lib, "uuid.lib")
    #endif

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Yes, but they are for VC++. They only run if _MSC_VER is defined and that is only defined in Visual Studio.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    7

    Ok it works but

    It works and it creates the shortcut it is supposed to create but it freezes up indefinatly. Do I need to cleanup something?

    What is causing this to happen and how can I stop it?
    Last edited by X3no; 09-05-2007 at 03:24 PM.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    The only thing I can see in what you've posted so far is that you don't have a balancing CoUninitialize.

    So lets see the code that's calling the dll - unless calling CoUninitialize fixes it...

    gg

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    7
    Quote Originally Posted by Codeplug View Post
    The only thing I can see in what you've posted so far is that you don't have a balancing CoUninitialize.

    So lets see the code that's calling the dll - unless calling CoUninitialize fixes it...

    gg
    CoUninitialize didn't fix it and my dll calling code isn't written in C or C++.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Write a small C/C++ app that just calls your DLL so you can rule out the DLL as the source of the issue.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker errors
    By jw232 in forum C++ Programming
    Replies: 3
    Last Post: 06-12-2009, 12:56 PM
  2. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  3. Sneaky little linker errors...
    By Tozar in forum C++ Programming
    Replies: 8
    Last Post: 10-25-2006, 05:40 AM
  4. why am i getting linker errors?
    By dantestwin in forum C++ Programming
    Replies: 11
    Last Post: 07-08-2004, 10:34 AM
  5. Linker errors with Visual C++
    By codegirl in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2003, 09:20 AM

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