Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use CreateFile function
Message
 
To
02/06/2003 21:28:01
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00795494
Message ID:
00795519
Views:
21
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)
Previous
Reply
Map
View

Click here to load this message in the networking platform