Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a C function with a parameter in AppleScript Studio



Hello,

I want to call a C function with a parameter in an AppleScript Studio application, I have look at in the developer examples for AppleScript Studio in the Multi-Language projet how to call a C function. In the source project there is no parameter for the function, I need to know how to pass a string parameter.

I have modify the
Multi-Language.mm and Multi-Language.h files as Mark Lively has suggest to me for passing a string parameter but the script end with the Error: NSCannotCreateScriptCommandError (10)

I have debug the code and I see that the same error is reproduce even if I don't call tke C function, have you any suggestion on how to make the script to work correctly ?

Here below are all the modified code from the Multi-Language projet that I use in my own projet.

---------------------- The Script button
on clicked theObject
tell window of theObject
-- Call the Objective-C method "nameForCLanguage" defined in "Multi-Language.h"
-- It in turn, will call a function defined in "C.h"
set contents of text field "MotDePasse" to call method "nameForCLanguage" with parameter "Language C"
end tell
end clicked

---------------------- Function
getNameForCLanguage
#include "C.h"
// A very simple function to return the name of the "C" language.
char *getNameForCLanguage(char *chaine)
{
return chaine;
}


----------------------
Multi-Language.h

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
// NSApplication
// =============
@interface NSApplication (ASKAMultiLanguage)
- (NSString *)nameForCLanguage:(NSString *)aString;
@end

----------------------
Multi-Language.mm

#import "Multi-Language.h"
extern "C"
{
#import "C.h"
}
@implementation NSApplication (ASKAMultiLanguage)

- (NSString *)nameForCLanguage:(NSString *)aString
{
// This will create a string using the c string returned from the
// function call 'getNameForCLanguage' which is defined in "C.h" and is implemented in "C.c".

NSString *languageName = [NSString stringWithCString:getNameForCLanguage([aString cString])]; return languageName;
}

------------------------------------------------

Thank for your help,

Gérard Brochu
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.