How to programmatically check C++ DLL files and C# DLL files for references to debug DLLS to automate a testing procedure

你。 提交于 2019-12-01 05:44:33

If you know the names of all the DLLs (because, for example, you ran Dependency Walker) you can just use LoadLibrary to check for unmanaged DLLs.

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
const UInt32 DONT_RESOLVE_DLL_REFERENCES = 0x00000001;
const UInt32 LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
const UInt32 LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;

[DllImport("kernel32.dll")]
static extern bool FreeLibrary(IntPtr hModule);

[DllImport("kernel32.dll")]
static extern UInt32 GetLastError();

void CheckUnmanagedDll(string DllName)
{
    IntPtr hModule = LoadLibrary(DllName);
    if (hModule.Equals(IntPtr.Zero))
        MessageBox.Show("Can't find " + DllName);
     FreeLibrary(hModule);
 }

Use GetModuleHandle to check for the presence of a DLL with the given name. If you want to know if it's a debug version or not, then you need to compile that information into the EXE and check for it somehow. "Debug" vs. "Release" is not a concept built-in to PE format; it's just a set of compile options. Many people put a flag in the version information to indicate whether it's an internal vs. public release.

P/Invoke reference for GetModuleHandle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!