Importing a class with dllimport [Resolved]
I am trying to import a class from a dll I created. The class seems to import fine. I can access data members of the class but when I try to access a member function of the class then I get errors. Here is the code in my .h file:
Code:
#ifndef MYLIBAPI
#define MYLIBAPI _declspec(dllimport)
#endif
MYLIBAPI int func1();
class MYLIBAPI MyClass
{
public:
void func();
int value;
};
Here is the code in my .cpp file:
Code:
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#include "test.h"
typedef int (*DllFunc)();
void main(void)
{
HINSTANCE hDll;
DllFunc func1;
hDll = LoadLibrary("Test2.dll");
if (hDll != NULL)
{
printf("Library successfully loaded!\n");
func1 = (DllFunc)GetProcAddress(hDll, "func1");
if (!func1)
printf("Error loading function!\n");
else
printf("The returned value is %i!\n", func1());
MyClass ClassTest;
ClassTest.value = 3;
ClassTest.func();
printf("The value of 3 after MyClass.func() is %i.\n", ClassTest.value);
FreeLibrary(hDll);
}
else
printf("Failed to load library!\n");
}
Here is the error I get:
Quote:
--------------------Configuration: asdf - Win32 Debug--------------------
Compiling...
stuff.cpp
Linking...
stuff.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall MyClass::func(void)" (__imp_?func@MyClass@@QAEXXZ)
Debug/asdf.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
asdf.exe - 2 error(s), 0 warning(s)
If anyone knows why I am getting this link error or what I can do please let me know. Any help would be appreciated.