Sending a message to SuperCard

External developers... This forum's for you!

Sending a message to SuperCard

Postby HairyHighlandCow » Wed Mar 23, 2011 7:20 am

Mike would like the FSIterator external to send a message to SuperCard while it is running. I have tried to adapt some code I found, but it is making SC crash. I don't understand string pointers; if I could have some help with making this work it would be much appreciated.
Thanks
Alec

Code: Select all
   
// send message to card in SuperCard
               
theMessage = [NSString stringWithFormat:@"iterator\"%@\",%d", (CFMutableStringRef) nameMCFString, idx];
               
theMessageData = [theMessage dataUsingEncoding: NSMacOSRomanStringEncoding];
               
//NSLog(theMessage);
               
if ([theMessageData length] <= 255){
   theMessagePointer[0] = [theMessageData length];
   memmove( theMessagePointer +1, [theMessageData bytes], theMessagePointer[0]);
   SendCardMessage(par, theMessagePointer);
}
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Sending a message to SuperCard

Postby sctell » Wed Mar 23, 2011 9:55 am

Have you looked at Uli's SCparamBlock

Here are two functions to get you going:
Code: Select all

-(void)sendCardMessage: (NSString*)superTalkStatement
{
   Str255      theMessage;
   [SCParamBlock setStringPtr: theMessage toString: superTalkStatement];
   SendCardMessage( paramPtr, theMessage );
}

+(void)setStringPtr: (StringPtr)theString toString: (NSString*)str
{
   NSData* textData = [str dataUsingEncoding: NSMacOSRomanStringEncoding];
   if( [textData length] > 255 )
      [NSException raise: @"SCParamBlockStringTooLongException" format: @"Can't turn a string longer than 255 character into a StringPtr."];
   else
      theString[0] = [textData length];
   memmove( theString +1, [textData bytes], theString[0] );
}


I have to say Uli's SCparamBlock makes these sort of thing easy in Cocoa.
sctell
 
Posts: 1150
Joined: Sun Jul 06, 2008 10:41 am

Re: Sending a message to SuperCard

Postby sctell » Wed Mar 23, 2011 9:59 am

Out of interest here is the header file:
Code: Select all
@interface SCParamBlock : NSObject
{
   XCmdPtr      paramPtr;
}

-(id)         initWithXCmdBlock: (XCmdPtr)pblock;

// Parameters:
-(int)         parameterCount;

-(NSString*)   parameterAtIndex: (int)ind;
-(void)         setParameterAtIndex: (int)ind to: (NSString*)str;   // For pass-by-reference parameters.

-(NSData*)      parameterDataAtIndex: (int)ind;
-(void)         setParameterDataAtIndex: (int)ind to: (NSData*)theData;   // For pass-by-reference parameters.

// Return value:
-(void)         setReturnValue: (NSString*)str;


// Callbacks:
-(void)         sendCardMessage: (NSString*)superTalkStatement;
-(void)         sendSCMessage: (NSString*)superTalkStatement;
-(NSString*)   evaluateExpression: (NSString*)superTalkExpression;

-(NSString*)   valueForGlobal: (NSString*)globalName;
-(void)         setValue: (NSString*)var forGlobal: (NSString*)globalName;

-(NSString*)   valueOfFieldNamed: (NSString*)fieldName onCardLayer: (BOOL)yorn;
-(NSString*)   valueOfFieldNumber: (int)num onCardLayer: (BOOL)yorn;
-(NSString*)   valueOfFieldID: (int)num onCardLayer: (BOOL)yorn;

-(void)         setValue: (NSString*)val forFieldNamed: (NSString*)fieldName onCardLayer: (BOOL)yorn;
-(void)         setValue: (NSString*)val forFieldNumber: (int)num onCardLayer: (BOOL)yorn;
-(void)         setValue: (NSString*)val forFieldID: (int)num onCardLayer: (BOOL)yorn;

// Low-level utility stuff:
+(Handle)      stringHandleFromString: (NSString*)str;
+(Handle)      stringHandleFromData: (NSData*)theData;

+(NSString*)   stringFromStringHandle: (Handle)theHd;
+(NSData*)      dataFromStringHandle: (Handle)theHd;

+(void)         setStringPtr: (StringPtr)theString toString: (NSString*)str;   // theString must be a variable of type Str255.


@end
sctell
 
Posts: 1150
Joined: Sun Jul 06, 2008 10:41 am

Re: Sending a message to SuperCard

Postby HairyHighlandCow » Wed Mar 23, 2011 3:07 pm

Hi Terry,

If you look at Uli's code and mine you will see they are the same because I have used Uli's code. However, all I get is a crash, so something is wrong.

Thanks

Alec
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Sending a message to SuperCard

Postby HairyHighlandCow » Wed Mar 23, 2011 3:12 pm

There's a Str255 in there which I'm not using-- maybe this is what I've missed out?
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Sending a message to SuperCard

Postby HairyHighlandCow » Wed Mar 23, 2011 3:30 pm

Yes, it was. Working now,
Thanks
Alec
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron