camera?

Great!  Happy to help!

And I’ve spotted one more problem in your code.  You are giving the “ofn.lpstrFile” field a char array when it should be a wchar_t array (ie: a 2 byte wide character array for UTF-16 strings).  So the follow should change from this…

   char szFile[260];

…to this…

   wchar_t szFile[260];

And the following line of code needs to change from this…

   ofs.nMaxFile = sizeof(szFile);

…to this…

   ofs.nMaxFile = sizeof(szFile) / sizeof(wchar_t);

…because you are suppose to provide the number of characters in the string array and not the number of bytes.

The rest looks good.  :slight_smile:

ah yeah that makes sense! Good looking out! One more question and I think this issue will be done… How do I access this file path from my corona app now? lol Or could I send a base64 encoded string instead of the file path… What do you think?

Good question.  Yeah, our display.newImage() API does not support loading files outside of Corona’s sandboxed directories such as Resources, Documents, Caches, or Temporary.  As in display.newImage() won’t accept absolute paths.  Only relative paths which are relative to one of these sandboxed directories.  So, the only option at the moment is to copy the file to one of these sandboxed directories.

This can be done in Lua by using the file io APIs.  Or in C by using the Win32 CopyFileW() function…

   https://msdn.microsoft.com/en-us/library/windows/desktop/aa363851(v=vs.85).aspx

If you need to create a subdirectory, then you can do so in Lua via the lfs.mkdir() function…

   https://docs.coronalabs.com/api/library/lfs/index.html

Or in C, you can use the Win32 SHCreateDirectoryExW(NULL, L"<MyDirectoryPath>", NULL) function…

   https://msdn.microsoft.com/en-us/library/windows/desktop/bb762131(v=vs.85).aspx

Ok so I managed to get the path to the TemporaryFiles dir for the app. I think. Which is located in the AppData/Local/company name/app name/TemporaryFiles folder. But the copyfile funciton is not putting it there. Here is my poorly written c code :slight_smile:

if (GetOpenFileName(&ofn) == TRUE) { TCHAR szPath[MAX\_PATH]; if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL\_LOCAL\_APPDATA, NULL, 0, szPath))) { auto utf8String = CreateUtf8StringFrom(szPath); auto sourceFile = CreateUtf8StringFrom(ofn.lpstrFile); char\* appPath = strcat(utf8String, "\\Tartar Sauce Media, LLC\\TabletDemo2\\TemporaryFiles\\somefile.png"); CopyFile(sourceFile, appPath, FALSE); } }

I don’t receive any errors and no file is copied. Any ideas?

I decided to go with Lua’s io Api. It works and was easier to figure out! Yet, I still would like to know why C’s copyfile function would not work.

First, the strcat() function call you are doing is dangerous.  It’s writing past the bounds of the utf8String array and will trash memory.  This is because the CreateUtf8StringFrom() function creates a char array just long enough to hold all of the characters it needs, leaving no room for string concatenation.  I’ll bet it’s turning your appPath into an invalid path because it’s not null terminated where you expect it to be.

It might be easier to return the absolute path to Lua and do the file copy from there.  This is because you don’t have easy access to Corona’s sandboxed directory paths at the moment on the C/C++ side.  Lua’s standard file io APIs can work with paths outside of Corona’s sandboxed directories.  We provide example code on how to copy a file here…

   https://docs.coronalabs.com/guide/data/readWriteFiles/index.html#copying-files-to-subfolders

And if you need to create a subdirectory, then you can use Lua’s lfs.mkdir() function as shown here…

   https://docs.coronalabs.com/api/library/lfs/index.html#working-with-directories

Now, if you don’t want to do the above in Lua and handle it on the C/C++ side, then it’s going to be a bit more work, but it’s definitely possible.  Your Lua code would have to pass in either a destination directory path to your C function or the base directory constant (ie: system.DocumentsDirectory, system.CachesDirectory, etc.).  The following link shows you how our “pasteboard” plugin does it by passing in a Corona base directory constant.  This is how we normally do it for “official” plugins that we would make publically available.  The trick is that your C/C++ code will have to call the Lua system.pathForFile() function, which is what the link below will show you.  Or you could keep it simple and do it on the Lua side like I mentioned above.  It’s up to you.  :slight_smile:

   https://github.com/coronalabs/plugins-source-pasteboard/blob/master/ios/Plugin/pasteboardPlugin.mm#L255

Thanks for the info! I’m keeping it simple and going with lua io API!