File will be changed after copying to system32 - c++

I have a helper DLL that I'm using for a long time without any change in its signature and I copy it to system32 in order to use it in all my products, now I add a function to its export list and compile it, everything looks OK and I have a new DLL that contain specified function. My problem is when I copy it into system32 specified function is missing, it looks like somehow it will be copied from a cache and some old version of it will be loaded, so programs that depend on new function will be failed! does anyone know what is the problem?

Most likely you have a 64 bit system. You copy the file to the 64 bit system directory, system32. But, because of the file system redirector, your 32 bit application loads it from the 32 bit system directory, SysWOW64.
Solve the problem by copying to SysWOW64.
You probably know this, but I feel compelled to say it anyway. The system directory belongs to the system and you should not be writing to it.

Use this to command to clear the dll cache. This has been tested on Win XP and Win 7.
sfc /purgecache
Please note that you need to be an admin to run this command or "Run as administrator". Not a 100% sure if this will fix your problem.

Related

Choosing from multiple DLL versions

Today I build my application and packaged the installer with QtIF. It worked nice on my computer but complained about missing msvcp140_1.dll in another computer.
Then I run find . -iname "msvcp140_1.dll" and found more than five different ones on my computer, I checked the md5sum.
Then I spend the time to try all of them on the other computer and all seem to work fine. No more complains about missing DLL.
How should I choose between the DLLs? Just pick any seems too easy.
Is there someway to inspect the DLLs, to check for a version?
I believe that DLL was a dependency from another binary included in my application, was not that the QtIF failed to include it.
Call the MS Redist Installer from your Installer. This can be done quietly, so that the end user does not notice it.
Find the vcredist_x64.exe file (or vcredist_x32 for 32 Bit applications), add it to your installer,
let it extract to the "TEMP" folder
and then call vcredist_x64.exe /quiet at the end of your install.
This has several advantages:
You will definitely copy all required files to the users computer.
Should new versions of the runtime library be released by Microsoft and should they already be on your users computer, your code will use the newer versions, which may include bugfixes.
Windows Update may also update the libraries.
That said, it is possible to copy the DLLs themselves, but you should make sure
a) you choose the right ones
b) they come from a trustworthy place, i.e. your VS installation folder
c) reside in the same directory as the executable - otherwise you will run into trouble with manifests.
The reason you might want to include the DLLs directly is if you want to reduce the overall size of your installer.
We did this a couple of years with our products, but finally gave in and simply used the vcredist_x64.exe, even if that increased the installer binary another couple of MB in size. But in the long run that's the easiest way.
I think (not sure), msvcp140_1.dll is an additional DLL for the VS 2019 runtime. VS 2017 runtime does not need this, but the new one does.
The non-redistributable method is to ship the DLL's that come with your compiler, i.e. the compiler that built your executable. After all, the DLL will be loaded into the same process as your EXE. It's only logical that these should match.
You'll find those DLL's in \Program Files*\Microsoft Visual Studio *\VC\Redist

How to build the program, so that DLLs won't be required at the location of EXE ( CodeBlocks )

I have, after some effort, successfully built a little piece of example code and make it run. I am using C++ in CodeBlocks 13.12 on a Win 7 x64 machine. The program makes use of wxWidgets and OpenGL libraries.
The problem is, that in order to make the EXE run successfully, I had to copy these DLL files to the location of EXE :
wxbase30ud_gcc481TDM.dll
wxmsw30u_core_gcc481TDM.dll
wxmsw30u_gcc48.dll
wxmsw30ud_core_gcc481TDM.dll
wxmsw30ud_gl_gcc481TDM.dll
I would like to know how to build the program ( what settings to change in project) so that the EXE file will be able to run on its own ( and also on other machines ) - without "missing DLL" error messages ? It would be nice if answer could be general and useful as a reference in future, similar issues.
In the linker, you could add lines similar to this one:
-static wxbase30ud_gcc481TDM
However, this isn't terribly effective or good practice. Better would be to go ahead and include the dll's with your .exe, and simply supply a shortcut to your program that the user could move anywhere. This allows you to install and keep all your program files together, but still let the user only worry about one for the entire thing.
You could use something like Enigma Box, which packs the DLLs into an exe and if you call LoadLibrary it will function as expected:
http://enigmaprotector.com/en/about.html
Some others exist like ILMerge or XBundler I heard as well... haven't used them though. I heard DLLPack too.

MSVCR100D.DLL and dependency walker

I put MSVCR100D.DLL into the c:\windows\system32 folder but dependency walker is still complaining about it being missing. Any ideas?
Dependency walker hasn't been updated in a very long time. I think the author just gave up trying to keep up with Windows development. Particularly resolving side-by-side manifest lookup rules is a very hard problem to solve. SetDllDirectory() is impossible to resolve statically. It isn't very smart about delay-loaded DLLs and it doesn't know anything about DLL exports that are forwarders. You almost always get a big list of missing DLLs that are not actually missing.
Using the 32-bit version on a 64-bit operating system does not work well either, your probable mistake in the case of msvcr100d.dll. Which must be copied into c:\windows\syswow64, not system32 for a 32-bit executable. You really want to favor local deployment for msvcrt versions 10 and up. In other words, simply copying the DLL into the same directory as the EXE. Putting it in the Windows system directory exposes you to too much DLL Hell, well beyond picking the wrong system directory.
If you still have trouble then SysInternals' ProcMon is the better tool. The trace it generates shows you exactly where it looked for the DLL.

"missing glut32.dll" with OpenGL under VS2010

I'm using OpenGL under VS2010 doing a program for a long time. The program can always run independtly(I mean not run from vs2010 but double click out side of the IDE) until now. "missing glut32.dll" shows to make me put it under the same directory.
Some one may say that I may losing glut32.dll in system32(or in my case, syswow64 for 64 bit windows). It is proved true when I put it in the dir. The question is: I've never removed it before. How can it be that case?
glut32.dll is not a core system library. It's not installed there by default. Maybe some program's installer did put its own copy into the system directory and removed it on uninstallation.
Anyway, glut32.dll is not a standard library and as such it's not a bad thing to ship an independent copy with your own program.
You must put the glut.dll files in:
C:/Windows/SysWOW64
This is the folder where 32-bit .dlls are located.
C:/Windows/System32 contains the 64-bit .dlls.
You can also put the GLUT.dlls in System32, if you want to feel safe.
You could've just uninstalled something. I think it shouldn't be there in the first place, since it isn't some sort of standard library.
Anyway, it's always wise to supply all of the libraries needed by your program. You can have multiple applications using GLUT in different versions, so it's best bet to just keep it close to executable.
Copy and paste the file glut32.dil in location C:\Windows,
it will fix all your problems.
If this does not work, then follow the steps below:
Go to settings->compiler->linker settings->add C:\MinGw\lib\glut32.lib then PRESS ok.
Go to settings->compiler->Toolchain executables->C:\Program Files (x86)\CodeBlocks\MinGW
then copy and paste the file glut32.dll in location C:\Windows
In W10 (64b), glut32.dll is not installed as standard and the convention seems to be "go find the source and compile it" (assuming like me you have an aversion to getting it off generic dll download sites).
Eventually, after visiting https://opengl.org/resources/libraries/glut/ , I found http://vis.eng.uci.edu/~jkimball/eecs205/glut.html which has a link to the DLL at https://user.xmission.com/~nate/glut.html
Oddly, regsvr32 would not register it, but dropping it into c:\Windows\SysWOW64\ worked fine.
Not to be confused with glu32.dll which is already there.
Hope this helps. Pls don't be rude by downvoting without explanation or modifying my reply for brownie points. I am trying to do you a favour.

Deploy c ++ program with vbscript?

I have created a windows application and a folder with the release executable and appropriate Dlls.
First problem is that I want to package it all into one setup.exe For this task I plan on using windows default iexpress application....(is there better software available for this...must be free though, since this is only for a university assignment)
Second problem is I want to structure the installation so that the actual program along with included libraries are saved in their disk drive, i.e program files(x86) for w7. And at the same time make a desktop shortcut so its easier to run and access for the user.
The issues arising with my second problem is:
Am I wrong to assume that a user will have a 'program file' folder ??
I am thinking of making a vbscript to handle the creating shortcut, but does a vb.exe also need library files to be included ??
Assignment due in 2 days so I would really be grateful if I could get this off my chest
Thx :)
You may be interested in following SW:
Advanced installer
NSIS
WIX
I would recommend first option, it's free for your purpose, you don't need to buy professional license and you can make MSI package in 5 minutes.
No, Program Files folder is common to the valid Windows installation. But you shall not assume that it's always C:\Program Files. You must use corresponding environment string to get program files folder:
%ProgramFiles% - to store 32 bit programs on 32 bit OS and 64 bit programs on 64 bit OS.
%ProgramFiles(x86)% - to store 32 bit programs on 64 bit OS.
VBScript has nothing to do with Visual Basic (VB.exe) itself. It's running by Windows Script Host and does not require any additional libraries. Windows Scripting Host is included by default into any modern Windows OS.
You just create script source file with extension .vbs and run it as any usual executable. Example of creating shortcut could be found here.
You have an environment variable ProgramFiles with in it the path to this folder.
Doesn't include the software you used to build the exe and dll files an installer/packager ?
Otherwise I would search a free packaging program, it should be the easiest way, making the shortcut could also be done by this package. On the other hand if you want to use vbscript you could do it all from there too but your script would have to be executed by the user with administrative rights, not for the everyday user...
free packaging: Some googling gave me http://www.windowsnetworking.com/articles_tutorials/msi-packaging-tools.html, check it out