0

stackoverflower i got a problem so i made a application in windows form but now i want to make it show becouse i inject it its a dynamic library not a executeable iknow that you use this for winapi

BOOL APIENTRY DllMain(HMODULE hModule,
    DWORD  ul_reason_for_call,
    LPVOID lpReserved
    )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hModule);
        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&showform, NULL, 0, 0);
        break;
    case DLL_THREAD_ATTACH:  break;
    case DLL_THREAD_DETACH:  break;
    case DLL_PROCESS_DETACH: break;
    }
    return TRUE;
}

and i tried this for windows form

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    if (fdwReason == DLL_PROCESS_ATTACH)
    {
        DisableThreadLibraryCalls(hinstDLL);
            hProcessCenter = ::FindWindow(NULL, _T("WINDOW"));

    }
    return 1;
}

i am gettings these errors for windows form:

Error 1 error C3641: 'DllMain' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

Error 2 error C2065: 'hProcessCenter' : undeclared identifier

Error 3 error C3861: '_T': identifier not found

i hope that somebody can help me out

Arix
  • 29
  • 5

2 Answers2

0

Well for error 1, I would refer to the example in the accepted answer in here for proper includes: How to specify dll onload function for mingw32?

Error 2 says that you need to define "hProcessCenter" in your DllMain(...) function somewhere. Probably, as you are not using the variable somewhere, you can convert the line to be ::FindWindow(NULL, _T("WINDOW")); to have compilable code.

For Error 3, you need to be sure to compile with Unicode support. Otherwise the macro _T is not found (What does _T stands for in a CString).

Community
  • 1
  • 1
Peter Merkert
  • 354
  • 5
  • 14
  • Error 2 error LNK1306: DLL entry point "int __clrcall main(cli::array^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z) cannot be managed; compile to native – Arix Oct 22 '16 at 11:25
  • @Neevo Lima Macro _T can be used to target both ANSI and UNICODE applications and it's declared in tchar.h – Asesh Oct 22 '16 at 12:22
0

To correct error #1 you should compile to native code rather than managed

Fix for error #2:

HWND hProcessCenter;
if (fdwReason == DLL_PROCESS_ATTACH)
{
    DisableThreadLibraryCalls(hinstDLL);
        hProcessCenter = ::FindWindow(NULL, _T("WINDOW"));

}

Fix for error #3:

#include <tchar.h>
Asesh
  • 3,186
  • 2
  • 21
  • 31
  • hmm i am still getting errors this is the code [STAThreadAttribute] int main(array ^args) { // Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it Application::Run(gcnew Form1()); return 0; } DLL entry point "int __clrcall main(cli::array^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z) cannot be managed; compile to native – Arix Oct 22 '16 at 12:08
  • Looks like you are using C++/CLI – Asesh Oct 22 '16 at 12:18
  • Yes i am using c++ windows form with c++ winapi how do i fix this?? – Arix Oct 22 '16 at 12:29
  • So is it managed DLL? If it is then managed DLLs should not have an entry point while managed exes should have one. You can move your DLL initialization code out of your main function and initialize the DLL from outside – Asesh Oct 22 '16 at 12:45
  • Its a dll that you inject to a game and idk what your explaining i dont get it – Arix Oct 22 '16 at 13:07
  • In other words, managed DLLs (in your case) don't have an entry point like DllMain which is for native applications. You should remove that DllMain and create another method and it's corresponding implementation in that method. Then it will compile – Asesh Oct 22 '16 at 13:41