1) If the method name is different from the DLL's entry's name - you'll have to specify that in the EntryPoint
property. Otherwise, you may omit it.
2) Control is returned to you after that method's execution ends. How it handles errors is depend on its implementation, but usually methods returns an error code (in this case, probably true
if the execution succeeded, and false
if it failed). Once again, it depends on its implementation, but it may set the Win32's "LastError". If it does, you should set the property SetLastError
of the DllImport
attribute, and if it fails, you may call to Marshal.GetLastError()
, or throw Win32Exception
.
3) DllImport allows you to consume a method from an unmanaged DLL. You can also wrap it with C++/CLI project, to create managed DLL wrapper, but on most cases that would be an over-kill.