|
-
September 15th, 2010, 12:05 PM
#1
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!
-
September 15th, 2010, 12:17 PM
#2
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.
-
September 15th, 2010, 12:33 PM
#3
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.
-
September 15th, 2010, 01:11 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|