Results 1 to 16 of 16

Thread: [RESOLVED] could anyone guide me on this byref arguement type mismatch error?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Resolved [RESOLVED] could anyone guide me on this byref arguement type mismatch error?

    sorry for disturbing whoever who viewing my question now,i was being asked to build an wrapper in c++ and connect with vb6. the issue i currently facing now was im using the code as below as the code for the form
    Code:
    Code had been deleted due  question solved
    and this would be the code i write in the header file in c++
    Code:
    Code had been deleted due  question solved
    really appreciate for the person which waste their time on looking my question and i really hope i could get some guide on how should i fix it or where is the part which i doing wrong. Thank you.
    Last edited by Kobayashi; Jan 21st, 2021 at 09:45 AM. Reason: make the question more complete

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,415

    Re: could anyone guide me on this byref arguement type mismatch error?

    Do you have the Header-Files?
    What i could find, the ConnectDevice-Function takes 2 Long-Parameters, you have 3 in your Declare.....
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    Hi sir, i had re-edit the question and putting in the code which i use in header file and fixed the issue which u had mentioned as , after that, i would still facing the issue in Disconnect-Function which is when the moment i run the disconnect function, it would show up
    Code:
     complile error:ByRef argument type mismatch
    this error and i had no clue on how to fix it. Thank you

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,415

    Re: could anyone guide me on this byref arguement type mismatch error?

    Since it's a pointer to a structure, i'd try ByVal sRespData As Long in your Declare, and use VarPtr-Function to get the Pointer to the UDT
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: could anyone guide me on this byref arguement type mismatch error?

    Quote Originally Posted by Zvoni View Post
    Since it's a pointer to a structure, i'd try ByVal sRespData As Long in your Declare, and use VarPtr-Function to get the Pointer to the UDT
    That would work too.

    However, as far as I know, passing the UDT by reference should work as well. My first instinct is that the sResp is not declared correctly or declared at all. The code he posted doesn't show him declaring sResp at all.

    EDIT:

    Nevermind. He did declare it.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,415

    Re: could anyone guide me on this byref arguement type mismatch error?

    But he does.
    Second Code-Block in the first post
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: could anyone guide me on this byref arguement type mismatch error?

    Well his code looks correct. However, this error has a very specific cause:-
    Code:
    '
    Private Type MyType
        MyName As String
        MyAge As Integer
    End Type
    
    Private Sub Form_Load()
        Dim myUDT As MyType
        Dim myBool As Boolean
        
        
        'Generates ByRef Argurment type mismatch
        CheckIt myBool
    
    End Sub
    
    
    Private Sub CheckIt(ByRef t As MyType)
    
    End Sub
    The above code generates the same error because I tried to pass a Boolean type when a function expects a UDT. The same thing must be happening in OP's code somehow.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: could anyone guide me on this byref arguement type mismatch error?

    Wait, I think I know what the cause is. He uses Dim to declare sResp in his module. I'm not entirely sure but I believe Dim defaults to Private which means his Form code is not actually seeing sResp in the module but is auto-defining a different one which will default to Variant as it's type. If he places Option Explicit at the top of his Form code, the compiler should complain about sResp not being defined.

    @Op

    To fix, change:-
    Code:
    Dim sResp As sRespData
    To
    Code:
    Public sResp As sRespData
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,415

    Re: could anyone guide me on this byref arguement type mismatch error?

    Damn! Missed that one.
    Confusing: He has Option Explicit in his Module, where he declares sResp and the API's, but i agree: Probably the Dim vs. Public (Global Variable....bleh)

    EDIT: And it should be "Public Type sRespData"
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: could anyone guide me on this byref arguement type mismatch error?

    Yea, in this case the compiler was very clear on what the problem was so I had an idea where to look.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    is that means all these error was causing by option explicit and dim was set as private as default
    so what i need to do would be change
    Code:
    dim sResp As sRespData
    into
    Code:
    public sResp As sRespData
    .appreciate all your help and i will be back if the solution was not working. thank you thank you . really appreciate all ur help and willing to wasting time on my question. Thank you once again.
    Last edited by Kobayashi; Jan 19th, 2021 at 09:10 PM.

  12. #12

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    really really appreciate u both, its working, its working, love u both sooo muchhhh

  13. #13

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    but here comes another issue which is how can i pass the return handler from MTK_ConnectDevice to MTK_DisconnectDevice. Example after i was use the connectDevice function, then when i try to disconnect it, i would require to put in the return handler value of MTK_ConnectDevice in to the MTK_DisconnectDevice paramater but i got abit clueless on how to do it, from what i google search i was require to use the address of function in order to use the handler, but tbh i got no clue on the correct method to implement this function. according from my google search, the method for me to use the address of would be
    Code:
    lngResult = MTK_DisconnectDevice(AddressOf MTK_ConnectDevice,sResp)
    but whenever i was using this line, i keep getting the error of invalid use of addressof operator, may i know what is this issue? and really sorry for causing any possible trouble to you. thank you

  14. #14
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: could anyone guide me on this byref arguement type mismatch error?

    Quote Originally Posted by Kobayashi View Post
    but here comes another issue which is how can i pass the return handler from MTK_ConnectDevice to MTK_DisconnectDevice. Example after i was use the connectDevice function, then when i try to disconnect it, i would require to put in the return handler value of MTK_ConnectDevice in to the MTK_DisconnectDevice
    It may just want the return value of MTK_ConnectDevice. That function returns a 64 bit integer according to the C code you posted. The only problem I see here is that VB6 doesn't have a 64 bit Integer type.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  15. #15

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    Hi Niya, is that means since it may just want the return value of the MTK_ConnectDevice, so i would need to declare a global variable and assign the global variable, then i put the assigned globalVariable as the return value of the MTK_ConnectDevice, then i will be able to get the return value of the MTK_ConnectDevice, then the next things i would need to do would be pass in the globalVariable in to the MTK_DisconnectDevice function parameter as the code below?
    Code:
    Code had been deleted due solved
    Is this the correct method to do so? but according to ur VB6 doesn't have a 64 bit Integer type. Is that mean i would need to somesort like doing convertion for my return value into 32bit 1st, then only pass into globalVariable? Due currently when im using the code above, the same error which occur on my sResp was coming out again which is Byref arguement Type Mismatch ,it just this time its not on sResp anymore but was on the g_reader which hold the return value of MTK_ConnectDevice. Sorry for asking so many question due i really just started using vb6 so i got abit clueless on what am i actually doing... and really appreciate u all who willing to spend time and answering my question....Thank you
    Last edited by Kobayashi; Jan 21st, 2021 at 09:41 AM.

  16. #16

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    12

    Re: could anyone guide me on this byref arguement type mismatch error?

    nvm, i had figure out what is the actual issue already, i wouldn't need to use globalVariable or anything else since this vb6 main function was used to act as a middle man and call the c++ only and for the c++ part, i had already pass the data into disconnect, thus for this part, i would just need to do as the code below then the problem solve and no more issue pop out.

    Code:
    code had been deleted
    Thank you for everyone who helping me figure out where is the problem and the method to solve it. Really appreciate for all ur help. Thank you
    Last edited by Kobayashi; Jan 21st, 2021 at 09:41 AM.

Tags for this Thread

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