C# vb.net 分别引用C++编译DLL
生活随笔
收集整理的這篇文章主要介紹了
C# vb.net 分别引用C++编译DLL
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
\\Form1.Designer.cs
using System.Runtime.InteropServices;//引入dll文件中的函數
namespace WindowsApplication20130113
{
partial class Form1{[DllImport("CommApi.dll")]private static extern bool SetSerialCom(Int32 nPort, Int32 lBaudRate, Int32 DataBit, Int32 lParity, Int32 lStopbit);[DllImport("CommApi.dll")]private static extern Int32 ReadCom(byte[] TheFirstAddrofInputBuff, Int32 lSizeofByte, Int32 msWaitTime);[DllImport("CommApi.dll")]private static extern bool WriteCom(byte[] TheFirstAddrofInputBuff, Int32 lSizeofByte);[DllImport("CommApi.dll")]private static extern int CloseSerialPort();\\其他代碼}
}
using System.Runtime.InteropServices;//引入dll文件中的函數
namespace WindowsApplication20130113
{
partial class Form1{[DllImport("CommApi.dll")]private static extern bool SetSerialCom(Int32 nPort, Int32 lBaudRate, Int32 DataBit, Int32 lParity, Int32 lStopbit);[DllImport("CommApi.dll")]private static extern Int32 ReadCom(byte[] TheFirstAddrofInputBuff, Int32 lSizeofByte, Int32 msWaitTime);[DllImport("CommApi.dll")]private static extern bool WriteCom(byte[] TheFirstAddrofInputBuff, Int32 lSizeofByte);[DllImport("CommApi.dll")]private static extern int CloseSerialPort();\\其他代碼}
}
然后便可以在源代碼中引用SetSerialCom等函數。
vb.net
'命名空間 Imports System.Runtime.InteropServicesPublic Class Form1Inherits FormPrivate Declare Function SetSerialCom Lib "commapi" (ByVal nPort As Int32, ByVal BaudRate As Int32, ByVal DataBit As Int32, ByVal Parity As Int32, ByVal Stopbit As Int32) As BooleanPrivate Declare Function ReadCom Lib "commapi" (ByRef TheFirstAddrofInputBuff As Byte, ByVal SizeofByte As Int32, ByVal msWaitTime As Int32) As Int32Private Declare Function WriteCom Lib "commapi" (ByRef TheFirstAddrofOutputBuff As Byte, ByVal SizeofByte As Int32) As BooleanPrivate Declare Sub CloseSerialPort Lib "commapi" ()注意:vb.net中的ByRef:傳地址 (因為vb.net數組一般是用首地址傳遞),ByVal:傳值;
?
轉載于:https://www.cnblogs.com/jonson1126/archive/2013/01/18/2865908.html
總結
以上是生活随笔為你收集整理的C# vb.net 分别引用C++编译DLL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为MateBook E 二合一笔记本助
- 下一篇: c# char unsigned_dll