Results 1 to 10 of 10

Thread: [RESOLVED] Getting a type from a DLL

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    [RESOLVED] Getting a type from a DLL

    In a Form I have
    VB Code:
    1. Private Type TypeDiskDrive
    2.     InterfaceType As String
    3.     Partitions As Long
    4.     Size As Currency
    5.     Status As String
    6. End Type
    7. Private DiskDrives As CDiskDrives
    8. Private ArrayDiskDrives() As TypeDiskDrive
    9. Private Sub Form_Load()
    10.     Set DiskDrives = New CDiskDrives
    11.     Modules.AddItem DiskDrives.Name
    12.     [COLOR=Red]ArrayDiskDrives = DiskDrives.GetTypeArray[/COLOR]
    13. End Sub
    and in a DLL I have
    VB Code:
    1. Option Explicit
    2. Type TypeDiskDrive
    3.     InterfaceType As String
    4.     Partitions As Long
    5.     Size As Currency
    6.     Status As String
    7. End Type
    8. Public DiskDrives() As TypeDiskDrive
    9. Sub Main()
    10.    Debug.Print "MDiskDrives->Main();"
    11. End Sub
    12. Public Sub Win32_DiskDrive()
    13.     Debug.Print "MDiskDrives->Win32_DiskDrive();"
    14.     Dim CIMV2 As Object
    15.     Dim Result As Object
    16.     Dim Row As Object
    17.     Dim i As Long
    18.     Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
    19.     Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Partitions, Size, Status FROM Win32_DiskDrive", "WQL", &H10 + &H20)
    20.     [COLOR=Blue]ReDim DiskDrives(111) As TypeDiskDrive[/COLOR]
    21.     For Each Row In Result
    22.         DiskDrives(i).InterfaceType = Row.InterfaceType
    23.         DiskDrives(i).Partitions = Row.Partitions
    24.         DiskDrives(i).Size = Row.Size
    25.         DiskDrives(i).Status = Row.Status
    26.         i = i + 1
    27.     Next
    28. End Sub
    29. Public Function GetTypeArray() As String()
    30.     GetTypeArray = DiskDrives
    31. 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.

  2. #2
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    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:
    1. 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:
    1. Public Sub GetTypeArray(ByRef PassedArray() As TypeDiskDrive)
    2.     PassedArray = DiskDrives
    3. End Function

    Then call it like this
    VB Code:
    1. DiskDrives.GetTypeArray(ArrayDiskDrives)

    That will fill your array for you. More efficent too because you aren't creating two copies of the array.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: Getting a type from a DLL

    Very good points, isn't default ByRef?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: Getting a type from a DLL

    Ok, now in the DLL I have
    VB Code:
    1. Public Type TypeDiskDrive
    2.     InterfaceType As String
    3.     Partitions As Long
    4.     Size As Currency
    5.     Status As String
    6. End Type
    7. Public Sub GetTypeArray(ByRef PassedArray() As TypeDiskDrive)
    8.     Dim CIMV2, Result, Row As Object
    9.     Dim i As Long
    10.     Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
    11.     Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Partitions, Size, Status FROM Win32_DiskDrive", "WQL", &H10 + &H20)
    12.     Dim DiskDrives() As TypeDiskDrive
    13.     For Each Row In Result
    14.         DiskDrives(i).InterfaceType = Row.InterfaceType
    15.         DiskDrives(i).Partitions = Row.Partitions
    16.         DiskDrives(i).Size = Row.Size
    17.         DiskDrives(i).Status = Row.Status
    18.         i = i + 1
    19.     Next
    20.     PassedArray = DiskDrives
    21. End Sub
    and in the EXE...
    VB Code:
    1. Dim DiskDrives As CDiskDrives
    2. [COLOR=red]Private Sub Form_Load()[/COLOR]
    3.     DiskDrives = New CDiskDrives
    4.     Dim ArrayDiskDrives() As DiskDrives.TypeDiskDrive
    5.     DiskDrives.GetTypeArray ArrayDiskDrives
    6. End Sub
    and it errors: User-defined type not defined.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    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

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    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. :/

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: Getting a type from a DLL

    lol I have Scriptomatic... and I don't see how it would help?

  10. #10
    New Member
    Join Date
    Oct 2005
    Posts
    11

    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
  •  



Click Here to Expand Forum to Full Width