Question:
How do I reference a dll in C# correctly?
ice
2006-07-19 02:25:21 UTC
There is this RCTDLL that I want to add as a reference to my project. But when I do add it to my project I get the error "A reference to C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Networking.RtcDll_6595b64144ccf1df_5.2.2.3_x-ww_d6bd8b95\rtcdll.dll cannot be added. Please make sure that the file is accessible, and that is a valid assembly or COM component"
Three answers:
alaa_tm
2006-07-19 02:57:18 UTC
First you need to know if this is a .net dll file, a COM component or a native win32 dll file.



You can easily add a reference to .net and COM dll files from References->Add



If it's a native dll then you need to know which function you want to import and the prototype of the function (the name, parameter list and their types, return type).

You can use a tool such as Depends.Exe located

Visual Studio .NET Folder\Common7\Tools\Bin

which will list all the exported functions for native dlls. However, it doesn't give you the list of parameters! So you need the documentation for the dll to be able to use it's functions.

For example:

the lstrcat function in kernel32.dll would be imported like this:

[DllImport("kernel32.DLL")] private static extern int lstrcat

([MarshalAs(UnmanagedType.LPTStr)] string lpstring1,

[MarshalAs(UnmanagedType.LPTStr)] string lpstring2);
♥HotIce♥
2006-07-19 02:44:15 UTC
I think the dll is not a COM dll so you won't be able to add reference to it:

You can use dllImport to invoke the methods present in that Dll.

For this you must be knowing the signature of the methods that you want to call,

Go through the following link.



Calling Win32 DLLs in C# with P/Invoke

http://msdn.microsoft.com/msdnmag/issues/03/07/NET/



I think this will solve your problem.

If still there for further help you can mail me,

i'll try to help if i can
foote
2016-12-10 15:00:42 UTC
Delegates assist you dynamically replace the behaviour of an merchandise. which you would be able to statically commerce the behaviour of an merchandise via using changing its form, usually to a derived class that overrides various methods. besides the undeniable fact that that determination is additionally too heavy weight in many situations, case in point in case you in basic terms had to customize a style set of rules it somewhat is easier to bypass a delegate than derive an entire new form. changing the behaviour of an merchandise using delegates turns into plenty greater effective whilst no least confusing is it impractical to derive a finished new type for an merchandise, you do no longer additionally be conscious of the class of the object interior the 1st region. case in point in a customer interface any volume of gadgets is likewise living house windows, all of with a view to usually grant customisation of mouse dealing with. that is much less confusing to grant a delegate to the window base type to administration the mouse than it somewhat is to derive many new training for each form of mouse dealing with you're able to desire to function. for people who recognized below the hood of C# and maximum an same languages, you will in looking that digital methods are utilized using delegates.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...