C-Sharp call standard dynamic library

xiaoxiao2021-03-06  66

What is C # calls the standard dynamic library, speaking in my previous file, C # calls Win32API, the principle is the same. Here I explain to write a standard dynamic library, then let C # call. ( This article is suitable for beginners, there is no redundancy code, simple and clear in the middle) software environment: VC6.0 (Of course other versions of VC5 can also be) 1. Making standard dynamic libraries __DECLSPEC (DLLEXPORT) INT __CDECL Add (int, int, int, int, int This sentence is to declare a dynamic library output a function prototype .int Add (int A, int b) {// implementing this function Return A B;} More 3 line code, declare an AddD Method, the input parameter is two int parameters, returns these two numbers. Save as MYLIB.C and then execute the compile command. H: / xschool / c # -school / howto> Cl / LD MYLIB.CMICROFT (R) 32 -bit C / C Optimizing Compiler Version 12.00.8168 for 80x86Copyright (C) Microsoft Corp 1984-1998. All rights reserved. MyLib.cMicrosoft (R) Incremental Linker Version 6.00.8447Copyright (C) Microsoft Corp 1992-1998. All rights reserved . /out:mylib: MYLIB.LIBMYLIB.OBJ CREATING LIBRARY MYLIB.LIB and Object MyLib.ex is confident that the output is successfully generated. 2. Write the C-Sharp program call Bank Using System; Using System.Runtime.InteropServices; // This is the package public class invokedll {[DLLIMPORT ("Mylib.dll", Charset = Charset.DLL)] Static Extern Intd (Int A) , int b); // Declare the external standard dynamic library, which is the same as Win32API. public static void main () { Console.WriteLine (add (10, 30));}} Save as an invokedll.cs file, placed with mylib.dll in the same directory, compile this file. H: / Xschool / c # -school / howto> CSC Invokedll.cs Generate Invokedll.exe, you can execute this file. The above is the whole process of C-Sharp calling standard dynamic library. It has always been very simple. I have never wanted to write. I happened that I met this friend today. I wrote it. Down.

转载请注明原文地址:https://www.9cbs.com/read-88116.html

New Post(0)