C-Sharp call standard dynamic library

zhaozj2021-02-17  56

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.8447 Copyright (C) Microsoft Corp 1992-1998. All Rights Reserved.

/out:mylib.dll/dll/implib:mylib.libmylib.obj createing library mylib.lib and object mylib.exp

Confident, there is more output, indicating that the compilation successfully generates a dynamic library.

2. Write the C-Sharp program to call this dynamic library Using system; use system.Runtime.InteropServices; // This is the package to be introduced when using DLLIMPORT

Public class invokedll {["" "", "" "" " 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 will generate invokedll.exe, you can execute this file. The above is the whole process of C-Sharp calling standard dynamic library. It is very simple. I have never wanted to write. I happened to meet this friend today. If you write it, you can contact ZlyPerson@163.net

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

New Post(0)