Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use CreateFile function
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00795494
Message ID:
00795519
Vues:
20
Hi Liu,

Unfortunately almost everything is wrong in your code, which is probably translated from VB. The translation is incomplete.

(1) External function parameters in Visual FoxPro must be declared as
INTEGER lpNumberOfBytes
not as
lpNumberOfBytes As Integer

(2) GENERIC_READ or GENERIC_WRITE does not work in Visual FoxPro the way it works in Visual Basic.
You should change it to BitOr(GENERIC_READ, GENERIC_WRITE).
Actually even (GENERIC_READ + GENERIC_WRITE) works Ok in this case.

So finally your code should be this way:
#DEFINE GENERIC_READ         0x80000000
#DEFINE GENERIC_WRITE        0x40000000
#DEFINE OPEN_EXISTING        3
#DEFINE FILE_FLAG_OVERLAPPED 0x40000000

DECLARE INTEGER CreateFile IN kernel32;
	STRING lpFileName, INTEGER dwDesiredAccess, INTEGER dwShareMode,;
	INTEGER lpSecurityAttributes, INTEGER dwCreationDisposition,;
	INTEGER dwFlagsAndAttributes, INTEGER hTemplateFile

DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject

* this already works
ICDEV = CreateFile('COM1', GENERIC_READ+GENERIC_WRITE, 0,0,;
	OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0)
? ICDEV
= CloseHandle(ICDEV)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform