Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- int main(int argc, char *argv[])
- {
- apiprint(NULL, "[HotLoad Dll Test]\n");
- char dllPath[MAX_PATH] = {0};
- lstrcpyA(dllPath, argv[1]);
- char dllName[MAX_PATH] = {0};
- lstrcpyA(dllName, argv[2]);
- char dllFull[MAX_PATH] = {0};
- lstrcpyA(dllFull, dllPath);
- dllFull[lstrlenA(dllFull)] = '\\';
- lstrcatA(dllFull, dllName);
- apiprint(NULL, "Dll Path: %s\n", dllPath);
- apiprint(NULL, "Dll Name: %s\n", dllName);
- apiprint(NULL, "Dll FUll: %s\n\n", dllFull);
- HMODULE dll;
- math_add MathAdd;
- math_sub MathSub;
- math_mul MathMul;
- math_div MathDiv;
- while (true)
- {
- dll = LoadLibraryA(dllFull);
- MathAdd = (math_add)GetProcAddress(dll, "m_add");
- MathSub = (math_sub)GetProcAddress(dll, "m_sub");
- MathMul = (math_mul)GetProcAddress(dll, "m_mul");
- MathDiv = (math_div)GetProcAddress(dll, "m_div");
- apiprint(NULL, "Dll Update! Testing functions:\n");
- apiprint(NULL, "m_add(5, 10) = %d\n", MathAdd(5, 10));
- apiprint(NULL, "m_sub(5, 10) = %d\n", MathSub(5, 10));
- apiprint(NULL, "m_mul(5, 10) = %d\n", MathMul(5, 10));
- apiprint(NULL, "m_div(5, 10) = %d\n", MathDiv(5, 10));
- apiprint(NULL, "Waiting for dll to update...\n\n");
- FreeLibrary(dll);
- waitForChange(dllPath);
- }
- getchar();
- return 0;
- }
- void waitForChange(char *path)
- {
- HANDLE waitHandle = FindFirstChangeNotificationA(path, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
- WaitForSingleObject(waitHandle, INFINITE);
- }
- void apiprint(int buffsize, char *fmt, ...)
- {
- HANDLE phandle = GetStdHandle(STD_OUTPUT_HANDLE);
- char *printstring;
- printstring = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (buffsize==NULL)?256:buffsize);
- memset(printstring, 0, sizeof(printstring));
- va_list args;
- va_start(args, fmt);
- vsprintf(printstring, fmt, args);
- va_end(args);
- WriteConsoleA(phandle, printstring, lstrlenA(printstring), NULL, NULL);
- HeapFree(GetProcessHeap(), NULL, printstring);
- }
Add Comment
Please, Sign In to add comment