- using System;
- using System.Runtime.InteropServices;
- namespace CallTestDLL
- {
- class Program
- {
- // ************COMMENT SHOWING A DIFFERENT WAY TO DECLARE THE PROTOTYPE*********************
- //[DllImport('TestDLL.dll', CallingConvention = CallingConvention.Cdecl)]
- //[return: MarshalAs(UnmanagedType.I4)]
- //public static extern int DLLFunction([MarshalAs(UnmanagedType.I4)] int Number1,
- // [MarshalAs(UnmanagedType.I4)] int Number2);
- // *****************************************************************************************
- // Description of DLL import:
- // 'TestDLL.dll' is the file being loaded.
- // The calling convention is cdecl as the function was exported in this way.
- // 'public static extern' means that this function does not belong to a class (static) and that it is
- // defined elsewhere (in the DLL).
- // The comment above shows what the function would look like if you wanted to Marshal the unmanaged
- // types yourself. However, int is done automatically so there is no need to add the Marshal attributes.
- [DllImport('TestDLL.dll', CallingConvention = CallingConvention.Cdecl)]
- public static extern int DLLFunction(int Number1,
- int Number2);
- static void Main(string[] args)
- {
- // Simple call the function as any other.
- Console.WriteLine(DLLFunction(2, 4));
- Console.ReadLine();
- }
- }
- }
![Calling a dll from c programs Calling a dll from c programs](/uploads/1/2/5/2/125290719/449639109.jpg)
Calling Dll From C Program
Use DLL in C without lib. Straightforward answer. How can I use the functions in a DLL in C without a LIB file to go with it? I know all of the function prototypes and their names. Thanks in advance! Is.LIB file needed to call DLL in C++ but not for C# P/Invoke? Linking DLL with.DEF or.LIB file.