找了一段快捷方式的代码,但编译就通不过,#include 就出错,好象是重复定义了很多变量?

jaffy 2006-07-21 02:16:06
第一次用COM,接口,很多地方都不懂,大家来教教我
IShellLink* pLink; // IShellLink介面可讓我們建立捷徑。
IPersistFile* pPersistFile; // IPersistFile 可將link存於硬碟中。
if(SUCCEEDED(CoInitialize(NULL)))// 首先進行COM程式庫的初始化。
{// 建立IShellLink物件的實體。
if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,IID_IShellLink, (void **)&pLink)))
{
// 快把捷徑的相關資訊填一填。
pLink->SetPath(sfile);
pLink->SetDescription(sfile);
pLink->SetShowCmd(SW_SHOW);
// 把捷徑存到硬碟去。
if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile)))
{
// 讓IPersistFile物件把捷徑存到桌面上。因為,Win32平台支援多國語言,所以這邊要用WideString。
WideString strShortCutLocation(tfile);
pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE);
pPersistFile->Release();
}
pLink->Release();
}
// 結束了,記得釋放COM程式庫的資源。
CoUninitialize();
return 0 ;
}
return -1 ;
...全文
462 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeahe83 2006-09-21
  • 打赏
  • 举报
回复
解决了每个unit都要放.......

#define NO_WIN32_LEAN_AND_MEAN
yeahe83 2006-09-21
  • 打赏
  • 举报
回复
土办法一一比较了一下,结果是在bpr文件的宏<MACRO>里面:

<USERDEFINES value="_DEBUG"/>------------出错
<USERDEFINES value="NO_WIN32_LEAN_AND_MEAN"/>----通过

和楼上大大说的很像呀,但是我用
#define NO_WIN32_LEAN_AND_MEAN
#define USERDEFINES NO_WIN32_LEAN_AND_MEAN
等都没有效果呀,只能手动改代码

请问.bpr文件中的macro到底怎么改变原值呢?
yeahe83 2006-09-21
  • 打赏
  • 举报
回复
我相同的一段代码的两个文件同时发生了出错和不出错的现象........
paskaa 2006-09-19
  • 打赏
  • 举报
回复
[C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'

我编译后说这几个错误
paskaa 2006-09-19
  • 打赏
  • 举报
回复
MARK 这个问题后来怎么解决的?我也遇到这个问题了
jaffy 2006-07-21
  • 打赏
  • 举报
回复
老大们怎么又不见了?
jaffy 2006-07-21
  • 打赏
  • 举报
回复
我放在一个空的工程的.H,一样报上面那个错误,难道我的BCB有问题
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
jaffy 2006-07-21
  • 打赏
  • 举报
回复
我是放在.H里的
下面是我的头文件

#ifndef Main2H
#define Main2H

//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include <DBGrids.hpp>
#include <Grids.hpp>
#include <Registry.hpp>
#include <Buttons.hpp>
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
cczlp 2006-07-21
  • 打赏
  • 举报
回复

#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
放在.h中, 不要放在.cpp中。
jaffy 2006-07-21
  • 打赏
  • 举报
回复
to BlueDeepOcean
如果按照你的说法,根本找不到这两个类型的申明
IShellLink* pLink; // IShellLink介面可讓我們建立捷徑。
IPersistFile* pPersistFile; // IPersistFile 可將link存於硬碟中。

to constantine:
还是老错误,我发现这个头文件shlobj.h是不是有问题呀?我直接一个空的工程INCLUDE也报错.
[C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'
BlueDeepOcean 2006-07-21
  • 打赏
  • 举报
回复
应该是#include <shlobj.hpp>吧,而且是在.h中。
constantine 2006-07-21
  • 打赏
  • 举报
回复
在include 最前面插入

#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
jaffy 2006-07-21
  • 打赏
  • 举报
回复
自己顶,高手都来看看呀?

703

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder ActiveX/COM/DCOM
社区管理员
  • ActiveX/COM/DCOM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧