Thread: Create program that accept modules

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    10

    Create program that accept modules

    Hi all...

    I'm new to c++ programming, and I wanna learn some programming concepts..

    What I need is some tutorial or some directions on creating a program that accept modules, like apache, that accept the php module for example...

    Does you know some books??

    Thx...

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    you have to crawl before you can fly. what you're talking about is far in the distance from just starting out.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Yes, you should start off with something smaller, like most beginners that post here - a MMORPG.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    hehe thanks... I will do that...

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    The thing is that I'm not new to programming, i have programmed in java and c#, and in c# we do this with dependency injection with the cab framework. But my c# programming days are over...

    Is there some framework for dependency injection in c++??

    Thx...

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm not entirely sure what "dependency injection" actually means.

    Accepting modules, however, can be done in several ways. The easiest is probably to have a shared library that you load at runtime rather than directly link against the library. That way, you can decide which module(s) to load. If all modules have the same interface (or a subset of a standard interface), then you can use any of the modules interchangably, and get different behaviour from it.

    Having said that, you do need a fair bit of programming experience and a bit of interface design experience to get there.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    Yeah, I think of that.. Have an interface that all modules must implement.. The case is how can I load a module at run time??

    I think of have a configuration file that tells me what modules to load with their options, but I dont know how to load a library at runtime...

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Depends on the OS you are using. LoadLibrary works for Winodws, dlopen() is used for Linux and several other Unix flavours. Other OS's may or may not have a similar thing - if they don't, then the problem becomes a fair bit harder, because you basically have to achieve the same thing yourself.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    [edit] Way too late for this reply. That's what happens when you leave tabs open indefinitely . . . . [/edit]

    Unfortunately, loading other libraries or "modules" at runtime is platform-specific. I'm not sure how to do it on Windows, but I'm sure it's related to DLLs (which are runtime libraries under Windows). Under linux you'd probably use dlopen() and friends.

    But really, this is quite complicated to do. I wouldn't recommend it unless you have a pretty good understanding of C++ already.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    I'll program in linux...

    Is there other ways of creating modules different of that???

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rluceac View Post
    I'll program in linux...

    Is there other ways of creating modules different of that???
    There is no EASIER way to get external code into your project, but there may be ways to get flexibility without using external code.

    It depends a lot on what you are trying to do. You may for example choose to have a little language of your own or configuration files that contain values/controls that allow you to do some flexibility in your application, rather than using externally generated code in a shared library or similar.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Apr 2009
    Posts
    10
    What I need is to let my app accept plugins, like firefox or so...

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rluceac View Post
    What I need is to let my app accept plugins, like firefox or so...
    Ok, so what are you ACTUALLY trying to do?

    Right now, I feel like the car-mechanic being asked "How do I undo a wheel-nut", when I know that no sane person wants to just undo a wheel-nut, it doesn't make any sense. So the customer PROBABLY has a puncture, and will be back in half an hour with another question. If you tell us what the ACTUAL problem is ("I've got a puncture, how do I fix it?"), then we can probably help a whole lot better than what you are describing so far.

    Note that firefox plug-ins are written in JavaScript, so are not compiled in the same way that C or C++ code would be.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I disagree that this is all that complicated. On either Linux or Windows it comes down to opening a dynamic library then getting a pointer to a function within that library.

    Linux:

    Code:
    void *handle = dlopen("module.so", RTLD_LAZY);
    void (*func)() = (void (*)())dlsym(handle, "fooFunc");
    func();
    Windows:

    Code:
    HMODULE handle = LoadLibrary("module.dll");
    void (*func)() = (void (*)())GetProcAddress(handle, "fooFunc");
    func();
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I guess as long as function pointers are understood (at least at a basic level), then it shouldn't be that bad.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 06:31 AM
  2. How to create a file association program?
    By eShain in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2006, 12:15 PM
  3. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  4. program won't create status bar
    By Unregistered in forum Windows Programming
    Replies: 7
    Last Post: 08-30-2001, 04:00 PM