[RESOLVED] Getting a type from a DLL
In a Form I have
VB Code:
Private Type TypeDiskDrive
InterfaceType As String
Partitions As Long
Size As Currency
Status As String
End Type
Private DiskDrives As CDiskDrives
Private ArrayDiskDrives() As TypeDiskDrive
Private Sub Form_Load()
Set DiskDrives = New CDiskDrives
Modules.AddItem DiskDrives.Name
[COLOR=Red]ArrayDiskDrives = DiskDrives.GetTypeArray[/COLOR]
End Sub
and in a DLL I have
VB Code:
Option Explicit
Type TypeDiskDrive
InterfaceType As String
Partitions As Long
Size As Currency
Status As String
End Type
Public DiskDrives() As TypeDiskDrive
Sub Main()
Debug.Print "MDiskDrives->Main();"
End Sub
Public Sub Win32_DiskDrive()
Debug.Print "MDiskDrives->Win32_DiskDrive();"
Dim CIMV2 As Object
Dim Result As Object
Dim Row As Object
Dim i As Long
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Partitions, Size, Status FROM Win32_DiskDrive", "WQL", &H10 + &H20)
[COLOR=Blue]ReDim DiskDrives(111) As TypeDiskDrive[/COLOR]
For Each Row In Result
DiskDrives(i).InterfaceType = Row.InterfaceType
DiskDrives(i).Partitions = Row.Partitions
DiskDrives(i).Size = Row.Size
DiskDrives(i).Status = Row.Status
i = i + 1
Next
End Sub
Public Function GetTypeArray() As String()
GetTypeArray = DiskDrives
End Function
The red line in the Form code errors: Can't assign to array. :(
Also I am still looking for what I should be putting in place of 111 in the blue line in DLL code.
Re: Getting a type from a DLL
You have a number of problems here. 1) You are declaring TypeDiskDrive in both your DLL and your EXE. Just make TypeDiskDrive public in the DLL.
Then do this instead of making a local type called TypeDiskDrive
VB Code:
Private ArrayDiskDrives() As CDiskDrives.TypeDiskDrive
You are also returning an array type of String into an array type of TypeDiskDrive.
I personally like to pass arrays by reference. Try this code in your DLL instead.
VB Code:
Public Sub GetTypeArray(ByRef PassedArray() As TypeDiskDrive)
PassedArray = DiskDrives
End Function
Then call it like this
VB Code:
DiskDrives.GetTypeArray(ArrayDiskDrives)
That will fill your array for you. More efficent too because you aren't creating two copies of the array.
Re: Getting a type from a DLL
Very good points, isn't default ByRef?
Re: Getting a type from a DLL
Ok, now in the DLL I have
VB Code:
Public Type TypeDiskDrive
InterfaceType As String
Partitions As Long
Size As Currency
Status As String
End Type
Public Sub GetTypeArray(ByRef PassedArray() As TypeDiskDrive)
Dim CIMV2, Result, Row As Object
Dim i As Long
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Partitions, Size, Status FROM Win32_DiskDrive", "WQL", &H10 + &H20)
Dim DiskDrives() As TypeDiskDrive
For Each Row In Result
DiskDrives(i).InterfaceType = Row.InterfaceType
DiskDrives(i).Partitions = Row.Partitions
DiskDrives(i).Size = Row.Size
DiskDrives(i).Status = Row.Status
i = i + 1
Next
PassedArray = DiskDrives
End Sub
and in the EXE...
VB Code:
Dim DiskDrives As CDiskDrives
[COLOR=red]Private Sub Form_Load()[/COLOR]
DiskDrives = New CDiskDrives
Dim ArrayDiskDrives() As DiskDrives.TypeDiskDrive
DiskDrives.GetTypeArray ArrayDiskDrives
End Sub
and it errors: User-defined type not defined.
Re: Getting a type from a DLL
I was talking to someone on MSN about this and he seems to think you can't access types defined in a DLL. :(
And when I type in "DiskDrives." only GetTypeArray pops up. :s
Re: Getting a type from a DLL
I don't get what you want to do. Scriptomatic2 lets you get info from anywhere , so I can't see the use for a .dll
Re: Getting a type from a DLL
So my program can read the ./Dll/ folder, loading all "modules" then build the GUI based on what was loaded.
There is no point to my program other then to learn. :/
Re: Getting a type from a DLL
Well, you should download Scriptomatic2, and learn how it works. They have a new version called EzScriptomatic2, or something like that. It is supposed to work with AD.
Re: Getting a type from a DLL
lol I have Scriptomatic... and I don't see how it would help?
Re: [RESOLVED] Getting a type from a DLL
Quote:
So my program can read the ./Dll/ folder, loading all "modules" then build the GUI based on what was loaded.
There is no point to my program other then to learn. :/
look
http://www.vbforums.com/showthread.php?t=424568