microsoft / xlang

MIT License
875 stars 103 forks source link

can not find the _winrt.pyd #753

Closed cjw1115 closed 1 year ago

cjw1115 commented 3 years ago

When I try to build the pywinrt.exe myself, I didn't get the file _winrt,pyd. Then I download the latest winrt in pip, the package contains the _winrt.pyd.

So I have two questions

  1. how _winrt.pyd is generated?
  2. Can I use pywinrt.exe to convert my own winrt component so that I can use it in python?

Thanks

dlech commented 3 years ago

Here is how I build the bindings:

  1. Build the bindings generator (pywinrt.exe). This is a program that generates C++ code based on WinRT metadata.

    cd src\scripts\windows
    vsdevcmd-build.cmd
  2. Set up a VS 2019 x64 dev environment in Power Shell.

    Import-Module "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
    Enter-VsDevShell -VsInstallPath "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community" -DevCmdArguments '-arch=x64'
  3. In the dev environment, run the generate and build scripts.

    cd src\package\pywinrt\projection
    .\generate.ps1
    .\build.ps1

generate.ps1 uses cppwinrt.exe (from NuGet) and pywinrt.exe (that we built) to generate C++ code that gets compiled by the build.ps1 script.

There is a -fullProjection argument for generate.ps1 to build all of the WinRT modules, otherwise just a select few are built.

I'm not sure what would be required to bind your own component, but if cppwinrt can do it, pywinrt can probably do it too.

cjw1115 commented 3 years ago

Thank you @dlech Now I can build the whole py/winrt module on my device, got a correct _winrt.pyd. And I also try to call some winrt API from my test python script, it works well!

cjw1115 commented 3 years ago

Under the help of @dlech , I can projection my own winmd file, it works. But a expected error "Class not registered" is thrown in runtime. In win32 or .Net framework project, we can try to add manifest to indicate our COM dll, but in python, I don't know how to do that. Do you have any idea? Thanks!

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days.