๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘จ๐Ÿผ‍๐Ÿ’ป๊ฐœ๋ฐœ/C | C++

C/C++ - DLL ๋งŒ๋“ค๊ธฐ, DLL ์‚ฌ์šฉํ•˜๊ธฐ (GCC)

by Janger 2023. 3. 23.
728x90
๋ฐ˜์‘ํ˜•

 

my_dll.c (DLL ๋งŒ๋“ค๊ธฐ)

 

#include <windows.h>

void func() {
    system("start www.google.com");
}

 

GCC DLL ๋นŒ๋“œ

 

gcc -shared my_dll.dll -o my_dll.c

 

run.c (DLL ์‚ฌ์šฉํ•˜๊ธฐ)

 

#include <stdio.h>
#include <windows.h>

typedef void(*dll_func)();

int main(){

    HINSTANCE hDLL = LoadLibrary("my_dll.dll");
    if(hDLL == NULL){
        printf("Failed to load DLL\n");
        return 1;
    }

    dll_func func = (dll_func)GetProcAddress(hDLL, "func");
    if(func == NULL){
        printf("Failed to get function address\n");
        return 1;
    }

    (*func)();

    return 0;
}

 

 


 

#include "windows.h"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    system("calc.exe");
  
    return TRUE;
}

 

 

gcc -shared test.dll -o test.c

 

 

rundll32 test.dll ANYTHING~
728x90
๋ฐ˜์‘ํ˜•