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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create User-defined Type 2

Status
Not open for further replies.

ashthud

Programmer
Oct 6, 2008
53
GB
How do i create a user-defined type in foxpro 2.6? The problem stems from me trying to call an api function that requires a parameter of a custom type.

In vb6 i simply say:

Private Type test
var1 as string * 10
var2 as integer
var3 as boolean
End Type

 
You are limited to the predefined types in Foxpro, but if you don't declare their type before using them , they will default to a logical data type with .F. as the value.
To declare them before using them , just assign them a value:

STORE '' TO charType
STORE 0 TO numType
STORE .F. TO boolType

DIMENSION arraytype[1,3]
arraytype[1,1] = '' &&... character
arraytype[1,2] = 0 &&... numeric
arraytype[1,3] = .F. &&... boolean



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
"The problem stems from me trying to call an api function that requires a parameter of a custom type."

It would seem that your needs would be defined on the variety of 'types' that are recognized by the API, not by Foxpro.

I'd suggest that you do some investigation into the requirements and allowed options of the API and then you can set up your FP users with whatever is needed through code.

Good Luck,
JRB-Bldr
 
To be more specific, i was trying to add a system tray icon (to the system tray obviously):

In vb6 i simply say:
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
szInfo As String * 256
End Type
Private Declare Sub Shell_NotifyIconA Lib "shell32" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA)

..."pnid" is a custom type, this is where i am slipping up.

i know how to call a function from a 32bit library... do i simply just send an array, like the one DSummZZZ (dave summer) suggests?
 
*CORRECTION:
pnid is of the custom type "NOTIFYICONDATA", which is made up of: long,long,long,long,long,long,string,string
 
The biggest issue here is trying to call a 32 bit API from a 16 bit architecture. As far as I know, you can't.

You may be able to do it with VB script using Windows Scripting Host called from a RUN command, but even then it would probably be iffy.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
The normal way to build structures in VFP you can pass to some API function is to stuff them together in memory by using a string with the structure size as a buffer and converting the basic subtypes to strings, Take a look at and you'll find examples for most API functions, that at least work with 32 bit VFP.

Bye, Olaf.
 
THANK YOU OLAF FOR THE LINK. I had a scout around the site and found: the vfp version of what i was trying to achieve.

You were correct, structures (or as i called them User-Defined types) can be built by simply concatenating the values (aka stuffing them together in memory.
 
I would also like to thank microsoft.public.fox.programmer.exchange's Andrew Howell for his explanation of Structures, and his correction of my above code:

var1 = PADR("BLAH",10)

should be:

var1 = "BLAH" + CHR(0)
 
Glad i could help.
Cheers for your help too! =D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top