Created
April 28, 2017 01:42
-
-
Save the-nose-knows/12a2f10b38ad767002bc4420678c92e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Answer is a slight diff of Ed Bayiate's answer on Stack Overflow | |
// Answer URI: http://stackoverflow.com/a/6903367/3543437 | |
// Question URI: http://stackoverflow.com/questions/6903256/how-to-programmatically-check-c-dll-files-and-c-sharp-dll-files-for-references | |
// Answer Author Profile URI: http://stackoverflow.com/users/695833/ed-bayiates | |
using System; | |
using System.IO; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Runtime.InteropServices; | |
namespace CA | |
{ | |
class Program | |
{ | |
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] | |
public static extern IntPtr GetModuleHandle(string lpModuleName); | |
[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_WITH_ALTERED_SEARCH_PATH = 0x00000008; | |
[DllImport("kernel32.dll")] | |
static extern bool FreeLibrary(IntPtr hModule); | |
[DllImport("kernel32.dll")] | |
static extern UInt32 GetLastError(); | |
static void CheckUnmanagedDll(string DllName) | |
{ | |
IntPtr hModule = LoadLibraryEx(DllName, new IntPtr(), LOAD_WITH_ALTERED_SEARCH_PATH); | |
if (hModule.Equals(IntPtr.Zero)) | |
{ | |
Console.WriteLine("Can't find " + DllName); | |
} | |
FreeLibrary(hModule); | |
} | |
static int Main(string [] args) | |
{ | |
CheckUnmanagedDll("C:\\pathToFile\\file.ext"); | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not working in my sample application, it doesn't have any related line of code.