Visual Studio构建错误

时间:2016-06-01 13:46:00

标签: c++

错误C1075左支撑'{'在文件末尾不匹配 - 第43行 错误(有效)预期一个声明 - 第123行 错误C2601'm_iGetProcessHandleByName':本地函数定义是非法的 - 第93行 错误(活动)预期';' - 第93行

#include "stdafx.h"

int XMemory::m_iDetaching()
{
    if (!m_hndProcessHandle)
    {
        std::wstring wsErrorText = L"'m_iDetaching' : Invalid handle specified.";
        Debug.m_fnAddError(wsErrorText, 1);
        return 1;
    }
    if (!CloseHandle(m_hndProcessHandle))
    {
        std::wstring wsErrorText = L"'m_iDetaching' : Failed to close handle.";
        Debug.m_fnAddError(wsErrorText, 2);
        return 2;
    }
    return 0;
}
int XMemory::m_iAttaching()
{
    if (m_iGetProcessHandleByName(&m_hndProcessHandle, Silver.m_wXProcessName))
    {
        std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXProcessName; wsErrorText += L"' handle.";
        Debug.m_fnAddError(wsErrorText, 1);
        return 1;
    }
    if (m_iGetModuleAddressByName(&m_dwClientModuleBaseAddress, Silver.m_wXClientModuleName, m_hndProcessHandle))
    {

        std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXClientModuleName; wsErrorText += L"' handle.";
        Debug.m_fnAddError(wsErrorText, 2);
        return 2;
    }
    if (m_iGetModuleAddressByName(&m_dwEngineModuleBaseAddress, Silver.m_wXEngineModuleName, m_hndProcessHandle))
    {
        std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXEngineModuleName; wsErrorText += L"' handle.";
        Debug.m_fnAddError(wsErrorText, 3);
        return 3;
    }
    return 0;
}
int XMemory::m_iGetProcessHandleByName(HANDLE* phndOutput, std::wstring wXProcessName)
{
    if (!phndOutput)
    {
        std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Invalid pointer specified.";
        Debug.m_fnAddError(wsErrorText, 1);
        return 1;
    }
    PROCESSENTRY32 p32Entry;
    p32Entry.dwSize = sizeof(PROCESSENTRY32);
    HANDLE hndProcessHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    if (!hndProcessHandle)
    {
        std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to create snapshot handle.";
        Debug.m_fnAddError(wsErrorText, 2);
        return 2;
    }
    if (Process32First(hndProcessHandle, &p32Entry) == TRUE)
    {
        if (!_wcsicmp(p32Entry.szExeFile, wXProcessName.c_str()))
        {
            HANDLE hndProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, p32Entry.th32ProcessID);
            if (!hndProcessHandle)
            {
                std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to open process handle.";
                Debug.m_fnAddError(wsErrorText, 3);
                return 3;
            }
            *phndOutput = hndProcessHandle;
            return 0;
        }
        else
        {
            while (Process32Next(hndProcessHandle, &p32Entry) == TRUE)
            {
                if (!_wcsicmp(p32Entry.szExeFile, wXProcessName.c_str()))
                {
                    HANDLE hndProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, p32Entry.th32ProcessID);
                    if (!hndProcessHandle)
                    {
                        std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to open process handle.";
                        Debug.m_fnAddError(wsErrorText, 4);
                        return 4;
                    }
                    *phndOutput = hndProcessHandle;
                    return 0;
                }
            }
        }
    }
    int m_iGetProcessHandleByName(HANDLE* phndOutput, std::wstring wsProcessName)
    {
        if (!phndOutput)
        {
            std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Invalid pointer specified.";
            Debug.m_fnAddError(wsErrorText, 1);
            return 1;
        }
        PROCESSENTRY32 p32Entry;
        p32Entry.dwSize = sizeof(PROCESSENTRY32);
        HANDLE hndProcessHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
        if (!hndProcessHandle)
        {
            std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to create snapshot handle.";
            Debug.m_fnAddError(wsErrorText 2);
            return 2;
        }
        if (Module32First(hndProcessHandle, &m32Entry) == TRUE)
        {
            if (!_wcsicmp(m32Entry.szModule, wsModuleName.c_str()))
            {
                DWORD dwModuleAdress = (DWORD)m32Entry.modBaseAddr;
                if (!dwModuleAddress)
                {
                    std::wstring wsErrorText = L"'m_iGetModuleAddressByName' : Invalid address found.";
                    Debug.m_fnAddError(wsErrorText, 3);
                    return 3;
                }
                *pdwOutput = dwModuleAddress;
                return 0;
            }
            else {
                while (Module32Next(hndModuleHandle, &m32Entry) == TRUE)
                {
                    if (!_wsicmp(m32Entry.szModule, wsModuleName.c_str()))
                    {
                        DWORD dwModuleAddress = (DWORD)m32Entry.modBaseAddr;
                        if (!dwModuleAddress)
                        {
                            std::wstring wsErrorText = L"'m_iGetModuleAddressByName' : Invalid Address found.";
                            Debug.m_fnAddError(wsErrorText, 4);
                            return 4;
                        }
                        *pdwOutput = dwModuleAddress;
                        return 0;
                    }
                }
                CloseHandle(hndProcessHandle);
                std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to find process.";
                Debug.m_fnAddError(wsErrorText, 5);
                return 5;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

看起来你的项目是用ANSI创建的,你试图用unicode编译它。尝试禁用此问题中的unicode:How do I turn off Unicode in a VC++ project?