-
Jan 18th, 2021, 03:52 AM
#1
Thread Starter
New Member
[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
-
Jan 18th, 2021, 05:52 AM
#2
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
-
Jan 18th, 2021, 08:35 PM
#3
Thread Starter
New Member
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
-
Jan 19th, 2021, 02:16 AM
#4
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
-
Jan 19th, 2021, 08:04 AM
#5
Re: could anyone guide me on this byref arguement type mismatch error?
Originally Posted by Zvoni
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.
-
Jan 19th, 2021, 08:06 AM
#6
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
-
Jan 19th, 2021, 08:11 AM
#7
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.
-
Jan 19th, 2021, 08:20 AM
#8
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
-
Jan 19th, 2021, 08:40 AM
#9
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
-
Jan 19th, 2021, 08:57 AM
#10
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.
-
Jan 19th, 2021, 07:00 PM
#11
Thread Starter
New Member
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.
-
Jan 19th, 2021, 07:07 PM
#12
Thread Starter
New Member
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
-
Jan 19th, 2021, 08:46 PM
#13
Thread Starter
New Member
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
-
Jan 19th, 2021, 09:29 PM
#14
Re: could anyone guide me on this byref arguement type mismatch error?
Originally Posted by Kobayashi
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.
-
Jan 19th, 2021, 10:26 PM
#15
Thread Starter
New Member
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.
-
Jan 20th, 2021, 12:05 AM
#16
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|