microsoft / win32metadata

Tooling to generate metadata for Win32 APIs in the Windows SDK.
Other
1.32k stars 113 forks source link

Function entrypoint Apis missing from winmd #1880

Closed TheRealColeB closed 5 months ago

TheRealColeB commented 5 months ago

I'm trying to generate winmd for my own api. Right now I'm just testing the waters by following the pattern in the post by Rafael (https://withinrafael.com/2023/01/18/generating-metadata-for-the-windows-crate), and applying it to generate a winmd for a simple header that just contains

struct Test {
    int a;
    int b;
    int c;
};

EXTERN_C int TestApi(Test* test);

But when I generate the winmd and look at it in ILSpy, the TestApi entry point is missing. I found that I can see the TestApi entry point in the intermediate file obj\generated\x64\Test.cs:

    public static unsafe partial class Apis
    {
        [DllImport("", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
        public static extern int TestApi(Test* test);
    }

But there is another file, obj\generated\obj\crossarch\x86\Test.modified.cs, in which the expected api is missing:

    public static unsafe partial class Apis
    {
    }

Can someone point me to where I may be going wrong here?

riverar commented 5 months ago

Hey @colebtest, I wrote that post. Any/all feedback is greatly appreciated.

This is a common gotcha. For better or worse, the build tooling quietly drops functions that cannot be mapped to dlls. If you don't have an import lib for TestApi that you can feed into the tooling, you can manually associate the two.

Assuming you're using the structure outlined in the blog post, create or modify options.rsp in your .metadata directory and add:

--with-librarypath 
TestApi=Test.dll
TheRealColeB commented 5 months ago

Thanks @riverar! I was able to use that option to get past this hurdle. I will probably have more questions as I make more progress, but I'll close this issue now.