Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing values to a win32api
Message
From
06/11/1997 00:58:19
 
 
To
05/11/1997 10:51:44
Simon Williams
First Data Merchant Services
Coral Springs, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00058045
Message ID:
00058551
Views:
53
The in_addr structure is in fact a 4-bytes variable that can be used in C like 4 different characters, 2 short unsigned integers or one long unsigned integer. In VFP you must use it as a 4 char string (because you must concatenate it in the other bigger string that simulates the sockaddr structure).

I'm not sure what's the meaning of the information contained in this structure, but if you have one numerical value to pass as in_addr:

lcin_addr = loPointersObject.converter.NumberToDWordString(lnin_addr)

And lcin_addr will replace lcpsa_data in your formula:

LPaddr = lcsa_family +lcport+lcin_addr+lcpadding

Vlad

>>What's the declaration for the in_addr structure?
>struct in_addr {
> union {
> struct{
> unsigned char s_b1,
> s_b2,
> s_b3,
> s_b4;
> } S_un_b;
> struct {
> unsigned short s_w1,
> s_w2;
> } S_un_w;
> unsigned long S_addr;
> } S_un;
>};
>
>>
>>Vlad
>>
>>>>>How can I pass multiple values to a win32api from Visual FoxPro?
>>>>
>>>>You must build a char string that will contain the data (the fields in a structure are always in a contigous memory space, so this is why you can use a char string.)
>>>>
>>>>>Basically I need to fill this structure prior of calling the bind function.
>>>>>
>>>>> struct sockaddr {
>>>>> u_short sa_family;
>>>>> char sa_data[14];
>>>>> };
>>>>
>>>>Unfortunately, you cannot use this structure directly from VFP (because it contains a pointer (sa_data is a pointer to char, in fact)). The string you must build must have 6 bytes:
>>>>
>>>>- the first 2 bytes: the sa_family in binary format
>>>>- the next 4 bytes: a pointer to a string that will contain sa_data
>>>>
>>>>You must use an third-party product (as my Pointers Class that you can download from the Files section) that adds pointer features to VFP, in order to send data to this function.
>>>>
>>>>If you use my Pointers Class:
>>>>
>>>>lnsa_family = ... && Your value
>>>>lcsa_data = ... && Your value, max 14 chars
>>>>*-- Instantiate a Pointers control object
>>>>SET CLASSLIB TO POINTERS ADDITIVE
>>>>loPointers=CREATEOBJECT('Pointers')
>>>>RELEASE CLASSLIB POINTERS
>>>>*-- Convert the sa_family field to binary format on 2 bytes
>>>>lcsa_family = loPointers.NumberToWordString(lnsa_family)
>>>>*-- Get a pointer to sa_data string
>>>>lcpsa_data = loPointers.GetPointer(lcsa_data, "STRUCTURE")
>>>>*-- Build the "structure"
>>>>lcSockAddr = lcsa_family + lcpsa_data
>>>>
>>>>lcSockAddr is the value that you must pass by reference to the bind function as the 2nd param.
>>>>
>>>>Hope I was clear, :)
>>>>Vlad
>>>>
>>>>> int bind (
>>>>> SOCKET s,
>>>>> const struct sockaddr FAR * addr,
>>>>> int namelen
>>>>> );
>>>>>
>>>>>Thanks in advance for your help.
>>>
>>>Thanks for your help, but I'm still hitting a wall.
>>>I getting this error "Address not available from local machine".
>>>I probably left something out. The code is below. Any help you
>>>can provide will be greatly appreciated.
>>>
>>>
>>>#define AF_INET 2 && internetwork: UDP, TCP, etc.
>>>#define SOCK_STREAM 1 && stream socket */
>>>
>>>DECLARE INTEGER WSAStartup IN wsock32 INTEGER wVersionRequested, INTEGER @lpWSAData
>>>DECLARE INTEGER socket IN wsock32 INTEGER lnaf, INTEGER lntype, INTEGER protocol
>>>DECLARE INTEGER closesocket IN wsock32 INTEGER socketnum
>>>DECLARE INTEGER bind IN wsock32 INTEGER socketnum, STRING @LPaddr, INTEGER namelen
>>>DECLARE INTEGER listen IN wsock32 INTEGER s, INTEGER backlog
>>>DECLARE INTEGER WSAGetLastError IN wsock32
>>>local x,lnwVersionRequested,lclpWSAData,LPaddr,namelen
>>>
>>>lclpWSAData = 0
>>>namelen = 31
>>>lnwVersionRequested = 2
>>>
>>>&& struct sockaddr_in{
>>>&& short sin_family;
>>>&& unsigned short sin_port;
>>>&& struct in_addr sin_addr;
>>>&& char sin_zero[8];
>>>&&};
>>>
>>>
>>>lnsa_family = AF_INET
>>>lnport = 5302
>>>lcsa_data = "129.110.200.92"
>>>lcpadding = SPACE(8)
>>>
>>>
>>>*-- Create the Pointers Class object
>>>SET CLASSLIB TO POINTERS ADDITIVE
>>>loPointersObject = CREATEOBJECT("Pointers")
>>>RELEASE CLASSLIB POINTERS
>>>
>>>lcsa_family = loPointersObject.converter.NumberToWordString(lnsa_family)
>>>lcport = loPointersObject.converter.NumberToWordString(lnport)
>>>lcpsa_data = loPointersObject.GetPointer(lcsa_data,"STRUCTURE")
>>>
>>>LPaddr = lcsa_family +lcport+lcpsa_data+lcpadding
>>>
>>>x = WSAStartup(lnwVersionRequested,@lclpWSAData)
>>>? "WSAStartup",x
>>>IF (x = 0)
>>> x = socket (AF_INET,SOCK_STREAM,0)
>>> d = WSAGetLastError()
>>> ? "Socket",x
>>> s = bind (x,@LPaddr,namelen)
>>> ? "bind",s
>>> d = WSAGetLastError()
>>> ? "ERROR",d
>>> v = listen(x,1)
>>> ? "Listen",v
>>> d = WSAGetLastError()
>>> ? "ERROR",d
>>> y = closesocket(x)
>>> ? "CloseSocket",y
>>>
>>>ENDIF
Previous
Reply
Map
View

Click here to load this message in the networking platform