{"id":1155,"date":"2010-11-08T10:02:11","date_gmt":"2010-11-08T08:02:11","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1155"},"modified":"2010-11-08T10:03:02","modified_gmt":"2010-11-08T08:03:02","slug":"how-to-get-hmodule-of-msvcr90-dll","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1155","title":{"rendered":"How to get HMODULE of msvcr90.dll"},"content":{"rendered":"<p>Because Microsoft C++ Runtime library is distributed as a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms229072%28VS.80%29.aspx\">side-by-side assembly<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms683199%28VS.85%29.aspx\">GetModuleHandle<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms684175%28VS.85%29.aspx\">LoadLibrary<\/a> is no longer available to locate the library within the process. Both API calls would return NULL handle.<\/p>\n<pre style=\"color: #000000; background: none repeat scroll 0% 0% #ffffff;\"><span style=\"color: #603000;\">HMODULE<\/span> hModule <span style=\"color: #808030;\">=<\/span> <span style=\"color: #400000;\">GetModuleHandle<\/span><span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">msvcr90.dll<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #603000;\">HMODULE<\/span> hModule <span style=\"color: #808030;\">=<\/span> <span style=\"color: #400000;\">LoadLibrary<\/span><span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">msvcr90.dll<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span><\/pre>\n<p>Still, how to locate the modules in order to, for example, be able to check DLL version? <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms684884%28VS.85%29.aspx\">Process Status API (PSAPI)<\/a> can help:<\/p>\n<pre style=\"color: #000000; background: none repeat scroll 0% 0% #ffffff;\"><span style=\"color: #004a43;\">#<\/span><span style=\"color: #004a43;\">include <\/span><span style=\"color: #800000;\">&lt;<\/span><span style=\"color: #40015a;\">psapi.h<\/span><span style=\"color: #800000;\">&gt;<\/span>\r\n<span style=\"color: #004a43;\">#<\/span><span style=\"color: #004a43; font-weight: bold;\">pragma <\/span><span style=\"color: #bb7977; font-weight: bold;\">comment(lib, <\/span><span style=\"color: #0000e6; font-weight: bold;\">\"psapi.lib\"<\/span><span style=\"color: #bb7977; font-weight: bold;\">)<\/span>\r\n\r\n<span style=\"color: #808030;\">.<\/span><span style=\"color: #808030;\">.<\/span><span style=\"color: #808030;\">.<\/span>\r\n\r\n<span style=\"color: #603000;\">DWORD<\/span> nDataSize <span style=\"color: #808030;\">=<\/span> <span style=\"color: #008c00;\">4<\/span> <span style=\"color: #808030;\">&lt;<\/span><span style=\"color: #808030;\">&lt;<\/span> <span style=\"color: #008c00;\">10<\/span><span style=\"color: #800080;\">;<\/span> <span style=\"color: #696969;\">\/\/ 4K<\/span>\r\nEnumProcessModules<span style=\"color: #808030;\">(<\/span><span style=\"color: #400000;\">GetCurrentProcess<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #808030;\">&amp;<\/span>nDataSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nnDataSize <span style=\"color: #808030;\">+<\/span><span style=\"color: #808030;\">=<\/span> nDataSize <span style=\"color: #808030;\">\/<\/span> <span style=\"color: #008c00;\">2<\/span><span style=\"color: #800080;\">;<\/span>\r\nCTempBuffer<span style=\"color: #800080;\">&lt;<\/span><span style=\"color: #603000;\">HMODULE<\/span><span style=\"color: #800080;\">&gt;<\/span> phModules<span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_THROW<span style=\"color: #808030;\">(<\/span>phModules<span style=\"color: #808030;\">.<\/span>AllocateBytes<span style=\"color: #808030;\">(<\/span>nDataSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> E_OUTOFMEMORY<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>EnumProcessModules<span style=\"color: #808030;\">(<\/span><span style=\"color: #400000;\">GetCurrentProcess<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> phModules<span style=\"color: #808030;\">,<\/span> nDataSize<span style=\"color: #808030;\">,<\/span> <span style=\"color: #808030;\">&amp;<\/span>nDataSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n<span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">const<\/span> SIZE_T nCount <span style=\"color: #808030;\">=<\/span> nDataSize <span style=\"color: #808030;\">\/<\/span> <span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> <span style=\"color: #808030;\">*<\/span>phModules<span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">for<\/span><span style=\"color: #808030;\">(<\/span>SIZE_T nIndex <span style=\"color: #808030;\">=<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #800080;\">;<\/span> nIndex <span style=\"color: #808030;\">&lt;<\/span> nCount<span style=\"color: #800080;\">;<\/span> nIndex<span style=\"color: #808030;\">+<\/span><span style=\"color: #808030;\">+<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #800080;\">{<\/span>\r\n        CPath sPath <span style=\"color: #808030;\">=<\/span> _VersionInfoHelper<span style=\"color: #800080;\">::<\/span>GetModulePath<span style=\"color: #808030;\">(<\/span>phModules<span style=\"color: #808030;\">[<\/span>nIndex<span style=\"color: #808030;\">]<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span> <span style=\"color: #696969;\">\/\/ uses GetModuleFileName<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>_tcsicmp<span style=\"color: #808030;\">(<\/span>FindFileName<span style=\"color: #808030;\">(<\/span>sPath<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> _T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">msvcr90.dll<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">=<\/span><span style=\"color: #808030;\">=<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #808030;\">)<\/span>\r\n        <span style=\"color: #800080;\">{<\/span>\r\n            <span style=\"color: #696969;\">\/\/ NOTE: Here we found it<\/span>\r\n            ATLTRACE2<span style=\"color: #808030;\">(<\/span>atlTraceGeneral<span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">2<\/span><span style=\"color: #808030;\">,<\/span> _T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">msvcr90.dll version is <\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> _VersionInfoHelper<span style=\"color: #800080;\">::<\/span>GetVersionString<span style=\"color: #808030;\">(<\/span>_VersionInfoHelper<span style=\"color: #800080;\">::<\/span>GetFileVersion<span style=\"color: #808030;\">(<\/span>sPath<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            <span style=\"color: #800000; font-weight: bold;\">break<\/span><span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800080;\">}<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n<span style=\"color: #800080;\">}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Because Microsoft C++ Runtime library is distributed as a side-by-side assembly, GetModuleHandle and LoadLibrary is no longer available to locate the library within the process. Both API calls would return NULL handle. HMODULE hModule = GetModuleHandle(_T(&#8220;msvcr90.dll&#8221;)); HMODULE hModule = LoadLibrary(_T(&#8220;msvcr90.dll&#8221;)); Still, how to locate the modules in order to, for example, be able to check&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1155\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,13],"tags":[487,38,218,303,304],"class_list":["post-1155","post","type-post","status-publish","format-standard","hentry","category-seriously","category-source","tag-atl","tag-c","tag-debug","tag-psapi","tag-runtime"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1155"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1155\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}