Question: C++ Requesting MSVCP110D.dll even if static linked

Question

C++ Requesting MSVCP110D.dll even if static linked

Answers 1
Added at 2017-01-04 19:01
Tags
Question

I created a dll injection method on my machine in C++ which works very well when I try to inject a specific dll into a game . However , when I run the program on my friend's computer ( where Visual Studio redistributables are not installed) , I am warned that I need MSVCR , etc ... (the redistributables) .
So I compiled in the release mode with the following setting in Visual Studio 2012 : Runtime Library : Multi-threaded /MT . Now when I run it on my friend's machine I am warned that I need only the library MSVCP110D.dll ( weird , asking for the debug version) (there is no antivirus , and UAC is disabled ). I copied the requested library manually in the release path and still wont work.

Just what is the problem ?

This is the injection code i made :

    #include <Windows.h>
    #include <iostream>
    #include <stdio.h>
    #include <string>
    #include <TlHelp32.h>

class process
{
private:
     HWND hProcWnd       ;
     DWORD id            ;
     LPCWSTR lpWindowName ;

     struct PPARAM 
     {
        DWORD pId   ;
        HWND  pHwnd ;
     };
public:
process(string lpProcessName)
{
    HANDLE process_list = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32  lcProcess;
    PPARAM pParam;

    pParam.pHwnd     = nullptr;
    lcProcess.dwSize = sizeof(PROCESSENTRY32);
    do {
        char ch[260];
        char DefChar = ' ';
        WideCharToMultiByte(CP_ACP,0,lcProcess.szExeFile,-1,ch,260,&DefChar, NULL);
        string ss(ch);

        if(ss == lpProcessName)
        {
            id = lcProcess.th32ProcessID;
            pParam.pId = id;
            EnumWindows(enumCallback , (LPARAM)&pParam);
            break;
        }
    }while(Process32Next(process_list,&lcProcess));     

    hProcWnd = pParam.pHwnd;
}

static BOOL CALLBACK enumCallback(HWND hWnd , LPARAM lParam)
 {
     DWORD    _tId = 0;
     PPARAM  &pData = *(PPARAM*)lParam;
     GetWindowThreadProcessId(hWnd , &_tId);

     if(_tId != pData.pId)
     {
        return 1;
     }

     pData.pHwnd = hWnd;
     return 0;
 }
int inject(string lpLibraryPath)
{
    if(hProcWnd == nullptr)
    {
        printf(ERROR_HWND_INEXISTENT);
        return 0;
    }

    HANDLE      hProc;
    LPVOID      paramAddr;
    HINSTANCE   hDll;

    hDll = LoadLibrary(L"KERNEL32");

    fpLoadLibrary LoadLibraryAddr = (fpLoadLibrary)GetProcAddress(hDll, "LoadLibraryA");

    hProc = OpenProcess(PROCESS_ALL_ACCESS, false, id);

    paramAddr = VirtualAllocEx(hProc, 0, strlen(lpLibraryPath.c_str()) + 1, MEM_COMMIT, PAGE_READWRITE);

    if(WriteProcessMemory(hProc, paramAddr, lpLibraryPath.c_str(), strlen(lpLibraryPath.c_str()) + 1, NULL) == NULL)
    {
        printf("\nCouldn't write data to process : %s , error code : %s\n" , lpLibraryPath.c_str() , GetLastError());
        return 0;
    }

    CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, paramAddr, 0, 0);
    CloseHandle(hProc);
    return 1;   
}
};

Here is the main function -- here I call the method

int main()
{
  string pName;
  string dllPath = "c:\\C++ Dll to inject.dll";

  cout<<"Enter the process to inject the dll into: ";
  getline(cin , pName);

  app::process prc(pName);

  if(prc.inject(dllPath))
  {
        printf("Succesfully injected into process !\n\n\n");
  }
return 0;
}

I found some references on stackoverflow but they were of no help . like msvcp110.dll, how do I get around it? or Fixing the "MSVCP110D.dll is missing from your computer" issue

Answers
nr: #1 dodano: 2017-01-07 20:01

weird , asking for the debug version

Tells you what you did wrong, you accidentally copied the Debug build of the DLL instead of the Release build. Since you only changed the setting for the Release build, it still requires msvcp110d.dll. It is in general wise to change such a setting for all configurations and all platforms. Tedious, so it often gets skipped.

I copied the requested library manually in the release path and still wont work

Right, that cannot work since you injected the DLL. A different process. So when it is loaded, the install directory for the game is searched for the file, not the directory where your utility is installed.

Source Show
◀ Wstecz