c++ - Basic DLL Function -
i'm new world of c , programming generally! trying create simple dll file prints messagebox hello world!
here's cpp
//main.cpp #include "main.h" // sample exported function void dll_export somefunction(const lpcstr sometext) { messageboxa(0, sometext, "dll message", mb_ok | mb_iconinformation); } extern "c" dll_export bool apientry dllmain(hinstance hinstdll, dword fdwreason, lpvoid lpvreserved) { switch (fdwreason) { case dll_process_attach: // attach process // return false fail dll load break; case dll_process_detach: // detach process break; case dll_thread_attach: // attach thread break; case dll_thread_detach: // detach thread break; } return true; // succesful }
and here h
//main.h #ifndef __main_h__ #define __main_h__ #include <windows.h> /* use exported function of dll, include header * in project. */ #ifdef build_dll #define dll_export __declspec(dllexport) #else #define dll_export __declspec(dllimport) #endif #ifdef __cplusplus extern "c" { #endif void dll_export somefunction(const lpcstr sometext); #ifdef __cplusplus } #endif #endif // __main_h__
the point once make console loads dll have call function it! how export functions without giving them name load dll in console? if wanna use dll , doesn't know call? or if got exe calling dll e want create custom dll functions called? not hacking porpuses! sorry skills thx
"what if wanna use dll , doesn't know call" - if uses dll, needs know call, there not simple ways around (therefore provide *.h function declarations).
there ways enumerate functions provided dll (see e.g. here: win32 api enumerate dll export functions?), not how dll libraries used.
note can enumerate function names, without header might not easy find out parameters pass each function , type functions returns. can in general done c++ exported functions (the c++ name mangling provides parameter count , type information), not if function exported plain "c" function (where name simple function name without mangling).
Comments
Post a Comment