Hello All,

Using the new NSURL methods available with Cocoa on Mac OS X 10.6, I am
trying to create an alias file to a certain file. However, this method
requires a NSURL data type. But I am writing a C program along with an
objective-C program to accomplish this. The C program would accept the
inputs as C strings. I would then convert them to NSString and then to NSURL
strings. However, this is not working :(
By hardcoding the NSURL strings the program works fine.

Below are the programs:

alias.c ===========>
/*==============================================================*/
#include<stdio.h>
#include<AvailabilityMacros.h>

int CreateAlias(char *, char *);

int main(int argc, char *argv[])
{
       #ifdef MAC_OS_X_VERSION_10_6
               if (CreateAlias(argv[1], argv[2]))
                       printf("Successful\n");
               else
                       printf("Failed\n");
       #else
               printf("Cannot create Alias files\n");
       #endif
       return 0;
}
/*================================================================*/

createalias.m (I use the NSURL methods for creating Aliases )
/*================================================================*/
#import <Foundation/Foundation.h>

int CreateAlias(const char *target, const char *aliasname)
{
       CFStringRef Ref1 = CFStringCreateWithCString(NULL, target,
kCFStringEncodingASCII);

       CFStringRef Ref2 = CFStringCreateWithCString(NULL, aliasname,
kCFStringEncodingASCII);

       if (Ref1 == NULL || Ref2 == NULL)
               exit(1);

       NSString *Destination = (NSString *)Ref1;
       NSString *Alias       = (NSString *)Ref2;
       //NSURL *src =  [NSURL URLWithString:@"file:///Alias_dir/aliastext"];
       //NSURL *dest = [NSURL URLWithString:@
"file:///Alias_dir/aliastext.alias"];

       NSURL *src =  [NSURL URLWithString:Destination];
       NSURL *dest = [NSURL URLWithString:Alias];

       if (src == nil || dest == nil)
               exit(1); *// Did not exit here.*

       NSData *bookmarkData =
                 [
                 src
bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
                 includingResourceValuesForKeys:nil
                 relativeToURL:nil
                 error:NULL
                 ];
       if (bookmarkData == NULL)
               exit(1);  // Did not exit here.

       BOOL ok = [NSURL writeBookmarkData:bookmarkData *// The program is
failing here*
                       toURL:dest
                       options:0
                       error:NULL];
       if (ok == NO)
               return 0;

       return 1;
}
/*===========================================================================*/

I also read that CFStringRef can be directly typecasted to NSString *which i
have done.

Can anyone tell me what the problem may be ?
Any comments ?

Thanks
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to