|
-
Nov 5th, 2005, 04:38 PM
#1
Thread Starter
Hyperactive Member
[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.
Last edited by frozen; Nov 8th, 2005 at 09:40 PM.
-
Nov 5th, 2005, 05:43 PM
#2
Hyperactive Member
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.
-
Nov 5th, 2005, 08:49 PM
#3
Thread Starter
Hyperactive Member
Re: Getting a type from a DLL
Very good points, isn't default ByRef?
-
Nov 5th, 2005, 09:25 PM
#4
Thread Starter
Hyperactive Member
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.
-
Nov 5th, 2005, 10:16 PM
#5
Thread Starter
Hyperactive Member
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
-
Nov 5th, 2005, 10:18 PM
#6
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
-
Nov 5th, 2005, 10:33 PM
#7
Thread Starter
Hyperactive Member
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. :/
-
Nov 5th, 2005, 10:46 PM
#8
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.
-
Nov 5th, 2005, 11:09 PM
#9
Thread Starter
Hyperactive Member
Re: Getting a type from a DLL
lol I have Scriptomatic... and I don't see how it would help?
-
Aug 3rd, 2008, 11:04 AM
#10
New Member
Re: [RESOLVED] 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. :/
look
http://www.vbforums.com/showthread.php?t=424568
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|