.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   loading a dll (http://forums.bots-united.com/showthread.php?t=3215)

@$3.1415rin 17-12-2004 10:32

Re: loading a dll
 
I guess sockets would be still the way to go ... since you can load plugins into the server without any problems, why try to do some other stuff, which might be prevented or causing other problems.

Lazy 17-12-2004 20:17

Re: loading a dll
 
Quote:

Originally Posted by stefanhendriks
Lazy, why aren't you a heck of a bot-coder? :P You seem to have some pretty good knowledge about this stuff! :)

I can't remain focused enough unfortunately, I have ideas and always wanted to make a bot to teach people Natural Selection but keep getting lost in bloated frameworks.
Although the one I'm making now isn't bad I just have re-design parts of it.
And my math is terrible too :)

As for using sockets, make sure you use non-blocking sockets so the server won't have to wait for calls to recv and send to return.

dub 22-12-2004 20:43

Re: loading a dll
 
here a way windows only using CreateToolhelpSnapshot Then Module32First
& Module32Next.

Code:


class CProcess 
{
public:
        CProcess () : dwProcessID(NULL), dwThreadId(NULL), iStrLen(0) { }
        virtual        ~CProcess () { }
        DWORD        GetProcessIDFromExeName (LPSTR lpExecutableName);
        MODULEENTRY32 GetModuleEntryForDll (LPSTR lpExeName, LPSTR lpDllName);
       
        HANDLE                hSnapshot;
        PROCESSENTRY32  pe32;
        MODULEENTRY32        me32;
private:
        DWORD                dwProcessID;
        DWORD                dwThreadId;
        int                        iStrLen;
        char                        szExeName[64];
};

DWORD CProcess::GetProcessIDFromExeName (LPSTR lpExecutableName)
{
        if ((hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPALL, NULL)) == INVALID_HANDLE_VALUE)
                return NULL;

        pe32.dwSize = sizeof (pe32);

        if (!Process32First(hSnapshot, &pe32))
        {
                CloseHandle (hSnapshot);
                return NULL;
        }

        // scan all the open process`s on the computer
        do
        {
                iStrLen = strlen (pe32.szExeFile);

                strcpy (szExeName, &pe32.szExeFile[iStrLen]);
               
                // skip the backward slash and get just the exe name
                // if it returns the full path name doesn`t seem to do
                // it in XP just the exe name.
                if (strstr (pe32.szExeFile, "/") != NULL)
                {
                        while ((iStrLen) && (pe32.szExeFile[iStrLen-1] != '/'))
                                iStrLen--;
                        strcpy (szExeName, &pe32.szExeFile[iStrLen]);
                }

                // some reason break didn`t seem to work
                if (strcmpi (lpExecutableName, szExeName) == 0)
                        goto done;
               
        } while (Process32Next (hSnapshot, &pe32) != 0);

done:
        CloseHandle (hSnapshot);
        return (pe32.th32ProcessID);
}

MODULEENTRY32 CProcess::GetModuleEntryForDll (LPSTR lpExeName, LPSTR lpDllName)
{
        if ((hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, GetProcessIDFromExeName (lpExeName))) == INVALID_HANDLE_VALUE)
        {
                ZeroMemory (&me32, sizeof (me32));
                return me32;
        }

        me32.dwSize = sizeof (me32);

        if (!Module32First (hSnapshot, &me32))
        {
                CloseHandle (hSnapshot);
                ZeroMemory (&me32, sizeof (me32));
                return me32;
        }

        // scan all the open process`s on the computer
        do
        {
                // some reason break didn`t seem to work
                if (strcmpi (lpDllName, me32.szModule) == 0)
                        goto done;
               
        } while (Module32Next (hSnapshot, &me32) != 0);

done:
        CloseHandle (hSnapshot);
        return (me32);
}

after you will have full access for the dll.


All times are GMT +2. The time now is 06:07.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.