SharpGenTools / SharpGen.Runtime.COM

COM runtime support for SharpGen generated interop code.
MIT License
13 stars 7 forks source link

CoreRT compile failed #6

Open ryancheung opened 4 years ago

ryancheung commented 4 years ago

I just made a library with SharpGenTools and tried to test corert compiling. It raised the error:

ImeSharp.Demo.obj : error LNK2001: unresolved external symbol WindowsCreateString [D:\TeamIG\ImeSharp\ImeSharp.Demo\ImeSharp.Demo.csproj]
bin\Release\netcoreapp3.1\win-x64\native\ImeSharp.Demo.exe : fatal error LNK1120: 1 unresolved externals [D:\TeamIG\ImeSharp\ImeSharp.Demo\ImeSharp.Demo.csproj]
C:\Users\ryanc\.nuget\packages\microsoft.dotnet.ilcompiler\1.0.0-alpha-29228-02\build\Microsoft.NETCore.Native.targets(331,5): error MSB3073: command“"C:\Program Files (x86)\Microsoft 
Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64\link.exe"  @"obj\Release\netcoreapp3.1\win-x64\native\link.rsp"”Existed,code is 1120。 [D:\TeamIG\ImeSharp\ImeSharp.Demo\ImeSharp.Demo.csproj]

The SharpGen.Runtime.COM package has this file:

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace SharpGen.Runtime.Win32
{
    // Token: 0x0200003D RID: 61
    internal static class WinRTStrings
    {
        // Token: 0x060000D8 RID: 216 RVA: 0x00003F98 File Offset: 0x00002198
        public unsafe static void WindowsCreateString(string sourceString, uint length, out IntPtr text)
        {
            Result result;
            fixed (IntPtr* ptr = &text)
            {
                void* param = (void*)ptr;
                fixed (string text2 = sourceString)
                {
                    char* ptr2 = text2;
                    if (ptr2 != null)
                    {
                        ptr2 += RuntimeHelpers.OffsetToStringData / 2;
                    }
                    result = WinRTStrings.WindowsCreateString_((void*)ptr2, length, param);
                }
            }
            result.CheckError();
        }

        // Token: 0x060000D9 RID: 217
        [DllImport("api-ms-win-core-winrt-string-l1", CallingConvention = 3, EntryPoint = "WindowsCreateString")]
        private unsafe static extern int WindowsCreateString_(void* param0, uint param1, void* param2);
    }
}

It seems the DllImport of WindowsCreateString is wrong?

Has anyone tried compiling with CoreRT?

ryancheung commented 3 years ago

After upgraded to SharpGenTools v2, this is fixed in Native AOT.