AfxLoadLibrary different vc6 to vc9
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: AfxLoadLibrary different vc6 to vc9

  1. #1
    Join Date
    May 2006
    Posts
    4

    AfxLoadLibrary different vc6 to vc9

    Just migrating to vc9 from vc6.

    I have a bunch of extension dlls that basically act as plugins, which may be added optionally.

    We put them in a subfolder under our app; appmain/plugins/appspecific/blah.dll

    In vc6, we used AfxLoadLibrary(plugins/appspecific/blah.dll) and it would load them fine.

    With vc9 it is failing. It turns out that there is an issue with the dll dependency in these plugins. In vc6, they appear to have loaded with appmain as their "current" folder so they would be able to pick up the dlls in that folder. Now, however, with vc9, they seem to load from the plugins/appspecific folder!

    As a test, if I put the plugin in the appmain folder, everything works fine. But it messes up a lot of configuration for people.

    Does anyone have any ideas?

    Thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,477

    Re: AfxLoadLibrary different vc6 to vc9

    Just generate the full path to where the dll's are located. I assume that the dll's are either in the application directory or in a sub directory below the app directory.

    If that's the case, then use GetModuleFileName( NULL, ... ) and strip off the exe name. Then use that path to form the complete path to the dlls that you would like to load.

  3. #3
    Join Date
    May 2006
    Posts
    4

    Re: AfxLoadLibrary different vc6 to vc9

    Thanks Arjay. Let me just make sure I've got this right:

    In appmain folder I have xyz.dll
    In appmain\plugins folder I have abc.dll

    So I'm using AfxLoadLibrary("appmain\\plugins\\abc.dll") to load my plugin. It requires xyz.dll. In vc6 it worked but in vc9 it did not work.

    So you're saying if I use the complete path AfxLoadLibrary("c:\\program files\\appmain\\plugins\\abc.dll) it will be able to find the xyz.dll in the appmain folder?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,477

    Re: AfxLoadLibrary different vc6 to vc9

    I misunderstood the dependency issue. In general, I prefer to provide explicit paths to loadlibrary to avoid any confusion where the dll is being loaded from.

    To solve your problem, retrieve the path of the app as I mentioned before, then call SetWorkingDirectory. Finally call load library.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center