Jump to content
  • Advertisement
Sign in to follow this  
bjut

easy DLL question

This topic is 4802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello! I'm trying to make a DLL which uses some functions in other LIB files and DLLs. When I try to register it using regsvr32, I get a failed message unless I also put the other DLLs that I used in the same directory as the DLL that I'm trying to register. If I am to use my DLL as a plug-in to another application, then I would also need to register the other DLLs, right? Is there a way to permanently import the functions that I used into my DLL so that I wouldn't have to register so many of the other DLLs? By the way, I'm using Visual C++ .NET 2003. Thanks!!

Share this post


Link to post
Share on other sites
Advertisement
If that is what you want to do then just use static library links. You completely abandon the advantages of a DLL by importing all the functions at compile time. Keep in mind, however, if any of those libraries ever need to change then you must recompile everything that uses it (this is the exact problem that dlls were made to fix!)

hth,
moe.ron

Share this post


Link to post
Share on other sites
If you're designing a DLL as a plugin then you should be able to drop it into the plugin directory and that is it. You shouldn't have to register it at all.
The program that is using the plugin should automatically recognize the DLL and take the appropriate action to handle that DLL.

Try using the GetProcAddress(*) function to call the functions inside of the DLL.

Share this post


Link to post
Share on other sites
thanks guys!

yup you're right about that! DLLs are supposed to be "dynamic". The reason why I wanted to statically link the other DLLs with my DLL is because the application that I'm trying to make a plugin for says that it can't load the DLL. So I have to test whether it's because of dependency issues or because of my code. I already put some MessageBox's in the initialization methods and they didn't come up before the application gave an error so it might be due to dependency issues. Just to make sure, I'd like to statically link them to my DLL if possible and see if it would pass through my initialization codes.

How do you statically link them anyway?

Share this post


Link to post
Share on other sites
Your going to have to either a.) create a new project that is setup to create a static library (.lib) or b.)change your current project (which would just be messy)

There is no way that I know of to statically link to a dynamic library directly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you cannot statically link funcs from other dlls into your code unless you have a lib that has the dll's code in it in order to do that. the lib for the dll just has references to the dll's funcs but none of the funcs internal code. so if you have the source for the other dlls then you can create a lib that can then be statically linked into your plugin.

btw, what types are the dlls your plugin references? system or 3rd party?

given your first post, the inability to register the dll kind of sounds like a pathing problem for your system. if these other dlls are not system dlls, then they will need to be distributed with your plugin and hence will need to be within the same directory as your plugin. if they are system dlls then they're either not in a directory that's within your load path or they are but are referencing other dlls that are not in a directory within the load path.

what exactly do you mean by the app says it can't be loaded? does it explicitly state that the LoadLibrary call failed or your plugin's referencing some other dlls that it can't find? is this a system error message or an app error message? if this is not a specific error message pointing you directly to a dll dependency issue or some other specific issue then i'd suggest you contact the app's dev(s) to find out what exactly is going on. normally if you send them your plugin they'll be able to figure things out very quickly since they have the app's source and will be able to debug step through to the failure point.

if this is a very specific error message indicating dll dependency failure, one easy way to determine whether it's your plugin's fault or the app's fault or one of the referenced dll's fault, is to use the Depends app that comes with VC++ (at least it did for 6.) put your plugin in the app's plugin directory and then load it up with Depends and see if Depends is able to resolve all external references. if that's not a problem then my next step would be to use the linker's delay load capabilities to remove all external references at load time, delaying the referencing and loading of the used dlls until one of their funcs is first called. then see if that plugin version is able to be loaded by the app. if not, my next step would be to write a little test harness app that mimics the other app's plugin loading, and see how that works out, and if it fails, where.

if none of that points to any dll dependency issues, then it could be that you're using compiling options that are creating incompatibilities between the app and the plugin. for instance, maybe the app can LoadLibrary the plugin, but it can't call it's init func(s) because it assumes stdcall func naming, whereas you used c++ func naming with all of its func decorating. so it's trying to get the proc addresss for your plugin's "Init" func, but your plugin only exports an "Init@@QAE@XZ" func. again, the app should be able to tell you this specifically . one easy way to determine whether this might be the problem is to generate a map file for your plugin and then take a look at its exported func names and see if they match up with the app's requirements. the app's plugin docs should also explicitly state what type of calling convention is needed, and whether you need to use a .def or not to trim off the excess func name decorators.

that's about all i can think of for now. if you tell us what app you're developing the plugin for, and explain how you set up your project, we might be able to help some more.

Share this post


Link to post
Share on other sites
hey thanks for the replies!

forgot about this post coz I didn't have the email notification "ON". anyway you're right. I'm using a 3rd party SDK and I only have the headers, LIB, ang DLLs. So I guess static linking is out of the question since the LIB files don't seem to have the source in them. thanks for making that clear, moeron.

It's also too bad that I wasn't able to read this post sooner. The LoadLibrary error message was due to not being able to find the other DLLs that my plug-in was referencing. You were right. I just put the other DLLs in the same path of the plug-in when registering it using regsvr32 and it went fine. The other error that said that the app couldn't load my plug-in was due to an older version of the DLL that I'm using being loaded first by the app. This is because some other plug-in that came with the app also uses the same SDK and DLL but older. I just replaced that DLL with a newer version that came with the SDK.

Thanks a lot and keep it up!

Share this post


Link to post
Share on other sites
BTW - regsvr32 is only used for registering COM components. If your application or the library you are using are not implemented as COM components then you have no need to call regsvr32.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!