微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

wstring-> ShellExecute中的LPCWSTR给我错误LNK2028&LNK2019

如何解决wstring-> ShellExecute中的LPCWSTR给我错误LNK2028&LNK2019

| 您好我正在使用UNICODE和/ clr在Visual C ++ 2010(西班牙语)中进行编程。我有一个名为\“ fileFuncs.h \”的头文件
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <string>

using namespace std;

std::wstring s2ws(const std::string& s)
{
    int len;
    int slength = (int)s.length() + 1;
    len = MultiBytetoWideChar(CP_ACP,s.c_str(),slength,0); 
    wchar_t* buf = new wchar_t[len];
    MultiBytetoWideChar(CP_ACP,buf,len);
    std::wstring r(buf);
    delete[] buf;
    return r;
}

void callSystem(string sCmd){
std::wstring stemp = s2ws(sCmd);
LPCWSTR params = stemp.c_str();

    ShellExecute(NULL,L\"open\",L\"c:\\\\windows\\\\system32\\\\cmd.exe /S /C \",params,NULL,SW_HIDE); 
}
但是当我编译时给我这些错误错误LNK2028:指的是 未解析的符号(令牌)(0A0004A5) \“外部\” C \“结构HINSTANCE__ * stdcall ShellExecuteW(struct HWND *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)\“(?ShellExecuteW @@ $$ J224YGPAUHINSTANCE _ @@ PAUHWND _ @@ PB_W111H @ Z) 在函数“ void __cdecl”中 callSystem(class std :: basic_string,class std :: allocator>)\“ (?callSystem @@ $$ FYAXV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ 错误LNK2019:外部符号 \“外部\” C \“结构HINSTANCE__ * stdcall ShellExecuteW(struct HWND *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)\“(?ShellExecuteW @@ $$ J224YGPAUHINSTANCE _ @@ PAUHWND _ @@ PB_W111H @ Z) 无效 __cdecl callSystem(class std :: basic_string,classstd :: allocator)\“ 功能 (?callSystem @@ $$ FYAXV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z) 是某种类型的配置吗?     

解决方法

在解决方案资源管理器,属性,链接器,输入中右键单击您的项目。将shell32.lib添加到其他依赖项设置。 请注意,使用/ clr选项编译此代码没有什么意义,您没有编写任何托管代码。 ShellExecute()函数的等效项是Process :: Start()。     ,附带说明:您确实意识到您在这种情况下不需要从
std::string
转换为
std::wstring
,对吗?像大多数带有字符串参数的API函数一样,ShellExecute()具有Ansi和Unicode两种版本。让操作系统为您完成转换:
#include <string> 

void callSystem(std::string sCmd)
{
    ShellExecuteA(NULL,\"open\",\"c:\\\\windows\\\\system32\\\\cmd.exe /S /C \",sCmd.c_str(),NULL,SW_HIDE);
} 
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?