Hi, ive been programming c++ (up from C) for two days now, and i want to use a class in a dll. Right now im just using the skeleton dll provided by dev-cpp with an add function in there, so i hope i havent stuffed up what i did change.
Code:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
DllClass::DllClass()
{
}
int DllClass::add(int a, int b)
{
return(a + b);
}
DllClass::~DllClass ()
{
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
and then my executable code
Code:
#include <iostream>
#include <windows.h>
typedef int (*AddFunc)(int,int);
using namespace std;
int main(int argc, char *argv[])
{
AddFunc _AddFunc;
HINSTANCE hInstLibrary = LoadLibrary("dllLoadingTestdll.dll");
if (hInstLibrary == NULL)
{
printf("o o");
FreeLibrary(hInstLibrary);
}
_AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "DllClass::add");
if ((_AddFunc == NULL))
{
printf("O O");
FreeLibrary(hInstLibrary);
}
//printf("%d\n", _AddFunc(23, 43));
getchar();
FreeLibrary(hInstLibrary);
return(0);
}
which i also copied for the most part off the net, so i hope i didnt stuff this up either.
anyway, what i want to know is how to get the function address for my add function.
_AddFunc == NULL is returning true, and its ouputting "O O" so thats where the problem is.