刚才新建了一个source file文件。。 拿了那段代码试了一下。 出错了,报错如下: --------------------Configuration: test_webTransfer - Win32 Debug-------------------- Compiling... test source file.cpp D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2146: syntax error : missing ';' before identifier 'h' D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2501: 'HINSTANCE' : missing storage-class or type specifiers D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : fatal error C1004: unexpected end of file found 执行 cl.exe 时出错.test_webTransfer.exe - 1 error(s), 0 warning(s)
是不是我用的HINSTANCE h = ShellExecute(NULL,"open","http://www.sina.com.cn",NULL,SW_SHOW); 这段话哪有问题呀??还是需要在别的地方设置一下呀??
ShellExecute(NULL,"open","http://www.sina.com.cn",NULL,SW_SHOW); 参数是六个,怎么少了一个? HINSTANCE ShellExecute( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd ); To open a folder, use either of the following calls: ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);or ShellExecute(handle, "open", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To launch the Shell's Find utility for a directory, use: ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0);If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function attempts to open or explore the folder.头文件: shellapi.h 库文件: shell32.lib
你试一下这个:#include <stdio.h> #include <stdlib.h> #include <windows.h>#pragma comment(lib,"shell32.lib") int main() { HINSTANCE h = ShellExecuteA(NULL,"open","http://www.sina.com.cn",NULL,NULL,SW_SHOW); return 0; }
我这里找了一段关于ShellExecute 的代码,不知道行不行?感觉里面还定义了其他的函数?
HINSTANCE h = ShellExecute(NULL, "open", "iexplore.exe", "-new http://www.sina.com.cn", NULL, SW_SHOW);
你用的是VS2005还是VC6.0??
//你用的是VS2005还是VC6.0??我现在测试用的是VC6.0
上午用VS2005,老是提示说我的工程已经过期了,什么都没做都报错。。
在哪个里面添加文件呀,是在“文件”->"新建"->“文件”里面吗??可是里面有很多类型的文件呀??
并且我也不知道是在Source Files/Header files/resource files里面建新文件呀??
拿了那段代码试了一下。
出错了,报错如下:
--------------------Configuration: test_webTransfer - Win32 Debug--------------------
Compiling...
test source file.cpp
D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2146: syntax error : missing ';' before identifier 'h'
D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : error C2501: 'HINSTANCE' : missing storage-class or type specifiers
D:\VC6.0\MSDev98\MyProjects\test_webTransfer\test source file.cpp(1) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.test_webTransfer.exe - 1 error(s), 0 warning(s)
参数是六个,怎么少了一个?
HINSTANCE ShellExecute( HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
To open a folder, use either of the following calls: ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);or ShellExecute(handle, "open", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);To launch the Shell's Find utility for a directory, use: ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0);If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function attempts to open or explore the folder.头文件:
shellapi.h
库文件:
shell32.lib
#include <stdlib.h>
#include <windows.h>#pragma comment(lib,"shell32.lib")
int main()
{
HINSTANCE h = ShellExecuteA(NULL,"open","http://www.sina.com.cn",NULL,NULL,SW_SHOW);
return 0;
}
我刚才把它粘贴进去了,运行了一下提示这个错误:
--------------------Configuration: test_webTransfer - Win32 Debug--------------------
Compiling...
test source file.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/test_webTransfer.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.test_webTransfer.exe - 1 error(s), 0 warning(s)
你的入口函数为WinMain,这样的话,要设置一下:因为你建的工程是控制台程序,所以入口函数应该是main, 而你使用了WinMain.
具体解决方法是:
1.进入project->setting->c/c++, 在category中选择preprocessor,在processor definitions中删除_WINDOWS, 添加_CONSOLE
2.进入project->setting->Link, 在Project options中将/subsystem:windows.改为/subsystem:console
3.保存设置,Rebuild All.
因为刚才我把代码删了,再运行还是报这个错误??
--------------------Configuration: test_webTransfer - Win32 Debug--------------------
Compiling...
test source file.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/test_webTransfer.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错. test_webTransfer.exe - 1 error(s), 0 warning(s)
对了顺便问一下,如果我想在http://www.sina.com.cn后面加上一个变量,能加吗??
把“http://www.sina.com.cn”这段话,变成一个变量。。我可以随时改变这个网址。。
#include <stdlib.h>
#include <tchar.h>
#include <windows.h>#pragma comment(lib,"shell32.lib")
int main()
{
LPCTSTR str;
str = _T("http://www.sina.com.cn");
HINSTANCE h = ShellExecuteW(NULL,_T("open"),str,NULL,NULL,SW_SHOW);
return 0;
}
--------------------Configuration: test_webTransfer3 - Win32 Debug--------------------
Compiling...
test_souce_file.cpp
d:\vc6.0\msdev98\myprojects\test_webtransfer3\test_souce_file.cpp(11) : error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'char [5]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.test_webTransfer3.exe - 1 error(s), 0 warning(s)
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string url="index.aspx?ID="+e.Item.Cells[1].Text;
Response.Direct(url);
}
其中e.Item.Cells[1].Text传过来的值可以直接放到参数字符串后面呀?