Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I put field(s) in the Status Bar in an app
Message
From
10/01/2008 16:19:46
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01280938
Message ID:
01280992
Views:
20
This problem with API declarations will be (hopefully) solved in the next version of the class, I just stole an idea used in GDIPlusX.

This is what I do:

I have a prg with all the API declarations, this PRG is called in the init of each class. The first few lines of this prg are:


#Include ctl32.h
If Not Juststem(Sys(16)) $ Set("Procedure") Then
Set Procedure To Sys(16) Additive
Endif
Return


After that, ALL the API declares are included, and each one of them is a VFP function. The name of the VFP function and the alias used in the declare statement is the same, for example:


********************************************************************************
Function apiGetForegroundWindow()
********************************************************************************
Declare Integer GetForegroundWindow In win32api As apiGetForegroundWindow
Return apiGetForegroundWindow()
Endfunc


Now, the first time apiGetForegroundWindow is called somewhere in code, the VFP function will be executed, this will declare the API function. What happens then is that a declared API call takes precedence over a VFP function with the same name, so the function just calls itself again, with the passed parameters, if any, and since the API function is already declared, the API function is called instead of the VFP function.

Another benefit of this is that if you have a CLEAR DLLS somewhere in your code, then the VFP function will be called then, that will redeclare the API function.... etc.

Another example with parameters:


********************************************************************************
Function apiGetClientRect(m.nHWnd, m.lcRect)
********************************************************************************
Declare Integer GetClientRect In win32api As apiGetClientRect ;
Integer nHWnd,;
String @lcRect
Return apiGetClientRect(m.nHWnd, @m.lcRect)
Endfunc


Carlos
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform