Results 1 to 10 of 10

Thread: User-Defined type may not be passed ByVal

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    User-Defined type may not be passed ByVal

    Argh can not figure this out. Program works fine until it hits
    Code:
    hFile = mmioOpen(File, ByVal 0&, MMIO_READ)
    which is under
    Code:
    Public Sub CreateDSBFromWaveFile(ds As IDirectSound, ByVal File As String, dsb As IDirectSoundBuffer)
    and thats when I get hit with a
    Code:
    compile error:
    User-Defined type may not be passed ByVal
    And it highlights the 0& in that string.

    I think the main code you have to see for this is
    Code:
    Option Explicit
    Declare Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, lpmmioinfo As mmioinfo, ByVal dwOpenFlags As Long) As Long
    Public Const MMIO_READ = &H0
    Declare Function mmioRead Lib "winmm.dll" (ByVal hmmio As Long, ByVal pch As Long, ByVal cch As Long) As Long
    Dim hFile As Long
    hFile = mmioOpen(File, ByVal 0&, MMIO_READ)
    I guess I just don't understand the ByVal enough to understand why the 0& is not working. I'm patching code that was already working before, and a lot got erased some how, so I know it SHOULD work, I just don't know what I have to do to patch it. I'm sure I'm leaving out something really obvious.

    ANY help would be greatly appreciated, if you want me to paste the whole pages of code up to that point I'll do that too. Or if you need to see something else let me know!

    It's driving me crazy!

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: User-Defined type may not be passed ByVal

    Change mmioOpen from:

    Declare Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, lpmmioinfo As mmioinfo, ByVal dwOpenFlags As Long) As Long

    to:

    Declare Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, lpmmioinfo As Any, ByVal dwOpenFlags As Long) As Long

    This allows you to pass ByVal 0& (ie. a null pointer) and it also allows you to pass the user defined type (ByRef).

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: User-Defined type may not be passed ByVal

    The problem is as stated by the error message, you can't pass a UDT(user defined type) ByVal. In your case that udt is called mmioinfo, and the actual value you are trying to pass ByVal is "0&". Even in the declaration of that "mmioOpen" this argument is NOT passed ByVal as opposed to all others.
    Did you try to pass the argument ByRef (you can just delete the ByVal since ByRef is the default)?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    Re: User-Defined type may not be passed ByVal

    Thank you both very much for your help.

    Merri, I tried what you said and it worked and that seems to be working fine now. But I don't know if it affected something else now, because now I get
    Code:
    a compile error: Type Mismatch  on the 'WaveF' on the line
    mmioRead hFile, WaveF, Detail.ckSize
    I don't know if thats because I made those changes or because of my
    Code:
    hFile = mmioOpen(File, ByVal 0&, MMIO_READ)
    line.

    And Opus you're saying I can just do away with the ByVal 0& all together? Just remove it right out?

    Thanks again a lot guys. Slowly but surely I'll figure out what seems to be the problem.

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: User-Defined type may not be passed ByVal

    What is WaveF? It's supposed to be a Long according to your API declaration.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    Re: User-Defined type may not be passed ByVal

    sorry about that!

    Code:
    Type WAVEFORMAT
           wFormatTag As Integer
           nChannels As Integer
            nSamplesPerSec As Long
          nAvgBytesPerSec As Long
          nBlockAlign As Integer
            wBitsPerSample As Integer
           cbSize As Integer
    End Type
    
    Dim WaveF As WAVEFORMAT

  7. #7
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: User-Defined type may not be passed ByVal

    Since WaveF is a WAVEFORMAT type, you'll generate that compile error. Your mmioRead declaration,

    Code:
    Declare Function mmioRead Lib "winmm.dll" _
      (ByVal hmmio As Long, ByVal pch As Long, ByVal cch As Long) As Long
    wants you to pass a Long for the second argument, while you're passing the WAVEFORMAT UDT (user defined type). You're making an error in logic somewhere. I'm not familiar with these APIs so I can't say precisely what that error is. Maybe you should look at an example like the one linked from this page.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    Re: User-Defined type may not be passed ByVal

    I actually patched this code so far with a lot of the API info I read off of that link you gave me jemidiah. So the
    Code:
    Declare Function mmioRead Lib "winmm.dll" _
      (ByVal hmmio As Long, ByVal pch As Long, ByVal cch As Long) As Long
    is actually something I put in there to try and get it to work that I retrieved from that link. On the other hand the
    Code:
    mmioRead hFile, WaveF, Detail.ckSize
    code was originally in the program so I know that is supposed to be there. What do you think I should change in the declare statement so that the WaveF can be passed successfully? Change the 'Long' in ByVal pch As Long to something else I'm assuming?

    Thank you so much.

  9. #9
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: User-Defined type may not be passed ByVal

    According to AllAPI.net "mmioread" has to be called using these parameters: "(ByVal hmmio As Long, ByVal pch As String, ByVal cch As Long) "
    with "pch" "Address of a buffer to contain the data read from the file"
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: User-Defined type may not be passed ByVal

    Hmm... I'm gonna say "(ByVal hmmio As Long, ByVal pch As String, ByVal cch As Long)" was a typo. It doesn't make sense to pass an address using a string, and the example project uses the OP's declaration (Long) instead.

    The example project uses
    Code:
    rc = mmioRead(hmmioIn, wavhdr.lpData, bufferSize)
    where hmmioIn was the file handle (a Long) obtained from an earlier mmioOpen call, bufferSize was a Long also calculated earlier, and wavhdr is a WAVEHDR UDT (*not* a WAVEFORMAT UDT). The WAVEHDR UDT contains an lpData pointer (a Long in VB6). The wavhdr variable is itself passed in to the WindowProc function as an argument. WindowProc is subclassed and checks for MM_WOM_DONE messages. The second argument, which for other subclassing uses would be the ByVal Long lParam, is instead the ByRef wavhdr WAVEHDR. So, you should have wavhdr available for your mmioRead call, assuming you're subclassing like you're apparently supposed to be.

    Again, I've never used this API and I'm making no attempt at figuring it out in particular. These are generic observations pertinent to any API call/subclassing/pointer passing.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

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