:cant将参数2从``char [20]'转换为LPWSTR [英] :cant convert parameter 2 from ''char [20]' to LPWSTR

查看:551
本文介绍了:cant将参数2从``char [20]'转换为LPWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void CDeptStore2Dlg::OnBnClickedNewitem()
{
	// TODO: Add your control notification handler code here
	CNewStoreItemDlg dlg;
	srand( (unsigned)time(NULL) );
	char strNumber[20];

	int number1 = rand() % 999;
	int number2 = rand() % 999;

	sprintf(strNumber, "%d-%d", number1, number2);
	dlg.m_ItemNumber = strNumber;

	if( dlg.DoModal() )
	{
		LVITEM lvItem;

		lvItem.mask = LVIF_TEXT;
		lvItem.iItem = 0;
		lvItem.iSubItem = 0;
		lvItem.pszText = strNumber;
		this->m_StoreItems.InsertItem(&lvItem);
	}
}


我在functionx网站的列表控件中复制了此代码,但给出了错误...
错误::无法将参数2从''char [20]''转换为LPWSTR

包含的代码块,删除了一些拼写[/Edit]


i had copy of this code in list control from functionx website..but gives an error...
ERROR ::cant convert parameter 2 from ''''char [20]'' to LPWSTR

Included code block, removed some spelling [/Edit]

推荐答案

问题来自以下几行:
The problem comes from these lines:
   char strNumber[20];
   ...
   sprintf(strNumber, "%d-%d", number1, number2);
   ...
   dlg.m_ItemNumber = strNumber;
}



您没有向我们显示m_ItemNumber的类型,但我想它是CString.
您有两种选择:

1-更改项目设置,以使CString类将使用ANSI字符串.
为此,显示项目属性,然后选择常规,然后将字符集字段更改为未设置.对所有配置(发布和调试)执行此操作.

2-如果您不想更改项目设置,则需要使用适当的类型和功能.将我提到的行更改为:



You didn''t show us the type of m_ItemNumber but I guess it is a CString.
You have two options:

1- Change your project settings so that CString class will use ANSI strings.
To do that, display the project properties, then select General, then change the Character Set field to Not Set. Do that for all configurations (Release and Debug).

2- If you don''t want to change your project settings, then you need to use the appropriate types and functions. Change the lines I mentionned into:

    TCHAR strNumber[20];
    ...
    _stprintf(strNumber, _T("%d-%d"), number1, number2);
    ...
    dlg.m_ItemNumber = strNumber;
}


并确保m_ItemNumber的类型为CString.
无论您的项目是否使用宽字符字符串,这都将起作用.


And make sure the type of m_ItemNumber is CString.
This will work wether your project uses wide char strings or not.


修改此行
<br />
wsprintfA(strNumber, _T("%d-%d"), number1, number2);<br />


再次给出了2个错误..
ist是我写的b4..
第二个是sprintf:cant将参数从``const wchar_t [6]''转换为const char *''
Again it gave 2 error ..
ist is b4 i wrote..
2nd is sprintf:cant convert parameter to from ''const wchar_t[6]'' to const char*''


这篇关于:cant将参数2从``char [20]'转换为LPWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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