Example:
DLL:
Code:
#include <stdio.h>
#include <Windows.h>
void sampleputs(const char *msg)
{
if(msg)
{
puts(msg);
}
else puts("<NULL Pointer>");
}
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
Test program:
Code:
#include <stdio.h>
#include <Windows.h>
typedef void (*FN_OUTPUT)(const char *);
int main(void)
{
FN_OUTPUT fnOutput = NULL;
HMODULE hModule = LoadLibrary("sampledll.dll");
if(hModule)
{
if((fnOutput = (FN_OUTPUT)GetProcAddress(hModule,"sampleputs")))
{
fnOutput("Success!");
fnOutput(NULL);
fnOutput = NULL;
FreeLibrary(hModule);
}
else fputs("Invalid proc.", stderr);
}
else fputs("Invalid dll.", stderr);
return 0;
}
Output:
Code:
Success!
<NULL Pointer>
Compilation for MinGW:
Code:
gcc -Wall -ansi -pedantic -O3 -shared sampledll.c -osampledll.dll
gcc -Wall -ansi -pedantic -O3 sampledyn.c
Edit: Apologies for C code, but this was the quickest example I had.