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

后端 未结 2 579
青春惊慌失措
青春惊慌失措 2021-01-13 08:35

I have run into this issue too many times and need this to be an automated approach:

I have multiple DLL files that are constantly being built/changed that multiple

2条回答
  •  Happy的楠姐
    2021-01-13 09:01

    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);
     }
    

提交回复
热议问题