Problem in example making a shortcut

I used a compiler MinGW With NetBeans IDE .
I try to make a shortcut file ,This attempt:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <shlobj.h> 

#include <istream>
#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>

using namespace std;


bool CreateShortCut(LPCSTR lpszSourceFile,
    LPCSTR lpszDestination, 
    LPCSTR lpszDesc) 
{ 
    HRESULT  hResult    = NULL; 
    IShellLink* pShellLink = NULL; 
        bool  rc     = false;

        hResult = CoInitialize(NULL);
    // Initialize the IShellLink interface. 
    
        hResult = CoCreateInstance(CLSID_ShellLink, NULL, 
        CLSCTX_INPROC_SERVER, IID_IShellLink, (void**) &pShellLink); 
        // Get a pointer to the IShellLink Interface

    if (SUCCEEDED(hResult)) 
        { 
        IPersistFile* ppf = NULL; 
 
        pShellLink->SetPath(lpszSourceFile); 
        // Set the path to the shortcut target
        
  hResult = pShellLink->SetDescription(lpszDesc); 
  // Add Description

        hResult = pShellLink->QueryInterface(IID_IPersistFile, (void**) &ppf); 
  // Query IShellLink for the IPersistFile interface for saving the 
        // shortcut in persistent storage. 
       
 
        if (SUCCEEDED(hResult)) 
  { 
            WORD wszWideString[MAX_PATH]; 
 
            // Ensure that the string is ANSI. 
            MultiByteToWideChar(CP_ACP, 0, lpszDestination, -1,
        wszWideString, MAX_PATH); 
 
            hResult = ppf->Save(wszWideString, TRUE); 
            // Save the link by calling IPersistFile::Save. 
            
         ppf->Release(); 
         rc = true;
        } 
        pShellLink->Release(); 
  CoUninitialize();
  // Clean up
    } 
        return rc; 
}

int main()
{

  CreateShortCut("C:\\Users\\win7\\Documents\\NetBeansProjects\\iii\\printscrin.exe"
          ,".lnk"
          ,"C:\\Users\\win7\\Documents\\NetBeansProjects\\iii");   
 
  return 0;
}

-----------------------------------
The Output:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/win7/Documents/NetBeansProjects/CppApplication_20'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_TDM-Windows/cppapplication_20.exe
make[2]: Entering directory `/c/Users/win7/Documents/NetBeansProjects/CppApplication_20'
mkdir -p build/Debug/MinGW_TDM-Windows
rm -f build/Debug/MinGW_TDM-Windows/main.o.d
g++.exe -c -g -MMD -MP -MF build/Debug/MinGW_TDM-Windows/main.o.d -o build/Debug/MinGW_TDM-Windows/main.o main.cpp
make[2]: Leaving directory `/c/Users/win7/Documents/NetBeansProjects/CppApplication_20'
make[1]: Leaving directory `/c/Users/win7/Documents/NetBeansProjects/CppApplication_20'
main.cpp: In function 'bool CreateShortCut(LPCSTR, LPCSTR, LPCSTR)':
main.cpp:16:27: warning: converting to non-pointer type 'HRESULT {aka long int}' from NULL [-Wconversion-null]
main.cpp:48:32: error: invalid conversion from 'WORD* {aka short unsigned int*}' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
c:\mingw32\bin\../lib/gcc/mingw32/4.6.1/../../../../include/winnls.h:624:23: error: initializing argument 5 of 'int MultiByteToWideChar(UINT, DWORD, LPCSTR, int, LPWSTR, int)' [-fpermissive]
main.cpp:50:52: error: invalid conversion from 'WORD* {aka short unsigned int*}' to 'LPCOLESTR {aka const wchar_t*}' [-fpermissive]
c:\mingw32\bin\../lib/gcc/mingw32/4.6.1/../../../../include/objidl.h:695:2: error: initializing argument 1 of 'virtual HRESULT IPersistFile::Save(LPCOLESTR, BOOL)' [-fpermissive]
make[2]: *** [build/Debug/MinGW_TDM-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 4s)

---------------------------------------------------

Note code adapted from:http://www.arabteam2000-forum.com/index.php?showtopic=54977&st=0&p=269268&hl=shortcut&fromsearch=1&
wszWideString MUST be of type WCHAR (or wchar_t), NOT WORD. And must link ole32 and uuid libraries to compile and link successfully.
I got the following libraries:
Ole32.Lib
Uuid.Lib
But I do not know how to Adding libraries for the project .
Last edited on
You need libole32.a and libuuid.a if you use MinGW, *.lib files are usually used by Microsoft compiler (or Borland as far as I know).
Topic archived. No new replies allowed.