Rundll32.exe doesn't function as expected, when attempting to call function in custom DLL

74 views Asked by At

I am learning how to write C++ in order to better understand how DLL work and how functions are called from within DLL. I am attempting to run calc.exe from within my DLL using rundll32.exe. In my code (below), when executing rundll32.exe with my compiled DLL as a argument, I expect spwncalc() to get called from DLLMain() (regardless of what export function/ordinal I pass through rundll32.exe) and calc.exe to start. I have also tried to call the spwncalc() function through the execution of rundll32.exe, but I can't get calc.exe to execute.

#include <windows.h>

void spwncalc()
{
        WinExec("C:\\Windows\\System32\\calc.exe", 1);
}
BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved){
        switch(dwReason){
                case DLL_PROCESS_ATTACH:
                        spwncalc();
                        break;
                case DLL_PROCESS_DETACH:
                        break;
                case DLL_THREAD_ATTACH:
                        break;
                case DLL_THREAD_DETACH:
                        break;
        }
        return TRUE;
}

How could I change my code so that when I run rundll32.exe calc_spwn.dll,spwncalc, it executes my function? Also, is there a way to get get it to load when the the dll is loaded through rundll32.exe?

0

There are 0 answers