在VC 2005下,自定义了一个aaa.h文件,此.h文件引用了Shellapi.h,在另外两个.cpp文件中,我需要调用aaa.h里面的函数,因此我在这两个.cpp文件中包含了aaa.h,但编译时提示错误是:already defined in .obj。请问各位,这是怎么回事,我如何多次包含自定义的头文件啊?

解决方案 »

  1.   

    aaa.h的最开始加上
    #pragma once
      

  2.   

    恩,rebuild,而且aaa.h不是定义的系统的类,而是只定义了一个函数,在另外两个cpp文件中都调用了这个函数,因此要包含aaa.h,两个.cpp文件都包含了这个aaa.h,然后就出错了
      

  3.   

    好吧,把你aaa.h发出来看看,还有错误 XX already defined in .obj  xx是什么
      

  4.   

    #pragma once
    //shellexecute.h
    //#if !defined(AFX_THIS_SHELLEXECUTE_INCLUDE)
    //#define AFX_THIS_SHELLEXECUTE_INCLUDE
    //#if _MSC_VER > 1000
    //#endif
    //#ifndef _THIS_SHELL
    //#define _THIS_SHELL#include "shellapi.h "/*HANDLE ExecutePackage(LPCWSTR fileName, LPCWSTR args, LPCWSTR baseDir, bool wait)   
    {   
    SHELLEXECUTEINFOW sei = { sizeof(SHELLEXECUTEINFOW) };   
    sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;   
    sei.lpFile = fileName;   
    sei.lpParameters = args;   
    sei.lpDirectory = baseDir;   
    if (!ShellExecuteExW(&sei)) {   
    return 0l;   
    }   
    if (wait) {   
    HANDLE hProcess = sei.hProcess;   
    if (hProcess != 0) {   
    WaitForSingleObject(hProcess, INFINITE);   
    }   
    }   
    return sei.hProcess;   
    }  */
    BOOL ExecutePackage(LPCWSTR fileName, LPCWSTR args, LPCWSTR baseDir, bool wait)   
    {   
    SHELLEXECUTEINFOW sei = { sizeof(SHELLEXECUTEINFOW) };   
    sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;   
    sei.lpFile = fileName;   
    sei.lpParameters = args;   
    sei.lpDirectory = baseDir;   
    if (!ShellExecuteExW(&sei)) {   
    return FALSE;   
    }   
    HANDLE hProcess = sei.hProcess;   
    if (hProcess != 0) {   
    if (wait) {   
    WaitForSingleObject(hProcess, INFINITE);   
    }   
    CloseHandle(hProcess);   
    }   
    return TRUE;   
    }
    //#endif错误:
    NotifyMenu.obj : error LNK2005: "int __cdecl ExecutePackage(wchar_t const *,wchar_t const *,wchar_t const *,bool)" (?ExecutePackage@@YAHPB_W00_N@Z) already defined in FMouse.objRelease/FreePen.exe : fatal error LNK1169: one or more multiply defined symbols found
      

  5.   

    .h里不要放函数体,提到对应的cpp中
    .h里只留定义
    BOOL ExecutePackage(LPCWSTR fileName, LPCWSTR args, LPCWSTR baseDir, bool wait);