含义
- 其实就是编码问题
- A:
- 代表ANSI
- W:
- 代表宽字节(wide),即 Unicode
- A:
- 一般win的库函数如果后面不加 ’A‘ 或 'W' 时,直接给它传字符串类型值时会报错:
- 以我常用的 ShellExecute() 为例:
- 会报错:
- "const char *" 类型的实参与 "LPCWSTR" 类型的形参不兼容
- 不存在从 “std::string” 到 “LPCWSTR” 的适当转换函数
- LPCWSTR 是个啥?让我们来看看它的定义:
- typedef const wchar_t* LPCWSTR;
- 即指向unicode编码字符串的32位指针,并且所指向字符串是wchar,而非char。
- 解决方法:
- 把函数改为 ShellExecuteA() 或 ShellExecuteW()
- 或者在传字符串时使用宏定义转换类型
- 对于常量字符串:
- _T() (推荐使用)自适应转换,当程序定义为unicode时,相当于L,当程序定义为ansi时,则被忽略(头文件:#include <tchar.h>)
- L ;例如原本传值为 fun("open"),使用后为fun(L"open");注意这个L并没有括号。
- CA2W() 从宽字符集(Unicode)转为多字符集(ANSI)(头文件:#include <atlstr.h>)
- CW2A() 从多字符集(ANSI)转化为宽字符集(Unicode)(头文件:#include <atlstr.h>)
- 对于string / char[] / const char[] :
- 使用以下函数
LPCWSTR stringToLPCWSTR(const std::string& orig)
{
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t *wcstring = (wchar_t *)malloc(sizeof(wchar_t)*(orig.length()-1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
return wcstring;
}
- -
- -
- 那么如果我是 char[] 或者 const char[] 呢?那当然是转string再使用上面的函数啦。
- 示例:
- -
ShellExecuteA(NULL, "open", "https://blog.coolight.cool/", NULL, NULL, SW_SHOWNORMAL);
string str = "https://blog.coolight.cool/";
ShellExecute(NULL, _T("open"), stringToLPCWSTR(str), NULL, NULL, SW_SHOWNORMAL);
const char link_char[] = "https://blog.coolight.cool/";
ShellExecute(NULL, _T("open"), stringToLPCWSTR(string(link_char)), NULL, NULL, SW_SHOWNORMAL);
ShellExecute(NULL, L"open", CA2W("https://blog.coolight.cool/"), NULL, NULL, SW_SHOWNORMAL);
常见编码格式
见另一篇文章:常见编码格式 / 字节序(大端 / 小端)/ 带BOM
http://cytotec.club/# Misoprostol 200 mg buy online
https://nolvadex.life/# benefits of tamoxifen
where can i buy nolvadex how does tamoxifen work buy tamoxifen
tamoxifen 20 mg tablet what is tamoxifen used for is nolvadex legal
price for 5 mg lisinopril: 30mg lisinopril – zestoretic 20-25 mg
cytotec pills buy online п»їcytotec pills online buy cytotec in usa
https://ciprofloxacin.tech/# ciprofloxacin order online
http://cytotec.club/# buy cytotec pills
tamoxifen effectiveness: dcis tamoxifen – is nolvadex legal
cheap propecia price: propecia – order propecia no prescription
http://cytotec.club/# buy cytotec online
cost generic propecia for sale buying cheap propecia buying generic propecia without insurance
https://cytotec.club/# Cytotec 200mcg price
cost of cheap propecia no prescription cost of propecia pills buy propecia no prescription
buying cheap propecia without a prescription: buying generic propecia without prescription – buy generic propecia no prescription
https://finasteride.store/# buy cheap propecia no prescription
http://lisinopril.network/# lisinopril 2.5 mg coupon
https://nolvadex.life/# nolvadex pills
tamoxifen postmenopausal where can i buy nolvadex tamoxifen citrate pct
buy cytotec over the counter: buy cytotec pills online cheap – buy cytotec
nolvadex for sale amazon: tamoxifen depression – tamoxifen chemo
cipro pharmacy where can i buy cipro online ciprofloxacin mail online
https://cytotec.club/# buy cytotec online
https://cytotec.club/# cytotec buy online usa
zestril 5mg medicine lisinopril 10 mg lisinopril 30mg coupon
На сайте коллегии юристов http://zpp-1.ru/ вы найдете контакты и сможете связаться с адвокатами. Юрист расскажет о том, как нужно правильно поступить, поможет собрать необходимые документы и будет защищать ваши права в суде. Квалифицированная юридическая и медицинская поддержка призывникам с гарантией!
ciprofloxacin 500mg buy online: cipro online no prescription in the usa – ciprofloxacin 500mg buy online
can you order lisinopril online zestoretic lisinopril brand
http://lisinopril.network/# lisinopril 20 mg brand name
http://cytotec.club/# buy cytotec pills online cheap
lisinopril 30 mg price lipinpril lisinopril 25
https://nolvadex.life/# what happens when you stop taking tamoxifen
lisinopril 40 mg for sale: lisinopril pills – buy lisinopril mexico
hysterectomy after breast cancer tamoxifen cost of tamoxifen tamoxifen bone pain
cipro for sale: cipro – ciprofloxacin 500mg buy online
https://ciprofloxacin.tech/# buy cipro online without prescription
tamoxifen for sale tamoxifen cost nolvadex online
lisinopril 7.5 mg: zestril online – can i buy lisinopril online
Misoprostol 200 mg buy online Abortion pills online п»їcytotec pills online
https://lisinopril.network/# zestril tablet
секс куклы с быстрой доставкой
femara vs tamoxifen tamoxifen and depression what is tamoxifen used for
https://lisinopril.network/# lisinopril 30 mg daily
cytotec online: buy cytotec online fast delivery – Cytotec 200mcg price
get generic propecia price: get cheap propecia without insurance – order generic propecia
https://lisinopril.network/# generic for zestril
https://lisinopril.network/# lisinopril 5 mg tabs
get generic propecia without rx get generic propecia pills order propecia without prescription
cipro pharmacy ciprofloxacin order online ciprofloxacin order online
http://ciprofloxacin.tech/# buy cipro cheap