ShellExecute问题,初学VC,请帮忙

general_cigarette 2002-09-04 11:39:52
// shell.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char pathbuff[256];
ZeroMemory(pathbuff,256);
GetCurrentDirectory(256,pathbuff);
strcat(pathbuff,"\\");
ShellExecute(NULL,NULL,_T("freecell.exe"),NULL,pathbuff,SW_SHOW);
return 0;
}

编译后:
--------------------Configuration: shell - Win32 Release--------------------
Compiling...
shell.cpp
E:\vc\shell\shell.cpp(16) : error C2065: 'ShellExecute' : undeclared identifier
E:\vc\shell\shell.cpp(16) : error C2065: '_T' : undeclared identifier
Error executing cl.exe.

shell.exe - 2 error(s), 0 warning(s)


...全文
230 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
joke100 2002-09-05
  • 打赏
  • 举报
回复

正确。
_T就是为了兼顾unicode与ansi版本的,而tchar.h里面定义了通用的标志。

下面就是_T宏等价的定义
#ifdef _UNICODE
define _T(x) L ## x
#elif
define _T(x) x
#endif
general_cigarette 2002-09-04
  • 打赏
  • 举报
回复
我增加了#include "TCHAR.H "
编译通过,不知道这样做对不对?
969209pxb 2002-09-04
  • 打赏
  • 举报
回复
up
asdfsdfrewrwesr 2002-09-04
  • 打赏
  • 举报
回复


ShellAPI函数的应用

  (1) 有些程序在选单中点击“说明”后,应用程序会调出Windows的记事本并打开一个文本文件。我们可以通过调用ShellExecute( )函数实现此功能。具体实现代码如下:

  ShellExecute(NULL,"open","readme.txt",NULL,NULL,SW_SHOWNORMAL);

  其中“open”代表执行打开操作,“readme.txt”是要打开的文件名。
general_cigarette 2002-09-04
  • 打赏
  • 举报
回复
#include "Shellapi.h"后,就剩下
E:\vc\shell\shell.cpp(17) : error C2065: '_T' : undeclared identifier

这一条错误了。
liutang 2002-09-04
  • 打赏
  • 举报
回复
加入
#include <shellapi.h>

你查一下MSDN就可以知道了。
joke100 2002-09-04
  • 打赏
  • 举报
回复

这个函数
Header: Declared in Shellapi.h.
Import Library: Shell32.lib.

#include "Shellapi.h"试一下,有可能Shellapi.h还包含其包文件,一般windows程序,#include <afxwin.h>一定要包含的
flyingeagle 2002-09-04
  • 打赏
  • 举报
回复
you shoud include the "shellapi.h"
general_cigarette 2002-09-04
  • 打赏
  • 举报
回复
这是从网上拷贝的一段代码,是不是少INCLUDE了什么文件,请指教!

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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