locked
Providing 3rd party library with file name

    Question

  • Hi

    I am using a 3rd party library in my app that requires me to pass an image file path to a function. However it seems that it doesn't work if I just pass the path directly in metro style apps.

    I though I should use FilePicker to pick a file name and then pass it but I am not sure and also don't know how to convert from Platform::String^ to const char*.

    Please help. 

    Thursday, June 21, 2012 9:58 AM

Answers

  • Hi MyMSDN23,

    A path probably won't help you here. Your app has direct access to files only in its install and application data directories. Your 3rd party library won't be able to open a file elsewhere by path.

    The FilePicker provides brokered access to other locations. The broker will open and read the file for you and provide the data as a stream in the StorageFile returned by the FileOpenPicker. Your app can get the data via the stream, but can't see the actual file.

    Ideally you could pass a stream or StorageFile to the 3rd party library. If it cannot be modified to accept that then you could copy the image to your app's temporary directory and then pass the path to that location. Also beware that a library written with assumptions that it can manipulate the file system may make other calls which aren't permitted to Metro style apps. Test out the library with the Windows App Cert Kit in a simple app to make sure it can pass.

    --Rob

    • Marked as answer by MyMSDN23 Wednesday, June 27, 2012 8:59 AM
    Friday, June 22, 2012 2:45 AM
    Owner

All replies

  •  

    Hello,

     

    You can try these codes:

     

    	// Set up a string to convert
    String^ str = ref new String(L"Lorem ipsum dolor sit amet\r\n");
            // Allocate enough space for the new string
    	int cb = WideCharToMultiByte(CP_UTF8,0,str->Data(),-1,nullptr,0,nullptr,nullptr);
    	char* sz = new char[cb];
    	
    	// Convert it to UTF-8
    	if (WideCharToMultiByte(CP_UTF8,0,str->Data(),-1,sz,cb,nullptr,nullptr) > 0)
    	{
    		OutputDebugStringA(sz);
    	}

    From these threads

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/42204844-15ef-4b4f-84d4-8355e7e647cf

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/c39b3060-0c2d-40b7-aa8c-035f1fad441c

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 22, 2012 2:25 AM
  • Hi MyMSDN23,

    A path probably won't help you here. Your app has direct access to files only in its install and application data directories. Your 3rd party library won't be able to open a file elsewhere by path.

    The FilePicker provides brokered access to other locations. The broker will open and read the file for you and provide the data as a stream in the StorageFile returned by the FileOpenPicker. Your app can get the data via the stream, but can't see the actual file.

    Ideally you could pass a stream or StorageFile to the 3rd party library. If it cannot be modified to accept that then you could copy the image to your app's temporary directory and then pass the path to that location. Also beware that a library written with assumptions that it can manipulate the file system may make other calls which aren't permitted to Metro style apps. Test out the library with the Windows App Cert Kit in a simple app to make sure it can pass.

    --Rob

    • Marked as answer by MyMSDN23 Wednesday, June 27, 2012 8:59 AM
    Friday, June 22, 2012 2:45 AM
    Owner