Programming .dll's

Questions about programming languages and debugging
Post Reply
User avatar
Asuna
suck-o-fied!
suck-o-fied!
Posts: 92
Joined: 27 Dec 2006, 17:00
17
Location: New York, USA

Programming .dll's

Post by Asuna »

I know I might be posting a lot of C++ questions lately and I apologize for that, but this one really stumps me.

How do you program .dll files with C++? I did figure out something i didn't know: .dll's contain code that can be shared between programs to save on memory usage. That's pretty cool!

Anyways, how do i add code to my .dll? I'm using Bloodshed Dev C++ 4.9.9.2 for my compiler. And I had the compiler generate the basics of a .dll project:

Code: Select all

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);

  private:

};


#endif /* _DLL_H_ */
So, should I do something like this?

Code: Select all

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);

  private:

  int main ()
  {
      //my code/data/etc.
  }

};


#endif /* _DLL_H_ */
seems to make sense. or should i add my code to public and not private? if it's in private it means that only the .dll can use the code, but, if the code is in public, it means that's the code that will be shared between the programs, right?

if i've figured it out myself that you would need to tell me (i might be unaware that i did). next! after the .dll works, how would i tell a program to use the .dll? it's most likely not the #include command, or is it? (srry, not trying to be funny (you know, the "or is it? mwhahahaha!" jokes (ie. "It's not blood... or is it? mwhahahaha!")), i'm just really confused.)

any help will be appreaciated! and if i didn't already do it: thanks to everyone who helped me with my other C++ questions.

User avatar
RNA
suck-o-fied!
suck-o-fied!
Posts: 95
Joined: 23 Nov 2006, 17:00
17
Location: A bit to the right of null
Contact:

Post by RNA »

no, the main method is called when an application is ran, the dll is not ran.

I would strongly advise you learn C++ classes, as thats what a dll really is, an encapsulated class.

there are alot of great places on the net to learn these things, and I'd advise you dont go within 200meters of any windows programming without understanding all these basics.

Code: Select all

http://www.cplusplus.com/doc/tutorial/
that was the first place I pulled up on google, and it looks ok.

Post Reply