佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 852|回复: 2

Unmanaged DLL File

[复制链接]
发表于 14-3-2006 11:27 PM | 显示全部楼层 |阅读模式
小弟現在再 Develop 一個 Access Control System,必須要用 VB.NET 來 Control 一些 Hardware,但有些東東不明百,希望有人能幫我解答,謝謝.

1)如何 Include Unmanaged DLL File 呢? 可否用 <DLLImport("DLLName,dll")> Public Shared Function ...... ? 是不是只要 Import 過後就馬上能用?

2)以下是某個 Function (the one which included in the statement above) 的 Structure:
int GetDLLVersion(Char *data, int datasize)

據大家所知, *data 會 return value, 但我要如何 store 這個 value 進 VB.NET 的 Variable 呢?
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 15-3-2006 02:34 PM | 显示全部楼层
Nobody can help me?
回复

使用道具 举报

发表于 16-3-2006 09:10 AM | 显示全部楼层
这里的人,很多都有工作和自己的家庭,即使懂你的问题,也没办法立刻帮你。

1,对,我试过可以这样做。另一个方式可以用Declare来做。

2,据我所知,如果是pointer to string,你可以在vb里直接用string来pass它parameter。不过,vb里没有pointer这种东西,所以遇到不同种类的type就可能需要用不同的方式来做。

以下是我调用User32的MessageBox的方式。

  1. int MessageBox(
  2. LPCTSTR lpszText,
  3. LPCTSTR lpszCaption = _T( "" ),
  4. UINT nType = MB_OK);
复制代码


  1. Imports System.Runtime.InteropServices    'Used for DllImport
  2. Imports System.Runtime.InteropServices.Marshal   'Used for StringToBSTR

  3. Module Module1
  4.     <DllImport("user32.dll")> Public Function MessageBox( _
  5.     ByVal Hwnd As Integer, _
  6.     ByVal text As String, _
  7.     ByVal Caption As String, _
  8.     ByVal ype As Integer) As Integer

  9.     End Function


  10.     Declare Auto Function MBox Lib "User32.dll" Alias "MessageBox" (ByVal hwnd As Int32, ByVal text As String, ByVal caption As String, ByVal uType As Int32) As Int32

  11.     Declare Auto Function MBox Lib "User32.dll" Alias "MessageBox" (ByVal hwnd As Int32, ByVal ptext As IntPtr, ByVal pcaption As IntPtr, ByVal uType As Int32) As Int32

  12.     Sub main()

  13.         Dim PtrString1 As IntPtr
  14.         Dim PtrString2 As IntPtr

  15.         MBox(0, "test1", "title1", 0)

  16.         MessageBox(0, "test2", "title2", 0)

  17.         PtrString1 = StringToBSTR("test3")
  18.         PtrString2 = StringToBSTR("title3")
  19.         MBox(0, PtrString1, PtrString2, 0)
  20.     End Sub
  21. End Module
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 29-7-2025 11:06 PM , Processed in 0.118594 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表