Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: any guidance on creating bindings from c and other languages? #18

Closed
carlokok opened this issue May 19, 2020 · 9 comments
Closed
Labels
area-Projections Request for support of a runtime or language

Comments

@carlokok
Copy link

I see there are bindings for JavaScript, rust and c++. What about languages that want to support this that aren't officially supported? Are there ways to use the new apis from c(which all languages can work from) or any info on how it fits together internally?

@jonwis
Copy link
Member

jonwis commented May 19, 2020

Ideally we'd like both Project Reunion and the Windows API surface to be metadata defined so we can do projections to any language. We're planning using MIDL3 / WinMD to define new Project Reunion APIs so that'll snap into the existing projections. While C++/WinRT is super awesome I'm aware of projects that either cannot use exceptions & C++17 or decide not to.

@kennykerr and @Scottj1s are building out projections - we've heard the request for a "flat C" or "C++ without exceptions" projection before, especially for very low-level components.

Can you create an issue-per-target-language that you're interested in, along with a little sample snippet of what that projection would look like for an API like this:

runtimeclass StartupTask
{
    static StartupTask[] GetStartupTasks();
    static StartupTask GetById(String taskId);

    StartupTaskState State { get; };
    String TaskId { get; };

    void Disable();
    IAsyncOperation<StartupTaskState> RequestEnableAsync();
}

@carlokok
Copy link
Author

So this was coming from my own languages (RemObjects elements native target). The.midl3 stuff you mentioned will be very useful to me, or really any sample in pure c will already be fantastic.

At some point I looked at the winrt header files, but I had trouble finding good non c++ samples.

@mdtauk
Copy link

mdtauk commented May 19, 2020

There is the Xlang project which is doing similar things.

It would be useful for non-windows developers to be able to use Swift or Kotlin to make apps. Maybe even Java and TypeScript - whilst still using XAML for UI

@jonwis
Copy link
Member

jonwis commented May 19, 2020

Check out https://docs.microsoft.com/en-us/samples/microsoft/windows-appsample-photo-editor/photo-editor-cwinrt-sample-application/ for a pretty neat complete sample of using C++/WinRT.

While it's not easy to make projections, the tooling in both xlang and the cppwinrt repos can help. Filing issues in this repo for each language you want projected and then bumping them will help us prioritize!

Just answering my own question, the startup task object could be represented as...

DECLARE_HANDLE(R_AM_STARTUPTASK);
STDAPI StartupTaskGetById(_In_ PCWSTR taskId, _Outptr_ R_AM_STARTUPTASK* result);
STDAPI_(VOID) CloseStartupTask(_In_opt_ R_AM_STARTUPTASK task);
STDAPI GetStartupTaskState(_In_ R_AM_STARTUPTASK task, R_Am_StartupTaskState* state);
STDAPI GetStartupTaskTaskId(_In_ R_AM_STARTUPTASK task, _Outptr_ PWSTR* result);
STDAPI StartupTaskDisable(_In_ R_AM_STARTUPTASK task);
STDAPI StartupTaskRequestEnable(_In_ R_AM_STARTUPTASK task, _Inout_ ReunionAsync* async);
STDAPI StartupTaskRequestGetResult(_In_ ReunionAsync* async, _Out_ R_Am_StartupTaskState*);

@jonwis
Copy link
Member

jonwis commented May 19, 2020

Also, note that you can use WinMDs and MIDL3 directly from your C code.

  1. Right-click the IDL file, Properties
  2. Under "MIDL > Output" set the "Header file" to $(IntDir)\%(FileName).h
  3. Apply settings
  4. Add #include "FileName.h" to your C code
  5. Use the CINTERFACE definitions. IFoo is a structure containing a __x_ABI_CFoo_CIFooVtbl* lpVtbl with members for each method visible on IFoo

This is of course why we like projections - they're easier for you to program against. :)

@pjmlp
Copy link

pjmlp commented May 19, 2020

@jonwis Regarding MIDL3, I dearly miss C++/CX when dealing with the lack of tooling currently available. Currently porting one DirectX sample from C++/CX to C++/WinRT is an exercise in masochism.

So it would be nice that in the context of opening binding creation to other language communities there would be some thought in actually making it a painless exercise instead of reviving ATL memories.

@jonwis jonwis added the area-Projections Request for support of a runtime or language label May 20, 2020
@carlokok
Copy link
Author

Thanks this is all very useful information. I'm going to play with it and see how far I can get.

@ilqvya
Copy link

ilqvya commented May 21, 2020

Will Win32api be deprecated?

@jonwis
Copy link
Member

jonwis commented May 22, 2020

Will Win32api be deprecated?

No - your app can continue to use Win32 APIs. Project Reunion brings new unified APIs and new functionality. We're considering a partitioning of the Windows Kit much like the _APP partition to help code that stays within the partition be nearly "Project Reunion Family" ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Projections Request for support of a runtime or language
Projects
None yet
Development

No branches or pull requests

5 participants