LPCSTR显示奇怪的字符属于char ** [英] LPCSTR show strange characters when is attrib to a char**

查看:81
本文介绍了LPCSTR显示奇怪的字符属于char **的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于将我的软件设置为在系统启动时初始化。如果在代码上手动设置字符串一切正常,但现在我需要从与子项和名称相对应的文本文件中加载这些
值,但是调试显示奇怪的字符而不能成功执行此任务。

I使用了  this   code
加载每个lin txt文件的e。

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <shlobj.h>
#include "Shlwapi.h"

using namespace std;

#pragma comment(lib, "Shlwapi.lib")

LPCSTR subkeyRun;
LPCSTR keyname;

void AutoRun(void)
{
    HKEY  hKey;
    TCHAR buffer[100];
    DWORD size = sizeof(buffer);

    char szPathToExe[MAX_PATH];
    GetModuleFileNameA(NULL, szPathToExe, MAX_PATH);

    RegCreateKeyEx(HKEY_CURRENT_USER, subkeyRun, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, 0);

    LONG result = RegQueryValueEx(hKey, keyname, 0, NULL, (BYTE*)buffer, &size);

    if (ERROR_SUCCESS == result); 
    else 
       RegSetValueEx(hKey, keyname, 0, REG_SZ, (BYTE *)szPathToExe, lstrlen(szPathToExe));

    RegCloseKey(hKey);
}

int main()
{   

    TCHAR szFolderPath[MAX_PATH];

    if (SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_LOCAL_APPDATA, FALSE))
    {

        PathAddBackslash(szFolderPath);
        lstrcat(szFolderPath, "b");

        char** lines = whole(szFolderPath);

        for (int i = 0; lines[i]; i++) {
            printf("%d %s\n", i, lines[i]);
            subkeyRun = lines[11]; // Software\Microsoft\Windows\CurrentVersion\Run
            keyname = lines[3]; // foo name
        }

        freewhole(lines);

    }

    AutoRun();

    system("pause");

    return 0;   
}

推荐答案

由于两个原因很难解释代码 -

It's difficult to interpret the code for two reasons -

1)有一个char和TCHAR的混合但我们不知道你是在为UNICODE或MBCS构建,有些函数调用专门调用它们的ASCII版本而其他函数调用没有(例如,GetModuleFileNameA,SHGetSpecialFolderPath)

1) There is a mixture of char and TCHAR but we don't know if you are building for UNICODE or MBCS and some function calls specifically call their ASCII versions and others do not (e.g., GetModuleFileNameA , SHGetSpecialFolderPath)

2)代码包括对whole()和freewhole()的调用,但是我们不知道这些函数是做什么的。

2) the code includes calls to whole() and freewhole(), but we have no idea what these functions do.

你能提供一些澄清吗? / p>

Can you provide some clarification?


这篇关于LPCSTR显示奇怪的字符属于char **的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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