Am working on VC++ application that generates an exe file and dll file with same name.
Now i want to change the dll filename for purpose.
I tried it changing in Project-Properties but still no luck.
Application is giving the renamed dll while i build.
But if i run the exe it showing the error "The Program cant start, dll name is missing"
Please tell me how to generate the dll with a different name.
A DLL must be in the path of the executable, so first check if your path is setup correctly or copy the DLL into the directory where your EXE is.
If you link against a DLL, the name of the DLL may not change, as it will be used for reference. If you want to be able to rename the DLL as you whish you must either load the DLL dynamically, then you can load a DLL from wherever you want. Or you must link against the renamed DLL.
Related
I have an C++ application in dir\executables.
I have a dll in dir\libraries.
And in case it's important, my header files are in dir\headers.
When I copy my dll into dir\executables, the program runs just fine, but when the dll is not in the executables directory, I get an error complaining about being unable to find the dll.
Is there a way to write or build my program so that it takes responsibility for finding the dll itself without having to modify PATH, update the registry or copy the dll into the same folder as the executable?
I am new to windows, I have a dll project that generates a dll and a test project which is an exe that consumes or calls the functions in dll. I am using visual studio 2010 to execute this. currently when i check the general properties of dll under configuration properties , the target name is DecryptEmailDll and target extension is .dll .With this the test exe runs fine and I get the desired output. But when i try to rename the dll's target name to TransformEmail, the build is fine ,but while running it says "unable to find DecryptEmailDll" . I am not able to understand why it is trying to find the old dll with the old name and not the new one.
The test.exe has been built with the file name to search for. So you have to change it and rebuild it with the new dll name.
Well, if you change the name of the dll, you have to either change the import lib declaraction, if you static import the dll (I suppose with cahnge the dll name you meant also the name of the lib and exp). Or, if you dynamicly import, change the parameter of the LoadLibrary function.
The project runs okay in the debug mode of Visual Studio, but when I tried to double-click the exe generated, it says some dll is missing. When I copied the missing dll beside the exe and double-click again, no error message dialog appeared but also nothing happened(the project has Qt-based GUI and reference some external png files).
How does Visual Studio run the exe ? How can I run the exe on my own ? Should I create a installer for the project to make it run on other computers?
you would need to either build statically or provide the required dll files.
the page at http://www.tapkaa.com/2013/05/what-dll-files-are-required-to-run-an-application-developed-with-visual-c/ tells how you can find the missing dll files.
When a process needs to load a DLL by name (without a full path to it), it will check several different places. One of those places may be the current working directory. (The details of the search path are complicated by history and security issues. You can learn the details by looking up LoadLibrary and SetDllDirectory on MSDN.)
In Visual Studio, if you look at the Properties page for the project, and click the Debugging tab, you'll see what directory is set as the working directory when you launch the program from Visual Studio. When you double click on an icon, I believe the working directory will be the directory of the executable file. If these are different, that could explain why you're able to find the DLL in one case but not in the other.
If you're calling LoadLibrary directly, the best thing to do is to always give the full path to the library. Typically, you GetModuleFileName to find out the full path for the executable, then replace the filename portion with the name of the DLL or a relative path from the executable to the DLL.
If you're failing to load an implicitly-linked DLL, then you probably need to make sure your DLL is in the same directory as the executable file.
I have a general question about how .dll/.libs are suppose to be used. I am creating a .dll to be used for my project, however, I noticed that when I go to compile I need to statically link the .lib associated with the .dll for the project to compile (otherwise there is the linking error "fatal error LNK1107: invalid or corrupt file: cannot read at 0x300"). So later when I go redistrobute my project, then update it in the future, will I need to ship a new .exe and a new .dll rather than only a new .dll? If that is the case, then why bother using .dll's?
The .lib contains stubs for the functions etc. that are exported by the DLL. You link the .lib into your EXE and now your EXE knows how to call the functions. But of course there's no function there - the calls go nowhere. At load time, when the operating system loads your EXE it also loads your DLL, and then it patches the EXE - where the EXE calls into the stub, the loader replaces that with a call into the real function in the DLL.
Normally you do not need to ship the .lib to your customers. However, if your customers want to write their own EXEs that use your DLL then you will need to send them the .lib so that they can link their EXE against it.
Linker error LNK1107 means that you've tried to link to the DLL rather than to the .lib. That's always wrong, because by definition a DLL is linked dynamically at runtime, rather than statically at build time.
In Visual Studio, you create a .dll project and it creates a .dll and .lib files. You link statically to the .lib, and if the .dll is in the same folder as the .exe, everything works.
I suspect that everything would also work if the .dll was in System32 or any other PATH folder (confirm or correct, please).
But here's the question: I want my exe to find the .dll in ./DLLS/ folder, that is, if my exe is in ....../MyApp/MyApp.exe then it should look for the .dll in ...../MyApp/DLLS/MyDll.dll. I DO NOT want to include the DLLS folder in path. Is there any way I can do this?
Please note that I do not wish to use LoadLibrary explicitly, so I can't specify the path there.
Thanks in advance for any help.
Here is the default sequence which Win32 applications go through when looking for a DLL:
http://msdn.microsoft.com/en-us/library/7d83bc18(VS.80).aspx
So according to this, another approach might be to call SetCurrentDirectory or SetDllDirectory. But in order for this to work you have to use the Delay Loaded Library functionality (you specify that in Project Settings in Visual Studio). Delay loaded library means that the DLL is loaded only at the moment when the program needs it, not automatically at the programs' startup.
You could use SetDllDirectory for this. The loader will use the additional directory you specify when loading libraries. There can only be one additional directory, however, so you need to make sure that there aren't other calls to this at a later point in your application, otherwise the directory you specify will be ignored.
If that API does not allow relative directories (I'm not sure), you could always call GetModuleFileName with a NULL first parameter to get the file name of the currently executing program. With a little string manipulation, you can get the absolute path to your DLLs folder.