| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <xplatform.h> |
| 7 | |
| 8 | LPCWSTR strManaged = W("Managed\0String\0" ); |
| 9 | LPCWSTR strNative = W(" Native\0String\0" ); |
| 10 | |
| 11 | size_t lenstrManaged = 7; // the length of strManaged |
| 12 | size_t lenstrNative = 7; //the len of strNative |
| 13 | |
| 14 | extern "C" DLL_EXPORT bool STDMETHODCALLTYPE MarshalStringPointer_InOut(/*[in,out]*/LPWSTR *s) |
| 15 | { |
| 16 | //Check the Input |
| 17 | size_t len = wcslen(*s); |
| 18 | if((len != lenstrManaged)||(wcsncmp(*s,strManaged, lenstrManaged)!=0)) |
| 19 | { |
| 20 | printf("Error in Function MarshalStringPointer_InOut\n" ); |
| 21 | |
| 22 | //Expected |
| 23 | printf("Expected:" ); |
| 24 | wprintf(L"%ls" ,strManaged); |
| 25 | printf("\tThe length of Expected:%d\n" ,static_cast<int>(lenstrManaged)); |
| 26 | |
| 27 | //Actual |
| 28 | printf("Actual:" ); |
| 29 | wprintf(L"%ls" ,*s); |
| 30 | printf("\tThe length of Actual:%d\n" ,static_cast<int>(len)); |
| 31 | |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | //Allocate New |
| 36 | CoreClrFree(*s); |
| 37 | |
| 38 | //Alloc New |
| 39 | size_t length = lenstrNative + 1; |
| 40 | *s = (LPWSTR)CoreClrAlloc(length * sizeof(WCHAR)); |
| 41 | memset(*s,'\0',length * sizeof(WCHAR)); |
| 42 | wcsncpy_s(*s,length,strNative,lenstrNative); |
| 43 | |
| 44 | //Return |
| 45 | return true; |
| 46 | } |
| 47 | |