VC 2005自定义头文件被引用出错 在VC 2005下,自定义了一个aaa.h文件,此.h文件引用了Shellapi.h,在另外两个.cpp文件中,我需要调用aaa.h里面的函数,因此我在这两个.cpp文件中包含了aaa.h,但编译时提示错误是:already defined in .obj。请问各位,这是怎么回事,我如何多次包含自定义的头文件啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 aaa.h的最开始加上#pragma once 恩,rebuild,而且aaa.h不是定义的系统的类,而是只定义了一个函数,在另外两个cpp文件中都调用了这个函数,因此要包含aaa.h,两个.cpp文件都包含了这个aaa.h,然后就出错了 好吧,把你aaa.h发出来看看,还有错误 XX already defined in .obj xx是什么 #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 .h里不要放函数体,提到对应的cpp中.h里只留定义BOOL ExecutePackage(LPCWSTR fileName, LPCWSTR args, LPCWSTR baseDir, bool wait); MFC的高深问题!!! 为什么DLL编译出的函数是这个样?带有特殊字符 如:?? @@ C/C++,VC,Java程序员招聘 如果一个数组中存放有汉字,我该怎样把它们读出来? 怎样把Sql Server2000 中的某个数据库中的日志缩小!或删除 在不影响数据库正常 初学vc++应该看那本书! 为什么会出现这种错误? MFC LISTCTRL中插入Combobox,拖动滚动条Combobox重影怎么解决 帮帮菜鸟吧! 请问如何在一个新的窗口中打开一个网址? RTSP 协议怎样返回“心跳” VC中如何获得当前程序的名字?
#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
.h里只留定义
BOOL ExecutePackage(LPCWSTR fileName, LPCWSTR args, LPCWSTR baseDir, bool wait);