Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1954
  • Last Modified:


Hi All,

I have recently started programming in VFP (OOP). I'm stuck with a few things at the moment and would need your help.

How to use WMI Classes with VFP? (Event Classes, Monitor Classes, etc) with an example

How to use Win32 API with VFP? with an example.

   To be honest, I have no idea about Win32 API at all. Could you please redirect me to a link which has good information about
   Win32 API?


Nirmal Sharma
Nirmal Sharma
  • 4
  • 4
  • 3
2 Solutions
Olaf DoschkeSoftware DeveloperCommented:

a Short sample:

strComputer = "."
objSWbemServices = GetObject("winmgmts:\\" + strComputer)
colServices = objSWbemServices.InstancesOf("Win32_Service")

* or use WQL, eg
* colServices = objSWbemServices.ExecQuery("Select * From Win32_Service Where Name Like '%sql%'")

For Each objService In colServices
    ? objService.Name
    ? objService.DisplayName
    ? objService.Description
    ? objService.PathName
    ? objService.StartMode
    ? objService.State
    ? objService.AcceptStop
    ? objService.AcceptPause

You can adapt scripts in the WMI script repository at (search for WMI), WMI scripting primer

In regard to events:
An overview over WMI classes:

You find tons of references googling.


The command supporting the use of C functions in DLLs is DECLARE, A very good resource for Win API declarations and sample code in foxpro is

Bye, Olaf.

CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
There are samples in that ship with FoxPro.
Olaf DoschkeSoftware DeveloperCommented:
True, Cyril.

While the Windows API "chapter" of solutions is far from being complete, it has nice samples on how to use API functions needing a struct or a pointer to an array.

@SystmProg - you find the solution samples via tools -> task pane, it's a toolbar button there. It also can answer many other basic foxpro questions.

Bye, Olaf.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Nirmal SharmaSolution ArchitectAuthor Commented:
Well, what I need on Win32 API is a Guide which explains:

    What a Win32 API is?
    What a DLL is?
    How to use DLL Functions?

I think the question is not related to VFP in anyway but I would still a link or a book if you can suggest.

CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
An API is Application Programming Interface

Windows offers a lot of API functions which some are in the form of DLL (Dynamic Link Library) to save space for applications and time in development.

You need to DECLARE an API in FoxPro to be able to use it as if you are calling a native/local function.

You don't need a book. You just need to know what it is and how to search for one.
Nirmal SharmaSolution ArchitectAuthor Commented:
Cyril, You're right - I don't need a book...but how about a beginner coding a program which utilizes APIs?

The issue is that I don't understand the parameters associated with an API, for example; I don't know what a hWND is and how touse it.

For example: (I copied this from

DECLARE INTEGER GetMonitorContrast IN dxva2;
    INTEGER hMonitor,;
    LONG @pdwMinimumContrast,;
    LONG @pdwCurrentContrast,;
    LONG @pdwMaximumContrast

it says "GetMonitorContrast" IN dxva2 - and next it says INTEGER hMonitor, LONG @pdwMinimumContrast , etc..

the question is/are:

    Is dxva2 is a DLL which contains GetMonitorContrast function and hMonitor is a parameter or @pdwMinimumContrast is a parameter?

   How do I know this function is defined in this DLL and I would need to DECLARE in this DLL? Is there any list of DLLs with functions/paras associated with it?

   When using a Function from a Windows DLL, we would need to know the parameters associated with it - once we know we need to use them - the question is how we use them in VFP? is it same as storing a value in the variable? e.g. in this case; MyMonitorMinContrast = GetMonitorContrast.

I hope you're clear on what I want...


CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
dxva2 is most probably a dll in your hard disk.

The API info you find with the hardware manual or online. I usually search for Windows API info online. I used to have a 12MB manual of all API calls but since there was the internet, it is easier and faster and usually you find sample code as well.

It is very important to know what type of string. No need to be concerned if Integer or Double or Numeric since FoxPro can treat them the same. Just be concerned with Numeric, String.

You need to declare the function once and you can call it as many times as you wish.

here is a sample

FUNCTION WindowsDirectory
LOCAL cBuff, nLen
DECLARE INTEGER GetWindowsDirectory IN kernel32 STRING @, INTEGER
cBuff = SPACE(255)
nLen = GetWindowsDirectory(@cBuff,LEN(cBuff))
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
hwnd is a Window handler just like a file handler. You can get is from oForm.hwnd where oForm is the variable to your form.
Olaf DoschkeSoftware DeveloperCommented:
"a Win32 API" - you seem to misunderstand that there are many Win32 APIs. There is only one Win32 API. Win32 API is standing for all C functions of Windows DLLs, there surely are more APIs in windows, eg WMI is a different API and there are much more things windows offers as interface to make use of it. Cyril already pointed you towards several definitions of the term API. Win32API is a API, but despite of the different versions of it because of the different windows versions, there is only one Win32 API.

Win32 API is naming all the functions windows offers to any programming language to make use of in their applications. By using foxpro you already use many of the API functions indirectly, eg a foxpro form is a windows form and is created by the os with many Win API functions.

If you like you won't need many of the functions windows offers and can do applications with the foxpro language alone, but there surely are things worth investigating, no question.

The official documentation is from the creator of windows and it's API: Microsoft. It's called the MSDN Library. For example you find Microsofts description of the GetMonitorContrast Function here: 

In regard of how to know what hMonitor is: In general a function is part of a family of functions of a DLLs of windows. MSDN often does better describe the parameters and their meaning, constants and structues involved etc. For example the meaning of hMonitor is described by both news2news and MSDN:

Handle to a physical monitor. To get the monitor handle, call GetPhysicalMonitorsFromHMONITOR or GetPhysicalMonitorsFromIDirect3DDevice9.

So this simply is the result of another API function. There are certain naming conventions and nomenclatures, eg a parameter beginning with h typically is a handle, hwnd is a handle of a window. a handle typically is an integer value standing representive for an object instead of an object reference to the object adress in memory.

And from the DELARE perspective the semantics of the command are as the foxpro help says:

DECLARE [cFunctionType] FunctionName IN LibraryName [AS AliasName] [cParamType1 [@] ParamName1, cParamType2 [@] ParamName2, ...]

So you define the type of the function result, then the function name within the DLL and then the list of parameters and their type, and if they are by value or referential parameters.

Yes, there are many things and terms to learn, but you can and should perhaps keep it to a minimum of what you really need additional to what foxpro offers itself. GetMonitorContrast for example has Vista or Win2008 Server as minimum requirement and even though a VFP9 application with the vfp9 runtime can run on win98, me, xp, vista and win7, you limit it on Vista or win7 by making use of that function.

DECLARE is also capable to declare functions from other DLLs not part of Windows, not part of the Win32 API. There are many third party vendors of DLLs, commercial and open source. DECLARE can make use of such DLLs with c functions, in fact it's not important the function is written in C/C++, it can also be a pascal DLL, as long as it's a functional DLL in contrast to a DLL with COM Servers in it or an .NET Assembly DLL.

I surely opened a can of worms now, keep calm and just see the general idea of API is to enable external programs to make use of functions and to extend capabilities of a language or product. You can but not necessarily need to make use of that. DECLARE is one way out of foxpro to include functions from DLLs, CREATEOBJECT(Oleclassname) is another way to make use of OLE classes, COM Servers in DLLs or OCX files, There are further things like Webservices and many more more to extend foxpro.

Put into one word this is interoperability. Don't complain there is no documentation or reference to it, you could also explain there is no book explaining life. ;)

Bye, Olaf.
Nirmal SharmaSolution ArchitectAuthor Commented:
A very clear and nice explanation on what is what!!!!!

You know your stuff, Olaf :)

>>>I surely opened a can of worms now, keep calm and just see the general idea of API is to enable external programs to make use of functions and to extend capabilities of a language or product.

I concur...

Nirmal SharmaSolution ArchitectAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now