Untitled

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
1.2 kB
16
Indexable
Never
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
    // Load the DLL module
    HMODULE hModule = LoadLibraryA("user32.dll");
    if (hModule == NULL) {
        cout << "Failed to load the DLL module." << endl;
        return 1;
    }

    // Get the address of the function
    FARPROC functionAddress = GetProcAddress(hModule, "MessageBoxA");
    if (functionAddress == NULL) {
        cout << "Failed to get the address of the function." << endl;
        FreeLibrary(hModule);
        return 1;
    }
    // Print out the address of the function
    cout << "Address of MessageBoxA: " << GetProcAddress(hModule, "MessageBoxA") << endl;

    // Define the function signature using a function pointer
    typedef int (*MessageBoxAFunc)(HWND, LPCSTR, LPCSTR, UINT);

    // Cast the function address to the correct function pointer type
    MessageBoxAFunc MessageBoxA = reinterpret_cast<MessageBoxAFunc>(functionAddress);
    cout << MessageBoxA << endl;
    // Call the function
    int result = MessageBoxA(NULL, "Hello, World!", "MessageBox Example", MB_OK);

    

    // Free the DLL module
    FreeLibrary(hModule);

    return 0;
}