0

Hey guys I'm sorry to ask this but I haven't found my answer online. So i keep getting the error "arg of type "const char *" is incompatible with parameter of type "LPSTR"" when compiling one of my projects. How ever when i send it to my friend same code same everything he can compile it were both on windows 10 using visual studio 2017. Here is the Source code

    void RunProcess()
{
    runSetDebugPrivs();
    while (!FindProcessName("csgo.exe", &__gameProcess)) Sleep(12);
    while (!(getThreadByProcess(__gameProcess.th32ProcessID))) Sleep(12);
    __HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, false, __gameProcess.th32ProcessID);
    while (__dwordClient == 0x0) __dwordClient = GetModuleNamePointer("client.dll", __gameProcess.th32ProcessID);
    while (__dwordEngine == 0x0) __dwordEngine = GetModuleNamePointer("engine.dll", __gameProcess.th32ProcessID);
    while (__dwordVGui == 0x0) __dwordVGui = GetModuleNamePointer("vguimatsurface.dll", __gameProcess.th32ProcessID);
    __HWNDCss = FindWindow(NULL, "Counter-Strike: Global Offensive");
}

};

Exile
  • 1
  • 5
  • 1
    I'd wager you are using MSVC 15.5 or later, while your friend does not. – StoryTeller - Unslander Monica Jan 22 '18 at 20:22
  • The errors are on lines while (__dwordClient == 0x0) __dwordClient = GetModuleNamePointer("client.dll", __gameProcess.th32ProcessID); while (__dwordEngine == 0x0) __dwordEngine = GetModuleNamePointer("engine.dll", __gameProcess.th32ProcessID); while (__dwordVGui == 0x0) __dwordVGui = GetModuleNamePointer("vguimatsurface.dll", __gameProcess.th32ProcessID); so 7 8 and 9 – Exile Jan 22 '18 at 20:24
  • Go to your project options, find the "Conformance Mode" option under C/C++\Language and change it to "No". If you are serious about learning C++, you should get a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), and make sure that option is "Yes" on your future projects. – StoryTeller - Unslander Monica Jan 22 '18 at 20:28
  • Thank you so much and i have a few ebooks im working out of – Exile Jan 22 '18 at 20:30

2 Answers2

1

I think the problem is that the first parameter of GetModuleNamePointer function wants non-const char* string, but you put there const char* literal when you call the function. Literal constants are always const char*. The cause of this is probably the fact that other flavour of C language doesn't differentiate these in this condition. One possible fix is to change declaration of that function to accept LPCSTR (a.k.a. const char*) in the first parameter instead of LPSTR (a.k.a. char*).

You didn't show GetModuleNamePointer function, so I can only guess. If it is what I found on hack forums, it is declared like this:

DWORD GetModuleNamePointer(LPSTR LPSTRModuleName, DWORD __DwordProcessId);

But it can work with const safely, so you can simply change it to

DWORD GetModuleNamePointer(LPCSTR LPSTRModuleName, DWORD __DwordProcessId);

After this change in declaration it will be compatible with your compiler.

As already pointed out by @StoryTeller in comments, you can also disable the standard conformance in compiler. Here is description what it does and why it helps you: https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance

In short: Correct behavior is, maybe surprisingly, when your LPSTR program does't work. It works on older compilers, while new ones follow the standards more strictly. :-)

Al Kepp
  • 5,831
  • 2
  • 28
  • 48
0

Answer taken from this forum entry. Go to Project "Properties -> C\C++ -> Language" and make sure the "Conformance mode" is set to "NO"

Slavi
  • 161
  • 1
  • 4