For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > September 2004 > USB function , ByRef argument type mismatch









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author USB function , ByRef argument type mismatch
boki

2004-09-29, 3:55 pm

Dear All,

I meet a problem when I compile my USB code, and I get this error
message

============================
Compile error:
ByRef argument type mismatch
============================

This problem happen at

========================================
==========
Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
....
Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0,
NameBuffer.Length, 260, BytesReturned&, 0)

^^^^^^
cursor stops at at "Length"
....
....
========================================
==========

It is the problem "ByRef argument type mismatch"

Set ByValue?


Best regards,
Boki.
Charlie

2004-09-29, 3:55 pm

Without see all of your code it's a crap-shoot for me, but I'd guess that
NameBuffer.Length is a Long (or Integer), and the arg position where you are
using it the function is expecting a string, not a Long (or Int). Did you
mean to use NameBuffer.Name? Or just NameBuffer or something like that?

P.S. if you ever get tired of typing all those dollar signs and ampersands
you might want to learn to Dim your variables instead!


"boki" wrote:

> Dear All,
>
> I meet a problem when I compile my USB code, and I get this error
> message
>
> ============================
> Compile error:
> ByRef argument type mismatch
> ============================
>
> This problem happen at
>
> ========================================
==========
> Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
> ....
> Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0,
> NameBuffer.Length, 260, BytesReturned&, 0)
>
> ^^^^^^
> cursor stops at at "Length"
> ....
> ....
> ========================================
==========
>
> It is the problem "ByRef argument type mismatch"
>
> Set ByValue?
>
>
> Best regards,
> Boki.
>

Randy Birch

2004-09-29, 9:27 pm

See if the declaration and calling syntax for DeviceIoControl from
http://vbnet.mvps.org/code/disk/deviodriveinfo.htm helps. Without your
declare and exact code, we can't really guess.

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"boki" <bokiteam@ms21.hinet.net> wrote in message
news:4c3c095a.0409290840.63691a5a@posting.google.com...
: Dear All,
:
: I meet a problem when I compile my USB code, and I get this error
: message
:
: ============================
: Compile error:
: ByRef argument type mismatch
: ============================
:
: This problem happen at
:
: ========================================
==========
: Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
: ...
: Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0,
: NameBuffer.Length, 260, BytesReturned&, 0)
:
: ^^^^^^
: cursor stops at at "Length"
: ...
: ...
: ========================================
==========
:
: It is the problem "ByRef argument type mismatch"
:
: Set ByValue?
:
:
: Best regards,
: Boki.

boki

2004-09-29, 9:27 pm

Dear All,
This is my declaration about CreatFile:

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&,
lpSecurityAttributes&, _
ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal
hTemplateFile&) As Long

Thank you very much for your help.

Best regards,
Boki.

"Charlie" <Charlie@discussions.microsoft.com> wrote in message news:<97DA6951-68F7-4AE7-B398-86598A62B7BC@microsoft.com>...[color=darkred]
> Without see all of your code it's a crap-shoot for me, but I'd guess that
> NameBuffer.Length is a Long (or Integer), and the arg position where you are
> using it the function is expecting a string, not a Long (or Int). Did you
> mean to use NameBuffer.Name? Or just NameBuffer or something like that?
>
> P.S. if you ever get tired of typing all those dollar signs and ampersands
> you might want to learn to Dim your variables instead!
>
>
> "boki" wrote:
>
Randy Birch

2004-09-30, 4:44 am

You indicated you had a problem with DeviceIoControl, not CreateFile. Post
your declare for DeviceIoControl, as well as all the code - including the
Dim's - for the local variables in the routine causing the problem. Also
provide, from your exact code, precisely what NameBuffer.Length is.

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"boki" <bokiteam@ms21.hinet.net> wrote in message
news:4c3c095a.0409291706.5125b04d@posting.google.com...
: Dear All,
: This is my declaration about CreatFile:
:
: Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
: (ByVal lpFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&,
: lpSecurityAttributes&, _
: ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal
: hTemplateFile&) As Long
:
: Thank you very much for your help.
:
: Best regards,
: Boki.
:
: "Charlie" <Charlie@discussions.microsoft.com> wrote in message
news:<97DA6951-68F7-4AE7-B398-86598A62B7BC@microsoft.com>...
: > Without see all of your code it's a crap-shoot for me, but I'd guess
that
: > NameBuffer.Length is a Long (or Integer), and the arg position where you
are
: > using it the function is expecting a string, not a Long (or Int). Did
you
: > mean to use NameBuffer.Name? Or just NameBuffer or something like that?
: >
: > P.S. if you ever get tired of typing all those dollar signs and
ampersands
: > you might want to learn to Dim your variables instead!
: >
: >
: > "boki" wrote:
: >
: > > Dear All,
: > >
: > > I meet a problem when I compile my USB code, and I get this error
: > > message
: > >
: > > ============================
: > > Compile error:
: > > ByRef argument type mismatch
: > > ============================
: > >
: > > This problem happen at
: > >
: > > ========================================
==========
: > > Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
: > > ....
: > > Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0,
: > > NameBuffer.Length, 260, BytesReturned&, 0)
: > >
: > > ^^^^^^
: > > cursor stops at at "Length"
: > > ....
: > > ....
: > > ========================================
==========
: > >
: > > It is the problem "ByRef argument type mismatch"
: > >
: > > Set ByValue?
: > >
: > >
: > > Best regards,
: > > Boki.
: > >

Boki

2004-09-30, 4:44 am

Thanks to all, there are the code:

==A. bas=====================================
========
Declare Function DeviceIoControl Lib "kernel32" _
(ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Byte,
ByVal nInBufferSize As Long, _
lpOutBuffer As Byte, ByVal nOutBufferSize As Long, lpBytesReturned As Long,
lpOverlapped As Long) As Long
........
........
Public Type UNameType: Length As Long: UnicodeName(256) As Byte: End Type

=A. frm=====================================
==============

Dim NameBuffer As UNameType
........

========================================
================


Best regards,
Boki.


"Randy Birch" <rgb_removethis@mvps.org> ???
news:enWGU8ppEHA.3688@TK2MSFTNGP09.phx.gbl ???...
> You indicated you had a problem with DeviceIoControl, not CreateFile.

Post
> your declare for DeviceIoControl, as well as all the code - including the
> Dim's - for the local variables in the routine causing the problem. Also
> provide, from your exact code, precisely what NameBuffer.Length is.
>
> --
>
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
>
> "boki" <bokiteam@ms21.hinet.net> wrote in message
> news:4c3c095a.0409291706.5125b04d@posting.google.com...
> : Dear All,
> : This is my declaration about CreatFile:
> :
> : Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
> : (ByVal lpFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&,
> : lpSecurityAttributes&, _
> : ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal
> : hTemplateFile&) As Long
> :
> : Thank you very much for your help.
> :
> : Best regards,
> : Boki.
> :
> : "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> news:<97DA6951-68F7-4AE7-B398-86598A62B7BC@microsoft.com>...
> : > Without see all of your code it's a crap-shoot for me, but I'd guess
> that
> : > NameBuffer.Length is a Long (or Integer), and the arg position where

you
> are
> : > using it the function is expecting a string, not a Long (or Int). Did
> you
> : > mean to use NameBuffer.Name? Or just NameBuffer or something like

that?
> : >
> : > P.S. if you ever get tired of typing all those dollar signs and
> ampersands
> : > you might want to learn to Dim your variables instead!
> : >
> : >
> : > "boki" wrote:
> : >
> : > > Dear All,
> : > >
> : > > I meet a problem when I compile my USB code, and I get this error
> : > > message
> : > >
> : > > ============================
> : > > Compile error:
> : > > ByRef argument type mismatch
> : > > ============================
> : > >
> : > > This problem happen at
> : > >
> : > > ========================================
==========
> : > > Function GetNameOf$(DeviceName$, DeviceHandle&, API_ID&)
> : > > ....
> : > > Status& = DeviceIoControl(DeviceHandle&, API_ID&, 0, 0,
> : > > NameBuffer.Length, 260, BytesReturned&, 0)
> : > >
> : > > ^^^^^^
> : > > cursor stops at at "Length"
> : > > ....
> : > > ....
> : > > ========================================
==========
> : > >
> : > > It is the problem "ByRef argument type mismatch"
> : > >
> : > > Set ByValue?
> : > >
> : > >
> : > > Best regards,
> : > > Boki.
> : > >
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com