Original Post
I've just begun to learn DLL-ing with MSVC++6.
I'm trying to use run-time linking using LoadLibrary and GetProcAddress.
DLLA.h contains
__declspec(dllexport) void printa();
DLLA.cpp contains
DLLTester contains
DLLA compiles fine, and produces a good dll as far as I can tell.
DLLTester also compiles ok.
When I run dlltester, LoadLibrary runs fine, but GetProcAddress returns NULL. - Am I exporting the function correctly?
OUTPUT:
dlla.dll = 10000000
Failed to load function
// This seems to be where main returns //
dlla(ProcAttach);
dlla(ProcDetach);
It seems to be that ProcAttach only happens when my program exits.
Is this the correct way to runtime-load a dll?
(I tried the web for basic dll tutorials, but all I could find were tutorials on how to write dll's)
[edited by - Krylloan on May 30, 2002 5:40:14 AM]
#include "stdafx.h"
#include "DLLA.h"
#include <stdio.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
printf("\ndlla(");
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
printf("ProcAttach"); break;
case DLL_THREAD_ATTACH:
printf("ThreadAttach"); break;
case DLL_THREAD_DETACH:
printf("ThreadDetach"); break;
case DLL_PROCESS_DETACH:
printf("ProcDetach"); break;
}
printf(")");
return TRUE;
}
__declspec(dllexport) void printa() {
printf("\na");
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef void (*vfp)();
int main(int argc, char **argv) {
freopen("c:\\lang\\media\\stdout.txt", "w", stdout);
HINSTANCE dlla = NULL;
dlla = LoadLibrary("c:\\lang\\kryll\\dll\\dlla.dll");
if(!dlla) {
printf("\nFailed to load dll");
return 1;
} else printf("\ndlla.dll = %p", dlla);
vfp fp;
fp = (vfp)GetProcAddress(dlla, "printa");
if(!fp) {
printf("\nFailed to load function");
return 1;
} else printf("\nprinta = %p", fp);
fp();
return 1;
}