wstring ->ShellExecute 中的 LPCWSTR 给我错误 LNK2028 &LNK2019 [英] wstring -> LPCWSTR in ShellExecute give me error LNK2028 & LNK2019

查看:33
本文介绍了wstring ->ShellExecute 中的 LPCWSTR 给我错误 LNK2028 &LNK2019的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用 UNICODE 和/clr 使用 Visual C++ 2010(西班牙语)进行编程.我有一个名为fileFuncs.h"的头文件:

Hello I'm programming in Visual C++ 2010 (spanish) with UNICODE and /clr. I have a header file called "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, 0, s.c_str(), slength, 0, 0); 
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 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); 
}

但是当我编译时给我这些错误:

But when I compile give me these errors:

  • 错误 LNK2028:指的是未解析的符号(令牌)(0A0004A5)"extern "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呼叫系统(类std::basic_string, 类std::allocator >)"(?callSystem@@$$FYAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@

  • error LNK2028: refers to the unresolved symbol (token) (0A0004A5) "extern "C" struct HINSTANCE__ * stdcall ShellExecuteW(struct HWND *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE_@@PAUHWND_@@PB_W111H@Z) in the function "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:外部符号"extern "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)

error LNK2019: external symbol "extern "C" struct HINSTANCE__ * stdcall ShellExecuteW(struct HWND *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE_@@PAUHWND_@@PB_W111H@Z) unresolved referred to in "void __cdecl callSystem(class std::basic_string,classstd::allocator)" function (?callSystem@@$$FYAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

是某种类型的配置吗?

推荐答案

在解决方案资源管理器中右键单击您的项目、属性、链接器、输入.将 shell32.lib 添加到附加依赖项设置.

Right-click your project in the Solution Explorer, Properties, Linker, Input. Add shell32.lib to the Additional Dependencies setting.

请注意,使用/clr 选项编译此代码没有什么意义,您没有编写任何托管代码.ShellExecute() 函数的等价物是 Process::Start().

Beware that there's little point in compiling this code with the /clr option, you didn't write any managed code. The equivalent of ShellExecute() function is Process::Start().

这篇关于wstring ->ShellExecute 中的 LPCWSTR 给我错误 LNK2028 &amp;LNK2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆