본문 바로가기
C & C++/C & C++

인터넷 바로가기 만들기

by izen8 2011. 4. 27.
반응형

#include <stdio.h>
#include <fstream>
#include <string>
#include <vector>

 

void writeTextFile(std::string strFileName,
    std::string& strFileData, bool bApp = false) throw(std::string)
{
    std::ofstream fout;
    if(!bApp) fout.open(strFileName.c_str());
    else fout.open(strFileName.c_str(), std::ios::app);
    if(!fout.is_open())
        throw "In writing " + strFileName + " of WriteTextSTR";
    fout.write(strFileData.data(), strFileData.size());
    fout.close();
}


void makeShortCut(std::string strFileName,
    std::string strURL, std::string strIcon) throw(std::string)
{
    std::string strShortCut("[InternetShortcut]\nURL=");
    std::string str1("\nIconIndex=0\nIconFile=");
    std::string str2("\nModified=000000000000000000\n");
    strShortCut += strURL + str1 + strIcon + str2;
    writeTextFile(strFileName, strShortCut);
}


int main(int argc, char *argv[])
{
    std::string strFileName("C:\\Windows\\바탕 화면\\ida.url");
    std::string strURL("http://blog.naver.com/idatopia.do");
    std::string strIcon("C:\\WINDOWS\\ida.ico");
   
    try {
        makeShortCut(strFileName, strURL, strIcon);
        puts("The internet shortcut file is created");
    } catch(std::string strError) {
        perror(strError.c_str());
    }
   
    putchar('\n'), system("pause");
    return 0;
}

반응형

댓글