From craigstanton at mac.com Mon Aug 1 19:40:37 2005 From: craigstanton at mac.com (Craig Stanton) Date: Mon Aug 1 19:40:45 2005 Subject: [missing-sync-ppc-dev-talk] CeReadFile causes instability? Message-ID: I'm trying to make a program that copies some files from a PocketPC, but ever since I added the call to CeReadFile my app has been playing up. The tricky thing is that it doesn't necessarily happen at the moment of calling CeReadFile. The SIGSEGV 11 signal could come a little while later, whether I am doing something else or not, but I'm sure it doesn't happen until after CeReadFile is used. I'm guessing that I am leaving some file open, or screwing up the memory management but I've done all I can and it won't go away. Does anyone here have experience with this, or better yet some (stable) sample code of copying a file from a device to the computer? This is what I have so far. -(Boolean )copyFileFromDevice:(NSString *)deviceFile toLocal:(NSString *)localFile { NSMutableData *fileData = [[NSMutableData alloc] init]; NSMutableData *bufferData = [[NSMutableData alloc] init]; [bufferData setLength:COPY_FILE_BUFFER_SIZE]; LPVOID aBuffer = (LPVOID)NewPtr(sizeof(LPVOID)); HANDLE hSource; DWORD dwBytesRead = -1; LPDWORD lpNumberOfBytesRead = (LPDWORD)NewPtr(sizeof(LPDWORD)); int totalBytesCopied = 0; RAPI_BOOL readSuccess = 1; hSource =[rapi CeCreateFile: deviceFile desiredAccess: GENERIC_READ sharingMode: 0 //These settings are all copied from securityAttributes: 0 //our Windows client creationDisposition: OPEN_EXISTING flagsAndAttributes: 0 templateFile: 0]; *lpNumberOfBytesRead = -1; while ((dwBytesRead != 0) & (hSource != INVALID_HANDLE_VALUE) & (readSuccess != 0)) { readSuccess = [rapi CeReadFile: hSource buffer: aBuffer bytesToRead: COPY_FILE_BUFFER_SIZE bytesRead: &dwBytesRead overlapped: 0]; if (readSuccess != 0){ [fileData appendBytes:aBuffer length:dwBytesRead]; totalBytesCopied += dwBytesRead; } NSLog(@"Uploaded %d bytes - total = %d",dwBytesRead, totalBytesCopied); } //if (hSource != INVALID_HANDLE_VALUE){ [rapi CeCloseHandle:hSource]; //} if (readSuccess){ [fileData writeToFile:localFile atomically:NO]; return YES; } else { DWORD LastError; LastError = [rapi CeGetLastError]; NSLog(@"the last error = %d", LastError); return NO; } } Cheers, Craig -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 3622 bytes Desc: not available Url : http://lists.markspace.com/pipermail/missing-sync-ppc-dev-talk/attachments/20050802/0783b42e/attachment.bin From craigstanton at mac.com Mon Aug 15 20:38:44 2005 From: craigstanton at mac.com (Craig Stanton) Date: Mon Aug 15 20:38:54 2005 Subject: [missing-sync-ppc-dev-talk] Notification of connection Message-ID: <38f3b49d571c69df8391a62abc75c2eb@mac.com> I'm looking for a way to be told when a Pocket PC is connected to my mac though Missing Sync. I could do the old looping-until-one-is-connected trick, but that's not very elegant and there is a more Cocoa way of doing things. NSNotifications. I found a program called Notification Watcher and tried to see what Notifications Missing Sync was posting, but it seems that the only thing Missing Sync fires out is MSWM_LogChanged, and it send out lots of them. The last four upon connection are: Key ValueNew NewString 8/16/05 15:33:40 MSUI: DLL found on device, testing it String 8/16/05 15:33:41 MSUI: Found version 1.28 on device NewString 8/16/05 15:33:41 MSUI: Send ConnectedMessageToPlugins NewString 8/16/05 15:33:41 Monitor: Waiting for connections on port 5678. Is there a recommended way to get an app to sit and wait for a connection message from Missing Sync? ~Craig From eshapiro at markspace.com Wed Aug 17 06:44:18 2005 From: eshapiro at markspace.com (Eric Shapiro) Date: Wed Aug 17 06:44:20 2005 Subject: [missing-sync-ppc-dev-talk] re: Notification of connection Message-ID: <80bea7660ac332ba0468367748e01ad2@markspace.com> If you register yourself as a plugin with The Missing Sync, you should get device connected notifications. If this is not the case, let me know. Specifically, call the routine "connectToMissingSync" as shown below from your application. You will then get calls to deviceConnected and deviceDisconnected which get passed an NSString with the device name. You should implement all of the routines in the protocol "MSCeAppToPluginProtocol" (in our framework's MSPPCPluginAPIProtocol.h file). There's a non-Cocoa way to do this too using callbacks in MSPPCPluginAPI.h. -Eric Shapiro #import #import @interface MyController : NSObject id mMissingSync; NSString *mBundlePath; @end @implementation MyController -(id) init { if ( (self = [super init]) != nil ) { mBundlePath = [[[NSBundle mainBundle] bundlePath] retain]; } return self; } -(void) awakeFromNib { if ( [self connectToMissingSync] ) NSLog( @"Connected to Missing Sync" ); else NSLog( @"Can not connect to Missing Sync" ); } /*=============================== connectToMissingSync Initiates a connection with The Missing Sync for Pocket PC application. ===============================*/ -(BOOL) connectToMissingSync { BOOL ok = NO; if ( mMissingSync ) { [mMissingSync release]; mMissingSync = nil; } id remoteObject = [NSConnection rootProxyForConnectionWithRegisteredName: @kMSCePluginConnectionName host: nil]; if ( remoteObject ) { [remoteObject setProtocolForProxy: @protocol(MSCePluginToAppProtocol)]; mMissingSync = [remoteObject retain]; NS_DURING [mMissingSync initialize:mBundlePath target:self]; ok = YES; NS_HANDLER NS_ENDHANDLER } return ok; } /*=============================== disconnectFromMissingSync ===============================*/ -(void) disconnectFromMissingSync { if ( mMissingSync ) { NS_DURING [mMissingSync cleanup:mBundlePath]; [mMissingSync release]; NS_HANDLER NS_ENDHANDLER mMissingSync = nil; } } /*============================================ deviceConnected Description: Called when a new device is connected. Typically ignored by plugins. ==============================================*/ -(oneway void) deviceConnected:(MSCeDeviceID)deviceID { } /*============================================ deviceDisconnected Description: Called when a new device is disconnected. We'll cancel any in-progress activity. ==============================================*/ -(oneway void) deviceDisconnected:(MSCeDeviceID)deviceID { [self stopSync]; } /*============================================= enableForDevice Called when the user turns on our plugin. ==============================================*/ -(oneway void) enableForDevice:(MSCeDeviceID)deviceID { } /*============================================= disableForDevice Called when the user turns off our plugin ==============================================*/ -(oneway void) disableForDevice:(MSCeDeviceID)deviceID { [self stopSync]; } /*============================================= missingSyncQuitting The Missing Sync application is quitting. ==============================================*/ -(oneway void) missingSyncQuitting { [NSApp terminate:self]; // no need to stick around } /*============================================= lockAvailable ==============================================*/ -(oneway void) lockAvailable:(NSString*)key { } /*============================================= showSettingsForDevice Show our settings dialog. ==============================================*/ -(oneway void) showSettingsForDevice:(MSCeDeviceID)deviceID { } @end -Eric ----------------------------------------------- Eric Shapiro Mark/Space Engineering ----------------------------------------------- From craigstanton at mac.com Wed Aug 31 21:29:11 2005 From: craigstanton at mac.com (Craig Stanton) Date: Wed Aug 31 21:29:10 2005 Subject: [missing-sync-ppc-dev-talk] Determining available space on the disk (CeGetStoreInformation?) Message-ID: <38fd7b2f2958302ff33511e03b1f544e@mac.com> Hello all, I'm trying to programatically find out the disk size and available space on a PocketPC, but the response I am getting from CeGetStoreInformation doesn't make sense. The structure that is populated by running it through CeGetStoreInformation claims the internal disk is about 31.2MB, and this is echoed in the OS X Finder when I get MissingSync to mount the device as a volume. The structure also says that the available space is a little less than that (261,008 bytes less to be exact) but the Finder claims there is 2.47GB available, which is much more likely though I don't have the exact figures to know if that is exactly correct. So my questions are these Does anyone have experience with determining the size/available space on a PocketPC, how did you do it? How do Mark/Space get the info to report to the finder? How would I convert this to also find out the size/space of a removable card that is inserted into the PocketPC? Cheers, Craig