This is a discussion on c# within the C# Programming forums, part of the Software Development category; How do you directly call a native function exported from a DLL? Here’s a quick example of the DllImport ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| How do you directly call a native function exported from a DLL? Here’s a quick example of the DllImport attribute in action: using System.Runtime.InteropServices; \ class C { [DllImport(\"user32.dll\")] public static extern int MessageBoxA(int h, string m, string c, int type); public static int Main() { return MessageBoxA(0, \"Hello World!\", \"Caption\", 0); } } This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA. For more information, look at the Platform Invoke tutorial in the documentation. |
| Sponsored Links |
| |||
| f a method is marked as protected internal who can access it? 1. Classes that are both in the same assembly and derived from the declaring class. 2. Only methods that are in the same class as the method in question. 3. Internal methods can be only be called using reflection. 4. Classes within the same assembly, and classes derived from the declaring class. |
| |||
| What’s the difference between private and shared assembly? Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name. |
| |||
| How can you tell the application to look for assemblies at the locations other than its own install? Use the directive in the XML .config file for a given application. < probing privatePath=c:\mylibs; bin\debug /> should do the trick. Or you can add additional search paths in the Properties box of the deployed application. |
| |||
| What is delay signing? Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development |
![]() |
| Thread Tools | |
| Display Modes | |
| |