This is driving me very insane. I seem to not be correctly initializing
the sockHP. When I run it, I get errors that the lines with sockHP in
it a about trying to access the address that sockHP holds (from the
debugger).
This function is SUPPOSED to take a URL from txtRequest field and put
the txtResponse field. Just that simple. No asynchornous nothing.
This should be simple. Maybe I'm missing a step. Maybe the sockH
should be preallocated with as a NewMemHandle? If that's the answer, I
can't figure that out either.
I did order a bunch of books to compliment the online docs from my boss.
(So I'm not just trying to freeload off here)
Please?
Thanks,
Jason
static Boolean frmMain_btnRequest_OnSelect(EventPtr event)
{
// Note: Form Fields are txtRequest and txtReturn.
// This function activated by pressing btnRequest.
FormType *formPtr; // pointer to current form
UInt16 fieldReturnIndex; // Index of txtReturn
UInt16 fieldRequestIndex; // Index of txtRequest
FieldType *fieldReturnPtr; // * to txtReturn
FieldType *fieldRequestPtr; // * to txtRequest
UInt16 libRefNum; // INetLib Reference Number
UInt16 WirelessConfig; // Wireless Configuration Set
MemHandle inetH; // Handle INetLib
MemHandle* sockHP; // Pointer to Handle of Socket
UInt32 actBytes = 0; // Actual Bytes Read from Socket
Char* serverResponse; // Server Response
Err myError;
// Get a pointer to the active form:
formPtr = FrmGetActiveForm();
// Get the indexes of the fields:
fieldReturnIndex = FrmGetObjectIndex(formPtr, txtReturn);
fieldRequestIndex = FrmGetObjectIndex(formPtr, txtRequest);
// Using the indexes we can get a pointers to the fields:
fieldReturnPtr = (FieldType *) FrmGetObjectPtr(formPtr,
fieldReturnIndex);
fieldRequestPtr = (FieldType *) FrmGetObjectPtr(formPtr,
fieldRequestIndex);
// Open Internet Library
SysLibFind(inetLibName, &libRefNum);
INetLibConfigIndexFromName(libRefNum, (INetConfigNameType*)
inetCfgNameDefWireless, &WirelessConfig);
myError = INetLibOpen(libRefNum, WirelessConfig, 0, NULL, 0,
&inetH);
ErrFatalDisplayIf(myError,"INetLibOpen failed.");
// Open Internet URL
myError = INetLibURLOpen(libRefNum, inetH,
FldGetTextPtr(fieldRequestPtr),
NULL, sockHP, 1500 , 0);
ErrFatalDisplayIf(myError, "INetLibURLOpen can't load page.");
// Get the Site Response
do
{
// Read from the Socket
myError = INetLibSockRead (libRefNum, *sockHP,
serverResponse, 1, &actBytes, 500 );
ErrFatalDisplayIf(myError,"INetLibSockRead failure.");
// Write output to the return field
if (actBytes != 0) FldInsert(fieldReturnPtr,
serverResponse, 1);
} while (actBytes != 0);
//Close the Internet Again
INetLibClose(libRefNum, inetH);
return true;
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/