Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetModuleBaseName dosen't take char* parameter

Tags:

c++

I got this code:

DWORD64 GetModuleBase(HANDLE hProc, string &sModuleName)//For 64bit process
{
HMODULE *hModules;
hModules = 0;
char szBuf[50];
DWORD cModules = 0;
DWORD64 dwBase = 0;

EnumProcessModules(hProc, hModules, 0, &cModules);
hModules = new HMODULE[cModules / sizeof(HMODULE)];

if (EnumProcessModules(hProc, hModules, cModules / sizeof(HMODULE), &cModules)) {
    for (int i = 0; i < cModules / sizeof(HMODULE); i++) {
        if (GetModuleBaseName(hProc, hModules[i], szBuf, sizeof(szBuf))) {
            if (sModuleName.compare(szBuf) == 0) {
                dwBase = (DWORD64)hModules[i];
                break;
            }
        }
    }
}

delete[] hModules;

return dwBase;
}

that fails on this line telling me that char* is incompatible with LPWSTR

if (GetModuleBaseName(hProc, hModules[i], szBuf, sizeof(szBuf))) {

I've been using it in another project for a long time and it was working fine, but I recently moved to a fresh one and I'm getting this issue. Not sure what to do. Adding (LPWSTR) next to szbuf just makes the dll crash.

I'm using VS 2013

like image 503
Hx0 Avatar asked Jan 30 '26 02:01

Hx0


1 Answers

Try using GetModuleBaseNameA (add "A" to the tail) instead.

GetModuleBaseNameA explicitly use ANSI characters in contrast to GetModuleBaseName, which is a macro to be GetModuleBaseNameA or GetModuleBaseNameW.

like image 63
MikeCAT Avatar answered Feb 01 '26 14:02

MikeCAT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!