Thread: Need help with plug-ins

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    6

    Need help with plug-ins

    I am designing a plug-in interface for a program. I can get the driver program to load the plug-in but when I try to access a function the function pointer value is NULL. I've gotten this to work using extern "C" but that will not do for this application because polymorphism will be used extensively. I know it is possible to do plug-ins with a C++ interface but I don't know how and thus far the internet has been less than useful.

    I've also tried to access the functions via their mangled names but that didn't work either.

    I am using Microsoft Visual C++ 6.0 and am using the LoadLibrary fuction to load a plug-in and GetProcAddress to get the pointers of functions.

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    How do you call GetProcAddress?

    C++ names are mangled when you compile them, to help resolve parameter overloading. You need to be looking for the mangled name (I think).

    Moved to windows board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Quote Originally Posted by Salem
    How do you call GetProcAddress?

    C++ names are mangled when you compile them, to help resolve parameter overloading. You need to be looking for the mangled name (I think).

    Moved to windows board.
    well, it depends on the interface of the function. For a function with no parameters i use
    int (*func)(void) = (int(*)(void))GetProcAddress(hm,"FunctionName");
    where hm is the handle to the plug-in.

    I have tried using the mangled names. I'm not sure if I used them correctly. I just ran dumpbin on the dll with the /export option and copied and pasted the name.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You probably didn't use the correct mangled name. What is the prototype of the function you are trying to call?

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    the function is: int TestPlugin::Type()

    dumpbin tells me the name is ?Type@TestPlugin@@EAEHXZ

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    What compiler are you using? Are you exporting the function?

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Quote Originally Posted by bithub
    What compiler are you using? Are you exporting the function?
    I'm using Microsoft Visual Studio 6.0 and yes, I am exporting the function. If I wasn't I don't think dumpbin would list it as an exported function.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Ok, you can't just export a function that is part of a class, then call it. You should export the entire class. This way you can create class objects, and call the function that way. Visual Studio will create a .lib file when you compile the dll class. Just have your application link to that .lib file, and then you include the dll header file. Once you've done that, you can create the class, and call its functions.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    I don't think linking to the lib file will be possible. It needs to support future plug-ins. But I will look into exporting the entire class. Thanks

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I see what you are trying to do now. Read the following article:
    http://www.codeguru.com/Cpp/W-P/win32/article.php/c1443

  11. #11
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Wonderful, that looks to be exactly what I need. I'll give it a try tomorrow and let you know how it goes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plug ins
    By Rune Hunter in forum C++ Programming
    Replies: 17
    Last Post: 09-04-2004, 09:12 PM
  2. Case mods for fans?
    By Shadow in forum Tech Board
    Replies: 12
    Last Post: 04-04-2003, 02:03 PM
  3. Funniest thing happened to be earlier this year
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 11-07-2002, 05:39 PM
  4. Shameless plug...
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-03-2002, 09:56 PM
  5. Insert plug here...
    By CompiledMonkey in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-07-2002, 07:12 PM