查看: 852|回复: 2
|
Unmanaged DLL File
[复制链接]
|
|
小弟現在再 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 呢? |
|
|
|
|
|
|
|

楼主 |
发表于 15-3-2006 02:34 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 16-3-2006 09:10 AM
|
显示全部楼层
这里的人,很多都有工作和自己的家庭,即使懂你的问题,也没办法立刻帮你。
1,对,我试过可以这样做。另一个方式可以用Declare来做。
2,据我所知,如果是pointer to string,你可以在vb里直接用string来pass它parameter。不过,vb里没有pointer这种东西,所以遇到不同种类的type就可能需要用不同的方式来做。
以下是我调用User32的MessageBox的方式。
- int MessageBox(
- LPCTSTR lpszText,
- LPCTSTR lpszCaption = _T( "" ),
- UINT nType = MB_OK);
复制代码
- Imports System.Runtime.InteropServices 'Used for DllImport
- Imports System.Runtime.InteropServices.Marshal 'Used for StringToBSTR
- Module Module1
- <DllImport("user32.dll")> Public Function MessageBox( _
- ByVal Hwnd As Integer, _
- ByVal text As String, _
- ByVal Caption As String, _
- ByVal ype As Integer) As Integer
- End Function
- 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
- 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
- Sub main()
- Dim PtrString1 As IntPtr
- Dim PtrString2 As IntPtr
- MBox(0, "test1", "title1", 0)
- MessageBox(0, "test2", "title2", 0)
- PtrString1 = StringToBSTR("test3")
- PtrString2 = StringToBSTR("title3")
- MBox(0, PtrString1, PtrString2, 0)
- End Sub
- End Module
复制代码 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|