Results 1 to 4 of 4

Thread: Automation types not supported in VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    What does this mean? Why does this happen?
    I know when: It happens when I use CopyMemory() function and when I want to assign variable, returned by CopyMemory to my function (string variable).
    Here's the code I use:
    [code]
    function MyFunction() As String

    hLock = LockResource(hLoad)
    hSize = SizeofResource(hInst, hFind)

    ReDim b(0 To lsize) As String
    CopyMemory b(0), hLock, hSize

    FreeLibrary hInst
    MyFunction = b

    End function
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Try this

    Change your line:

    ReDim b(0 To lsize) As String

    to:

    ReDim b(0 To lsize) As Byte

    Then I know the CopyMemory will work. Can't vouch for the rest because I never play with DLL's at that level.

    The trickle down effect of this is of course that you would have to change the return type of the function and then you probably will have more headaches.

    So to convert a byte array to a string, I do the following: (There are no doubt better ways, so if someone else knows of one post a reply too!)

    Code:
    ...
    Public Declare Sub CopyMemory Lib "kernel32" Alias _ "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, _
    ByVal cbCopy As Long)
    ...
      Dim sTmp as String
      Dim lVal,lLen as Long
    
      sTmp = String$(lLen + 1, Chr$(0))
      CopyMemory ByVal sTmp, ByVal lVal, lLen 
      
      Dim nullPos As Integer
      nullPos = InStr(1, sTmp, Chr$(0))
      If nullPos > 0 Then sTmp = Left(sTmp, nullPos - 1)
    ...
    I hope this helps.

    Regards
    Paul Lewis

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    The thing I was loading from dll was string, but declared variable was byte so that caused error. So I changed it to string and it worked.
    I'll try your example and tell you if it worked.
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    I tried it and it works.

    THANKS, PAUL!!!
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

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