CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2014
    Posts
    2

    Code works only on computer, when it was compiled

    Hello.
    For some reason this code dont work on other computers, but work on computer, where it was compiled. Any idea why?
    Code:
    #include <windows.h>
     
    
     
    
     
    int WINAPI DllThread()
    
    {
    	for (;;)
    
    	{
    		HMODULE hModule = NULL;
    		while (!hModule)
    
    
    		{
    			hModule = LoadLibraryA("scripter.dll");
    			Sleep(100);
    		}
    		
    
    		if (GetAsyncKeyState(VK_INSERT))
    		{
    			hModule = LoadLibraryA("Proxy.dll");
    			return 0;
    		}
    
    
    	}
    
    	}
    
    
    BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
            switch (ul_reason_for_call)
            {
            case DLL_PROCESS_ATTACH:
                    CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)DllThread, NULL, NULL, NULL);
                    break;
            case DLL_THREAD_ATTACH:
                    break;
            case DLL_THREAD_DETACH:
                    break;
            case DLL_PROCESS_DETACH:
                    break;
            }
            return TRUE;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Code works only on computer, when it was compiled

    You are using local paths for "Proxy.dll" and "scripter.dll".
    The probability that they will be the same on some other PC is very close to zero...
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2014
    Posts
    2

    Re: Code works only on computer, when it was compiled

    They are same and they exist.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Code works only on computer, when it was compiled

    See http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx and in particular the return value & GetLastError part. It will tell you exactly why it doesn't work
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Code works only on computer, when it was compiled

    Quote Originally Posted by xManiac View Post
    They are same and they exist.
    What are "same"? The "current working directories" on all these PCs are the same and they contain both dlls?

    BTW, if you checked the return value of LoadLibraryA and call the GetLastError in case LoadLibraryA failed then you could understand the reason of the problem.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured