Home Function already defined in main.obj & unresolved externals errors
Reply: 0

Function already defined in main.obj & unresolved externals errors

Charles
1#
Charles Published in 2017-12-05 23:31:15Z

So I keep having these issues while trying to work with classes. Sometimes I spend hours trying random stuff and it sometimes ends up working for some reason but most of the time I just end up giving up and trashing my code. I've seen multiple answers for a question like mine on stack-overlflow, but not only, but, sadly, none of them worked for me.

I either get errors like x already defined in y.obj or unresolved externals or both (my current project's case)

Also have tried messing with some linker settings, but still nothing.

I really do not understand what is up, so if anyone could quickly look over my ass code and tell me what I might have done wrong it'll be a really good thing since this problem always happens.

proc.h

    #ifndef PROJ_PROC_H
#define PROJ_PROC_H
#pragma once

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <Windows.h>
#include <iostream>
#include <vector>
#include <TlHelp32.h>

namespace my_proc
{
    class _MyProc
    {
    public:
        _MyProc(VOID) {};
        ~_MyProc(VOID) {};

        inline
        DWORD
        WhatIsTheLastError(VOID) { return _lastErr; };


        inline
        DWORD
        GrabProcessIdA(
            _In_ const char* szProcess,
            _In_ bool bCaseSensitive = false);

    private: UINT_PTR _lastErr = 0;
    };
}

#endif

proc.cpp

#include "proc.h"

using namespace my_proc;

DWORD
_MyProc::GrabProcessIdA(
    const char* szProcess,
    bool bCaseSensitive)
{
    if (nullptr == szProcess)
    {
        _lastErr = ERR_BAD_PARAM;
        return false;
    }

    HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (!hSnap || INVALID_HANDLE_VALUE == hSnap)
    {
        _lastErr = ERR_CANNOT_CAPTURE_SNAP_COMMIT;
        return false;
    }

    PROCESSENTRY32 PE32 = { 0 };
    PE32.dwSize = { sizeof(PE32) };

    bool bFirst = false;
    bFirst = Process32First(hSnap, &PE32);

    if (bFirst)
    {
        do
        {
            if (bCaseSensitive ? !strcmp(PE32.szExeFile, szProcess)
                : !_stricmp(PE32.szExeFile, szProcess))
            {
                DWORD dwProcId = 0;
                dwProcId = PE32.th32ProcessID;
                CloseHandle(hSnap);

                return dwProcId;
            }
        } while (Process32Next(hSnap, &PE32));
    }

    else
    {
        _lastErr = ERR_PROCFIRST_FAIL;
        return false;
    }

    CloseHandle(hSnap);
    _lastErr = ERR_FAILED_TO_FIND_PROC;

    return 0;
}

I have also tried calling it both like this

my_class* ptrc = new my_class();
my_class.function();

and

my_class ptrc;
ptrc.function()

And also tried making it static but I get unresolved external symbol error :(

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.329956 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO