-3

Error C1075 the left brace '{' was unmatched at the end of the file - line 43
Error (active) expected a declaration - line 123
Error C2601 'm_iGetProcessHandleByName': local function definitions are illegal - line 93
Error (active) expected a ';' - line 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;
            }
        }
    }
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • 5
    Welcome to Stack Overflow! Please **[edit]** your question with a [mcve] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org) – NathanOliver Jun 01 '16 at 13:46
  • Don't edit your post to effectively remove all its content: either improve it, or delete it. I've rolled back your last change. – Benjamin W. Jun 07 '16 at 19:20
  • missing a closing brace '}' right before `m_iGetProcessHandleByName` – kmdreko Jun 07 '16 at 19:23

1 Answers1

0

Looks like your project was created in ANSI and you are trying to compile it in unicode. Try disabling unicode like in this question: How do I turn off Unicode in a VC++ project?

Community
  • 1
  • 1
Jehy
  • 4,729
  • 1
  • 38
  • 55
  • I disabled it and turned on multi byte, i changed the post with the errors – Xiben Nguyen Jun 01 '16 at 17:58
  • @XibenNguyen you should use character encoding "Not Set" - just as pointed in the answers to the question which I linked. – Jehy Jun 03 '16 at 09:17
  • argument of type "const wchar_t *" is incompatible with parameter of type "LPCSTR" – Xiben Nguyen Jun 04 '16 at 17:23
  • @XibenNguyen without seeing any code, I can only advice you to read answers on this question: http://stackoverflow.com/questions/13977388/error-cannot-convert-const-wchar-t-13-to-lpcstr-aka-const-char-in-assi - it is the same problem and it should help you. – Jehy Jun 05 '16 at 20:09
  • I have edited the post with the code, I fixed the wchar errors but got others. – Xiben Nguyen Jun 06 '16 at 07:09
  • @XibenNguyen right now, you are missing `}` somewhere in your code. – Jehy Jun 06 '16 at 11:01
  • I suppose, it should be on line 92. – Jehy Jun 06 '16 at 11:09
  • I have managed to fix most of the errors but it is still giving me 2/4 errors. I have edited the main post with the errors. all of the {'s are linked as far as I know, I have re-written the whole thing and saw nothing. This is frustrating. – Xiben Nguyen Jun 06 '16 at 13:23