Is it possible to find out what functions are available in an arbitrary dll file and then call these functions using C# interop services.
I don't know about "arbitrary" dlls, but for .net assemblies, there's an excellent utility called "Reflector" that will tell you what functions are inside. you can then call them with reflection. I'm not familiar with "interop services".
You can use Dependency Walker to find the exported functions in the DLL.
If the .dll is a managed assembly, then you can use the classes in System.Reflection
to find and run arbitrary methods.
If it's a native Win32 dll, then you have a much harder road to hoe: you have to P/Invoke the Win32 APIs LoadLibrary
and GetProcAddress
and call the functions you want through an unsafe pointer.
If its an unmanaged, native dll, you will need to use a program such as dumpbin or PE Explorer. Both programs will show the export section of the dll.
You can analyze the exported functions of any native module (DLL or EXE) using tools such as dumpbin. Once you have the signatures of the exported functions, you can write P/Invoke wrappers for any of them you wish.
Alternatively, you can use a tool like the P/Invoke Interop Assistant to automagically do the grunt work for you.
However, all of that relies upon the native module having listed the functions you're trying to call in its export table. If what you're looking to hook into is not actually exported, then you will have to resort to old-fashioned spelunking with GetProcAddress, etc.
So if the DLL you are refering to is a native DLL with C functione exports this is going to be range from easy to very difficult.
Easy: If you have the DLL and a C header file and even better with some documentation so that you know what arguments the exported functions expect, what calling convention is used. No problem use the .NET Interop services (PInvoke) as others have mentioned and call the functions you need.
Very Hard: If all you have is the DLL, you can discover the exports using DumpBin /exports filename.dll
but then you are left with disasembling the code to try and determine the calling convention and what possible values and types the function expects. To be honest, if this stuff is Greek to you then this is not Very hard, it is borderline impossible without huge but interesting learning curve.