Click to See Complete Forum and Search --> : DLL linker header Confusion


John_M_Gough
November 19th, 2007, 02:55 PM
Hi. I have just learned how to make dll`s, that part was easy. the problem is when i create a header for loading the dll. functions were easy but classes and structures, lets say i had a struct like this for example (How it would look if i just used a header file and not a dll).

struct Times
{
public:
float ConstAmount;

Times(int Constent)
{
ConstAmount=Constent;
}

~Times()
{
Delete [] ConstAmount;

}

Float Go(float TimesBy)
{
return (ConsAmount*TimesBy);
}
Private:
}


How would i make a header file that loads this from the dll so it can be used as normal?.

and the same for this


enum Flags
{
FLAG1=1
FLAG2=10
}


the only other thing is #define SOMEHING 400, Can this be in the dll or can i only define these in the loader header file.

Thank You All For Your Time.
ps im using Dev C++

henky@nok.co.id
November 20th, 2007, 06:04 AM
You need to understand "definition" and "implementation" in C/C++.
When your code:

class MyClass
{
MyClass();
void MyFunction();
};

This is just definition of MyClass class. It still needs to implement this class.
It will be:

MyClass::MyClass()
{
......
}

void MyClass::MyFunction()
{
......
}

The DLL only keeps the implementation. I suggest you read C/C++ tutorial/handbook again.

Marc G
November 20th, 2007, 10:21 AM
#define SOMEHING 400 is only used by the compiler during compilation process, so yes, you should put it in the header file.

John_M_Gough
November 20th, 2007, 09:58 PM
henky@nok.co.id Thankyou for your post, i understand how to use classes and structures, the example was how i would have writen the struct if i was using a header file. my problem is accessing the class from the dll, if it were a function i would access it like this:

typedef UINT (CALLBACK* LPFNDLLCLASS_LFI)(LPCSTR);
LPFNDLLCLASS_LFI LoadFromIni;
. . .
hDLL = LoadLibrary("Lib/J_Libarary.dll");
. . .

LoadFromIni=(LPFNDLLCLASS_LFI) GetProcAddress(hDLL,"LoadFromIni");


using this method to load a class or struct, casts a function, not a class with a constructor and its own functions for controlling it. it only casts a function. in other words it wont let me do this:

LoadFromIni iniPrefs("Prefs.ini");
iniPrefs.loadint("anint_A");


i would be greatfull if you or anyone else could help me resolve this problem.
Thankyou.

PS. i dont have a handbook yet only WIN32.HLP