C# 中引用vb編寫的DLL

來源:互聯網
上載者:User

 Private Declare Sub Make Lib "makebar.dll" _
(ucData As Byte, ByVal nLen As Long, ByVal szFileName As String, ByVal nClumn As Long, ByVal nErr As Long, ByVal nHLRatio As Long)

Dim a() As Byte
a = StrConv(Text1.Text, vbFromUnicode)
Make a(0), UBound(a) - LBound(a) + 1, "abc.bmp", CLng(Text2.Text), CLng(Text3.Text), CLng(Text4.Text)

C#
[DllImport("makebar.dll", EntryPoint="Make")]
private static extern void Make(ref byte ucData, long nLen, string szFileName, long nClumn, long nErr, long nHLRatio);

byte[] a = System.Text.Encoding.UTF8.GetBytes(Text1.Text);

Make(ref a[0], a.Length, "abc.bmp", long.Parse(Text2.Text), long.Parse(Text3.Text), long.Parse(Text4.Text);

其中對於那個ref參數我不是很確定。舊VB裡,不寫ByVal就是ByRef,但是好像在C#裡面ref只可以傳遞簡單的變數,例如a,而"a[0]"是沒辦法ref傳的。如果過程之後a[0]不需要改變,那就去掉那兩個ref就可以了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.