locked
How do I modify my code to work ?

    Question

  •         void  SimpleTextRenderer::libgetclick()
            {
     int wurd;
                int cx, dx;
    
    	FileOpenPicker^ openPicker = ref new FileOpenPicker();
        openPicker->ViewMode = PickerViewMode::Thumbnail;
    	openPicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
        openPicker->FileTypeFilter->Append(".slb");
    
    	create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
            {
                if (file)
                {
                 create_task(file->OpenAsync(FileAccessMode::Read)).then([this, file](IRandomAccessStream^ readStream){
    	
    		DataReader^ dr = ref new
    		DataReader(readStream); //requires input stream
    
    
    
    		create_task(dr->LoadAsync((UINT)readStream->Size));
    			  
    		int cx,di,si,wurd;	
    		wurd=0;
                di = 1;
    readlp:
                wurd = (UINT16)rev(dr->ReadInt16());
    			        
    				if (wurd == 65535)
                    goto endreadlp;
    
                slibrary[di] = wurd;
                di = di + 1;
    
                //{data. 1 already done!}
                for (cx = 1; cx <= (schdefdatawidth - 1); cx++)
                {
                    wurd = (UINT16)rev(dr->ReadInt16());
                    slibrary[di] = wurd;
                    di = di + 1;
                }
    
    
    
                //{name}
            repeat9:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 255)
                    goto repeat9;
    
    
    
                //{tracks}
            repeat10:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 65535)
                    goto repeat10;
    
    
            //{text}
            textlp:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd == 65535)
                    goto endtextlp;
    
                for (cx = 1; cx <= (textdatawidth - 1); cx++)
                {
                    wurd = (UINT16)rev(dr->ReadInt16());
                    slibrary[di] = wurd;
                    di = di + 1;
                }
    
            repeat12:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 255)
                    goto repeat12;
    
    
                goto textlp;
            endtextlp:
    
                //{pads}
            repeat13:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 65535)
                    goto repeat13;
    
    
            //{connections}
            conlp:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd == 65535)
                    goto endconlp;
    
                for (cx = 1; cx <= (SCHCONDATAWIDTH - 1); cx++)
                {
                    wurd = (UINT16)rev(dr->ReadInt16());
                    slibrary[di] = wurd;
                    di = di + 1;
                }
    
            repeat14:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 255)
                    goto repeat14;
    
    
                goto conlp;
            endconlp:
    
                //{sepers}
            repeat15:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 65535)
                    goto repeat15;
    
    
    
                //{refs}
            repeat16:
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                if (wurd != 65535)
                    goto repeat16;
    
    
    
                // {sub symbol delimiter}
                wurd = (UINT16)rev(dr->ReadInt16());
                slibrary[di] = wurd;
                di = di + 1;
                goto readlp;
    
            endreadlp:
                slibrary[di] = 65535; //{end marker}
                //result = 1;//{loaded ok}
    			  });
                }
                else
                {
                    ;
                }
            });
        	
    auto boxOK =
            ref new Windows::UI::Popups::MessageDialog("Loaded ok");
        boxOK->ShowAsync();
    
    
    	
    
    
    
    
    
    
    
    		}


    n.Wright

    Friday, June 22, 2012 11:44 PM

Answers

  • I eventually found a code snippet online that worked.

    My problems were compounded by using messageboxes that were running async and interfering with the disc system.


    n.Wright

    • Marked as answer by Jesse Jiang Wednesday, July 04, 2012 7:25 AM
    Thursday, June 28, 2012 12:23 AM

All replies

  • What is the problem with your code?

    Saturday, June 23, 2012 6:11 PM
  • What is the problem with your code?

    It keeps crashing out with exceptions.

    Access denied to memory location.


    n.Wright

    Saturday, June 23, 2012 8:16 PM
  • Ok, A couple of issues:

    1) make sure you have a continuation after: create_task(dr->LoadAsync((UINT)readStream->Size));

    That's an async operation.

    Something like:

            return dr->LoadAsync((unsigned int) stream->Size);

        }).then([this, dr] (task<unsigned int> bytesLoaded)

        {

                   

    2) Try to refactor your code, it is very difficult to follow it. Get rid of all those gotos
    3) Make sure the the value of 'di' is in range when accessing 'slibrary' by index: slibrary[di]

    Monday, June 25, 2012 6:12 AM
  • I eventually found a code snippet online that worked.

    My problems were compounded by using messageboxes that were running async and interfering with the disc system.


    n.Wright

    • Marked as answer by Jesse Jiang Wednesday, July 04, 2012 7:25 AM
    Thursday, June 28, 2012 12:23 AM