locked
GetEndpointPairsAsync invalid parameter?

    Question

  • I am getting "Unhandled exception at 0x5DCF4E4e (msvcr1103d.dll) in RakNet_WindowsStore8_VS20212.exe: An invalid parameter was passed to a function that considers invalid parameters fatal."

    What am I doing wrong?

    Code:

    DatagramSocket ^listener = ref new DatagramSocket();
    HostName ^hostName = ref new HostName(ref new Platform::String(L"microsoft.com"));
    task< Windows::Foundation::Collections::IVectorView<EndpointPair^>^ > op(listener->GetEndpointPairsAsync(hostName, L"0"));
    op.wait();
    Windows::Foundation::Collections::IVectorView<EndpointPair^>^view = op.get();
    if (view->Size>0)
    {
    Platform::String ^name = view->GetAt(0)->RemoteHostName->DisplayName;
    RakString rs2;
    rs2.FromWideChar(name->Data());
    strcpy(ip, rs2.C_String());
    }
    else
    {
    ip[0]=0;
    }

    Monday, January 7, 2013 9:08 PM

Answers

  • Hi,

    We should not use wait function in Windows Store UI thread, the UI thread cannot be block. I change it with .then and it works fine on my side.

    	DatagramSocket ^listener = ref new DatagramSocket();
    	HostName ^hostName = ref new HostName(ref new Platform::String(L"microsoft.com"));
    	task< Windows::Foundation::Collections::IVectorView<EndpointPair^>^ >(listener->GetEndpointPairsAsync(hostName, L"0")).then(
    		[this](task< Windows::Foundation::Collections::IVectorView<EndpointPair^>^> previousTask)
    	{
    		try
    		{
    			Windows::Foundation::Collections::IVectorView<EndpointPair^>^view=previousTask.get();
    			if (view->Size>0)
    			{
    				Platform::String ^name = view->GetAt(0)->RemoteHostName->DisplayName;
    	
    			}
    			else
    			{
    				
    			} 
    
    		}
    		catch(Exception^ exception){
    		}
    
    	}
    	);
    

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, January 14, 2013 2:37 AM
    Wednesday, January 9, 2013 3:20 AM