CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2010
    Posts
    10

    Linking both 32- and 64-bit dlls

    I am using a third-party library that has seperate 32 and 64 bit libraries:

    C:\Program Files (x86)\CompanyName\LibraryName.lib
    and
    C:\Program Files (x86)\CompanyName\x64\LibraryName.lib

    The libraries are not COM and have no namespaces by which to differentiate them, and all the function names are the same.
    My project lead wants my library that incorporates theirs to dynamically link to the correct one at runtime (it is safe to assume the LibraryName.dll exists on the computers that run this program).

    How might I go about doing that? I can't use preprocessors because they run at compile time but I don't know any way to link the libraries (or for that matter, determine bit count) at runtime. I could just reference both libs but I'm sure I would just get ambiguity errors.

    Help me out, pros. I need direction.

    Thanks!

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Linking both 32- and 64-bit dlls

    Wow, someone actually using dynamical libraries dynamically :P I do it all the time, here you go.

    Code:
    HANDLE library = LoadLibrary("oneYouWant.dll");
    if (library){
       funcPtr foo = GetProcAddress(library, "foo");
    }
    
    foo(bar);
    Thats how to dynamically load a library, but mixing 32 and 64 bit versions scares me, especially on Windows. I don't think this will work. If any of your functions in the library use pointers, I promise you that it won't work.

  3. #3
    Join Date
    May 2010
    Posts
    10

    Re: Linking both 32- and 64-bit dlls

    That looks exactly like what I needed, but I neglected to mention something else maybe you know.

    I'm creating a COM dll out of these libs, so there is a static class incorporating my calls. Is there a constructor for when a static class is loaded/first called so I can instantiate the function pointers? It wouldn't make sense to do this every time a static function is called.

    I apologize for what's probably a bad question. I'm still learning about dlls, COM and managed code.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Linking both 32- and 64-bit dlls

    Well, you could do something with a singleton I guess.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured