in VS2008 I created a project from the MFC template. Everything is working. Next, connect the third-party dll. Compilation is successful. However, when you start the application, it swears at the absence of MSVCP90.dll. The search showed that such files are located in subfolders of the C: \ Windows \ winsxs directory. Similarly, in C: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ VC \ redist. The method of "scientific tyke" from the example (it seems to have been created in VS2008), supplied with a plug-in dll, copied a piece of code into the project:

#ifdef _DEBUG #ifdef _M_IX86 #pragma comment(linker,"/manifestdependency:\"type='win32' " "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " "version='" _CRT_ASSEMBLY_VERSION "' " "processorArchitecture='x86' " "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"") #pragma comment(linker,"/manifestdependency:\"type='win32' " "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".MFC' " "version='" _MFC_ASSEMBLY_VERSION "' " "processorArchitecture='x86' " "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"") #else #pragma comment(linker,"/manifestdependency:\"type='win32' " "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " "version='" _CRT_ASSEMBLY_VERSION "' " "processorArchitecture='amd64' " "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"") #pragma comment(linker,"/manifestdependency:\"type='win32' " "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".MFC' " "version='" _MFC_ASSEMBLY_VERSION "' " "processorArchitecture='amd64' " "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"") #endif #endif 

and it all worked.

  1. Why without this code exe-shnik can not find the necessary dll?
  2. Where in the project the directives #ifdef _DEBUG and #ifdef _M_IX86 are defined, that the condition becomes true? Somewhere in the project properties?
  3. Explain the essence of this code. And how it affects the search for the desired dll. I don’t remember what they wrote in the book. Or give a link where it is well written.
  4. If you create a similar MFC project in VS2010, that with this piece of code, that without, swears at the absence of MSVCP90.dll. I noticed if you create a project in VS2008 with this piece of code. Then open it in VS2010 and in the settings put the Platform toolset v90, then it works. How, initially creating a project in VS2010, point to this dll?

Thank.

    1 answer 1

    There is such a thing as " previously declared (added) definitions ". Your two are just like that.

    • _DEBUG Defined as 1 when the / LDd, / MDd, or / MTd compiler options are added. Otherwise, it is not defined.
    • _M_IX86 Defined as a number with a value of 600 if compiled for an x86 processor. This macro is not defined for the x64 or ARM platform.

    This was the answer to the second question.

    #pragma comment is a very versatile piece. In this case, it allows you to transfer options to the linker. And the rest - just tying, that would form the right.

    This was the answer to the third question.

    In this case, these lines form a special manifest file, where they add different hints for the PE file loader (that is, exe files).

    Why is all this necessary? At one time, Microsoft came across a problem called "dll hell" (nightmares with dll) - when there are several dll, different versions that work a little differently. And, programmers (bad programmers), knowing this, will surely carry with them the “correct dll” and copy them into the windows folder (and it’s not serious to keep them in your folder). Microsoft, scratched a turnip and came up with a piece called side by side, she's SxS, she's "side by side." If the application needs standard specific versions, they will be provided to it by slipping the correct ones. And so that Windows would know what is needed, for this there is a manifest file. This is the answer to the first question.

    What book is it written in? oh that's a good question. Usually this is written on msdn.com - because it is not part of the standard, but things specific to a particular compiler.

    • Look, please, if it doesn’t make it difficult, I added the 4th question to the original one. Thank you - pucher
    • as it is not customary here to expand and expand the question, doing a lot from one. On the other hand, why do you use such an old studio? can take 6 more? - KoVadim 6:39 pm
    • I will consider about expansion - pucher February
    • about the studio. There is a third-party program. It comes with .lib and .h files for use by its dll by third-party applications (like mine). According to the documentation "... dll was created using the Ms Visual C ++ 2008 compiler. Redistributable Visual C ++ 2008 SP1 9.0.30729.6161 must be installed for the libraries to work." It is installed. Creating a project in vs2008, he uses the redist by default. 2008, as well as the connected library. When inserting the manifest into an exe file (the one in the question itself, also from the documentation), it automatically finds the required version of the library and everything works ... - pucher
    • only I do not want to use vs2008. At least vs2010 or higher. That's just when creating an application, it already uses acc. Redist 2010 When you turn on the manifest in exe, the compilation fails with the error "warning C4083: expected ')'; found identifier '__LIBRARIES_ASSEMBLY_NAME_PREFIX". When you start the application, an error pops up that can not find the MSVCP90.dll. Which is probably used by the plug-in library. Therein lies the question of how to make it work with studios higher than vs2008. Thank you - pucher