Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass Structure in API functions?

Status
Not open for further replies.

rajeevnandanmishra

Programmer
Jun 1, 2001
379
IN
Hi all,
I want to call a win32 api function in foxpro.
The api expects a strucuture like this :
-------------
hWnd long
pID long
pszDN long
lpszTl long
ulFlg long
lpfnCb long
lParam long
iImg long
-------------
I had tried to create a class and then pass that class object to this api, But of no use. It always says "too many arguments".
Can any one help me in creating the structures in VFP, or, tell me how to execute such functions from VFP.

Any help is highly appriciated.
Thanks!
 
Hi,
in VFP, structure is string

Some DLL functions require more complex parameters, such as structures or arrays. If the function requires a pointer to a structure, you must determine the layout of the structure, then emulate it as a string in Visual FoxPro before passing it or receiving it from the DLL function. For example, the Windows system function GetSystemTime( ) expects a pointer to a structure consisting of eight words or unsigned 16-bit integers indicating the year, month, day, and so on. The structure is defined this way:

typedef struct _SYSTEMTIME {
WORD wYear ;
WORD wMonth ;
WORD wDayOfWeek ;
WORD wDay ;
WORD wHour ;
WORD wMinute ;
WORD wSecond ;
WORD wMilliseconds ;
} SYSTEMTIME

To pass data between Visual FoxPro and the GetSystemTime( ) function, you must create a 40-byte string buffer (consisting initially of spaces) and then pass the address of this string to the function for it to fill in. When the string is returned, you must parse it in 2-byte increments to extract the individual fields of the structure. The following fragment illustrates how you could extract three of the fields from the structure:

DECLARE INTEGER GetSystemTime IN win32api STRING @
cBuff=SPACE(40)
=GetSystemTime(@cBuff)

tYear = ALLTRIM(STR(ASC(SUBSTR(cBuff,2)) * ;
256 + ASC(SUBSTR(cBuff,1))))
tMonth = ALLTRIM(STR(ASC(SUBSTR(cBuff,4)) * ;
256 + ASC(SUBSTR(cBuff,3))))
tDOW = ALLTRIM(STR(ASC(SUBSTR(cBuff,6)) * ;
256 + ASC(SUBSTR(cBuff,5))))



Jimmy Le
nhan_tiags@yahoo.com
 
Hi jimmy,
Thanks for your help. I had seen that code in HELP.
But the problem here is i have to pass a structure having long datatypes like.

typedef struct _myStructure {
hWnd long ;
pID long ;
pszDN long ;
lpszTl long ;
ulFlg long ;
lpfnCb long ;
lParam long ;
iImg long ;
} myStructure

Moreover, in a few elements of this structure i have to pass the value also. Like before calling the API, i must initialize first 3 elements (hwnd,pId,pszDn) with my program values.

In the systime example we are converting a "word" type to string. How should i convert the "long" type to string.
And in systime, we are not passing any value to any of the "word" elements. But here i require to pass values also.

May be now you had understood, my problem exactly.

Thanks again for your response. I am waiting for your next response.
 
Hi!

Find 2 classes: struct.zip and CLSHEAP.PRG at the site. First one allows easy creating structures using class, than get a string required to pass to API function. Second one allows to work with pointers in VFP to pass such data to API function as a structure with a pointer to string or with pointer to another structure.


Hope this helps.
Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top