Windows启动管理器 [英] Windows Startup Manager

查看:107
本文介绍了Windows启动管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int CFileRead::ReadFromPos(LONG lBeginFrom, DWORD lLen, LPSTR lpszBuffer)
{
    hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_WRITE + FILE_SHARE_READ, NULL, OPEN_EXISTING,
               FILE_ATTRIBUTE_ARCHIVE, NULL);


错误1错误C2664:"CreateFileW":无法将参数1从"LPSTR"转换为"LPCWSTR"


Error 1 error C2664: ''CreateFileW'' : cannot convert parameter 1 from ''LPSTR'' to ''LPCWSTR''

bool CRegEnum::OpenKey(HKEY RegKey, LPSTR SubKey)
{
    if (hKey != NULL) RegCloseKey(hKey);
    if ( RegOpenKeyEx(RegKey, SubKey,0 , KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS ) return false;
    return true;
}



错误C2664:"RegOpenKeyExW":无法将参数2从"LPSTR"转换为"LPCWSTR"

编译代码时出现上述错误.



error C2664: ''RegOpenKeyExW'' : cannot convert parameter 2 from ''LPSTR'' to ''LPCWSTR''

I get the above errors while i compile the code.

推荐答案

当然,它不能转换.也许有人会尝试帮助您进行转换.
但是在我看来,您不必如此.

我最好建议您将所有开发完全转换为宽字符串.
只需摆脱所有类型,变量和函数参数声明中的所有声明(如LPSTRLPCSTR(和char*)),分别切换到LPWSTRLPCWSTR.使您的软件完全使用Unicode.

您尝试使用的所有Windows API都具有所有方法的宽"版本,而不仅仅是文件I/O和注册表API.

—SA
Of course it cannot convert. Maybe, somebody will try to help you with the conversion.
But to me it looks like you don''t have to.

I would better advise you to switch all your development to wide strings totally.
Simply get rid from all declarations like LPSTR, LPCSTR (and char*) from all the type, variable and function parameter declarations, switch to LPWSTR, and LPCWSTR, respectively. Make your software using Unicode entirely.

All the Windows API you''re trying to use has "wide" versions of all the methods, not only file I/O and Registry API.

—SA


您的项目很可能使用常规项目属性"下的Unicode字符集.

您可以将其更改为ASCII来解决此问题,但是我建议改为更改您的代码

Your project is most likely using the Unicode character set under the General Project Properties.

You can change this to ASCII to fix this, however I would recommend changing your code instead

int CFileRead::ReadFromPos(LONG lBeginFrom, DWORD lLen, LPTSTR lpszBuffer) {
    hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_WRITE + FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL);





bool CRegEnum::OpenKey(HKEY RegKey, LPTSTR SubKey) {
    if (hKey != NULL) RegCloseKey(hKey);
    if ( RegOpenKeyEx(RegKey, SubKey,0 , KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS ) return false;
    return true;
}



然后,您需要在所有字符串周围添加_T()TEXT()宏,以使它们成为Unicode:



Then you will need to add the _T() or TEXT() macros around all your strings to make them Unicode:

OpenKey(HKEY_LOCAL_MACHINE, TEXT("Software"));



strlenstrcpyprintf之类的功能现在分别变为_tcslen_tcscpy_tprintf.



Functions like strlen, strcpy and printf will now become _tcslen, _tcscpy and _tprintf respectively.


这篇关于Windows启动管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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