含义
- 其实就是编码问题
- 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
online pharmacy reviews no prescription best website to buy prescription drugs buy prescription drugs on line
pharmacy no prescription: meds online no prescription – indian pharmacy no prescription
https://onlinepharmacyworld.shop/# rxpharmacycoupons
canada pharmacy not requiring prescription rxpharmacycoupons cheapest pharmacy to fill prescriptions without insurance
http://edpill.top/# where to buy erectile dysfunction pills
online drugs without prescription: online pharmacy with prescription – mexican pharmacies no prescription
https://kursovuyupishem.ru/
order ed meds online buy erectile dysfunction pills online buy ed pills online
promo code for canadian pharmacy meds: canadian pharmacy coupon – pharmacy coupons
prescription drugs online: cheapest pharmacy prescription drugs – pharmacy online 365 discount code
cost of ed meds edmeds buying erectile dysfunction pills online
Услуга по сносу старых зданий и утилизации отходов в Москве и Московской области. Мы предоставляем услуги по сносу старых сооружений и удалению мусора на территории Москвы и Московской области. Услуга http://demontazh-doma-msk8.ru выполняется квалифицированными специалистами в течение 24 часов после оформления заказа. Перед началом работ наш эксперт бесплатно посещает объект для определения объёма работ и предоставления консультаций. Чтобы получить дополнительную информацию и рассчитать стоимость услуг, свяжитесь с нами по телефону или оставьте заявку на сайте компании.
online pharmacy not requiring prescription: buy drugs online without prescription – buying prescription drugs online canada
buy prescription online mail order prescriptions from canada medicine with no prescription
zithromax prescription: buy zithromax canada – where can i buy zithromax capsules
https://azithromycina.pro/# zithromax over the counter canada
how to purchase prednisone online: prednisone 1 mg for sale – cheap prednisone 20 mg
prednisone daily prednisone 50 mg tablet canada order prednisone 10 mg tablet
https://stromectola.top/# stromectol liquid
ivermectin online: minocycline for acne – ivermectin 10 mg
http://clomida.pro/# cheap clomid price
amoxicillin 500 mg online where to buy amoxicillin amoxicillin 500 mg capsule
http://amoxicillina.top/# amoxicillin medicine over the counter
https://amoxicillina.top/# amoxicillin where to get
where to buy generic clomid pill how can i get clomid no prescription how to get cheap clomid without a prescription
http://amoxicillina.top/# amoxicillin 500mg capsules antibiotic
ivermectin 200 stromectol medicine ivermectin 4 tablets price
https://amoxicillina.top/# amoxicillin 500mg
https://prednisonea.store/# prednisone 0.5 mg
can i order generic clomid for sale how to get clomid without prescription can i get cheap clomid now
https://amoxicillina.top/# amoxicillin generic brand
buy amoxil: buy amoxicillin 500mg usa – amoxacillian without a percription
Услуга по сносу старых домов и вывозу мусора в Москве и Московской области. Мы предоставляем услуги по сносу старых зданий и удалению мусора на территории Москвы и Подмосковья. Услуга демонтаж после пожара выполняется опытными специалистами в течение 24 часов после оформления заказа. Перед началом работ наш эксперт бесплатно приезжает на объект для оценки объёма работ и консультации. Чтобы получить дополнительную информацию и рассчитать стоимость услуг, свяжитесь с нами по телефону или оставьте заявку на сайте компании.
http://stromectola.top/# ivermectin 5 mg price
prednisone 20 tablet buy prednisone online without a script prednisone for dogs
cost of prednisone 10mg tablets prednisone 50 mg tablet cost 50mg prednisone tablet
http://clomida.pro/# how to buy cheap clomid
https://stromectola.top/# ivermectin 50 mg
zithromax 500 without prescription zithromax online usa zithromax 500 price
http://womangu.ru
where to buy ivermectin cream: stromectol tab 3mg – minocycline
https://azithromycina.pro/# zithromax price canada
zithromax order online uk: zithromax cost uk – where can i buy zithromax capsules
amoxicillin order online amoxicillin 500mg capsules buy amoxicillin 500mg uk
http://stromectola.top/# ivermectin 10 mg
can you get cheap clomid: where to buy cheap clomid tablets – cost of clomid now
ivermectin 3 mg dose: ivermectin 10 ml – purchase stromectol
canine prednisone 5mg no prescription prednisone 3 tablets daily prednisone uk price
http://stromectola.top/# ivermectin over the counter
http://amoxicillina.top/# amoxicillin for sale