need help to call API

  • Thread starter Thread starter Eric BOUXIROT
  • Start date Start date
E

Eric BOUXIROT

hi all !!!
i need to call this API :
FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD
Flags)

i have a sample code in C++ that work fine...
FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD Flags)

FT_STATUS ftStatus;
DWORD numDevs;

ftStatus = ListDevices(&numDevs, NULL, FT_LIST_NUMBER_ONLY);
char Buf[64];
ftStatus = ListDevices((PVOID)numDevs, buffer,
FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);

but i don't know how i can convert it on VB.NET

thank a lot !
 
I'm assuming FT_STATUS is 32-bit number. Another thing is bothering me -
the first param is a DWORD. You are passing its address in the first call
(which I assume causes the function to return the number), but then you are
casting the number to a pointer in the second call?? That doesn't seem
right. I will assume you will always need to pass an address. I'm also
assuming the buffer is an ASCII string. Otherwise, you'll want to change
that to a Byte array. Strange that you declare Buf[64] as a Char array, but
then use a non-existant buffer variable. That leaves my interpretation of
the second paramater in a little bit of a mystery. I'm assuming at the
moment that buffer is the address of Buf.

Declare ANSI Function FT_ListDevices(ByRef pArg1 As Integer, ByVal pArg2 As
String, ByVal Flags As Integer) As Integer

You will need to get the numeric values for the 3rd parameter and create
constants for them. Also, in the first call, pass String.Empty to the second
parameter (which will translate to NULL).

PS: All C(++) programers that assign PVOID or *void to variables and
parameters are going to the same hell as VB programers who don't declare
their variables.

-Rob Teixeira [MVP]

Eric BOUXIROT said:
hi all !!!
i need to call this API :
FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD
Flags)

i have a sample code in C++ that work fine...
FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD Flags)

FT_STATUS ftStatus;
DWORD numDevs;

ftStatus = ListDevices(&numDevs, NULL, FT_LIST_NUMBER_ONLY);
char Buf[64];
ftStatus = ListDevices((PVOID)numDevs, buffer,
FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);

but i don't know how i can convert it on VB.NET

thank a lot !
 
hi rob,

thank for your answer.
i have try what you say but it don't work too..
for your info:
FT_STATUS is long

when i call :the API should put in numDevs the number of devices it can access.

this call work fine...OK

but when i call the second :FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);
the device should put in buffer (which is an array of 64 byte) the name of
the device (from index numDevs). numDevs is Long. but it don't work (the API
return in ftStatus that device doesn't exist)..

i have try the exemple in VC++ then it work fine (all two calls !!),

i have try to replace (PVOID)numDevs in second call by &numDevs and this
don't work..(the API return in ftStatus that device not exist, like with VB
!)

thank for your help...
Flags)
 
OK, sounds more and more like the kind of C programmer I want to hate.
They appear to have created the 1st parameter as both a number and a
pointer.
If you ever find the programmer of this API, shoot him.
Your safest bet is to create TWO api declare statements with different
Aliases.
One passes the 1st parameter ByValue and the other passes the 1st parameter
ByRef.

Also, Long in C = Integer in VB.NET and C#.

-Rob Teixeira [MVP]
 
Hello, Eric:

You will need (as Rob said) different declarations for the three different flags:


declare function FT_ListDevices1 lib "FTD2XX.DLL" alias "FT_ListDevices" (byref pArg1 as int32, byval pArg2 as int32, byval Flags as int32) as int32 'For FT_LIST_NUMBER_ONLY
declare ansi function FT_ListDevices2 lib "FTD2XX.DLL" alias "FT_ListDevices" (byval pArg1 as int32, byval pArg2 as string, byval Flags as int32) as int32 'For FT_LIST_BY_INDEX
declare ansi function FT_ListDevices3 lib "FTD2XX.DLL" alias "FT_ListDevices" (byval pArg1 as int32, byref pArg2 as string(), byval Flags as int32) as int32 'For FT_LIST_ALL (I don't know if it will work)

Remember that each string must be at least 64 characters long before calling the function.

Regards.


"Eric BOUXIROT" <[email protected]> escribió en el mensaje | hi all !!!
| i need to call this API :
| FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD
| Flags)
|
| i have a sample code in C++ that work fine...
|
| > FTD2XX_API FT_STATUS WINAPI FT_ListDevices(PVOID pArg1,PVOID pArg2,DWORD
| Flags)
| >
| > FT_STATUS ftStatus;
| > DWORD numDevs;
| >
| > ftStatus = ListDevices(&numDevs, NULL, FT_LIST_NUMBER_ONLY);
| > char Buf[64];
| > ftStatus = ListDevices((PVOID)numDevs, buffer,
| FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);
|
| but i don't know how i can convert it on VB.NET
|
| thank a lot !
 
Thank to you José and Rob !!!

after 1 day of hard search, this shit of API work....
Big Thank !!

i have one more question...
with this call
declare ansi function FT_ListDevices2 lib "FTD2XX.DLL" alias
"FT_ListDevices" (byval pArg1 as int32, byval pArg2 as string, byval Flags
as int32) as int32 'For FT_LIST_BY_INDEX
now i get a string ok but it seem to be incomplete..i explain..
when i break the program and in execution windows i type
? buffer (which is my string buffer with 65 Spaces)
i get
"123456
but there isn't the " at the end of string....

now i change the declare to use array of 64 bytes...
and add each byte to my string buffer with CHR instruction...
now when i ? buffer i get correct
"123456"
......
i don't know why...

thank a lot for your help !
 
Back
Top