-
Notifications
You must be signed in to change notification settings - Fork 55
Generate rust code from IDL/TLB/COM dll? #216
Comments
We're currently doing some work to figure out the future of this library and its role in the Windows Rust ecosystem along with windows-rs. This is something we would most likely eventually support, but it's unlikely to be something we could add anytime soon (due to lack of development and review bandwidth). Unfortunately, for now you'll have to write the interfaces manually. |
The Windows crate is beginning to provide this capability. You can provide a https://github.com/microsoft/windows-rs/tree/master/tests/component |
So it will be merged with windows-rs eventually or it will become unmaintained?
I think generating from TLB would provide more value as not all COM libraries come with C/C++ headers. There are also COM libraries that were written in C#. |
The |
That's where the trouble begins. I mostly use C# when I need to interact with some COM library. I just add The github page for the generator also mentions it's exclusively to generate metadata for Windows API and not for any other third party COM libraries registered on your system. What would be needed is something like EDIT: just tried to use winmdexp on generated COM interop assembly for .NET but it didn't work. Many errors. Classic ActiveX/COM libs differ a bit from WinRT |
I would also like to be able to generate .rs code directly from the .idl file. |
I'm still looking into this for https://github.com/microsoft/windows-rs |
For what it's worth, huge shout-out already to Isn't it already possible to go from IDL -> .h -> .winmd -> Rust? |
With some effort. I'm hoping to streamline the process to only require the Rust toolchain. |
I tried: https://github.com/microsoft/windows-rs/blob/master/crates/tests/component/src/component.idl |
Does someone has a simple example/code to generate a I try to look at Rafael Rivera post, but for the moment I didn't success to generate an |
@Wawha Hey there! I'd be interested in any feedback you have on the article. (I wrote it.) Here's a sample/skeleton project that generates Rust bindings from Microsoft IDL (https://github.com/riverar/washington-rs). Specifically, the sample demonstrates taking IDL, generating metadata with WinmdGenerator, and using windows_bindgen to generate bindings for use in a Rust crate. |
@kennykerr thank you. Unfortunately, I was not able to generate Rust code with the samples "components", because my COM idl was to complicated. But using the project washington-rs from @riverar, I finally succeed to do it! |
@riverar Hi! I have two .idl files: I tried following your article + "washington" repo, but I'm running into a issue where only the types in My <?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.Windows.WinmdGenerator/0.62.23-preview">
<PropertyGroup Label="Globals">
<OutputWinmd>../.windows/winmd/My.Project.winmd</OutputWinmd>
<WinmdVersion>255.255.255.255</WinmdVersion>
<Idl>./idl</Idl>
<AdditionalIncludes>$(CompiledHeadersDir);$(Idl)</AdditionalIncludes>
</PropertyGroup>
<ItemGroup>
<Idls Include="$(Idl)/service.idl;$(Idl)/base.idl" />
<Headers Include="$(CompiledHeadersDir)/service.h;$(CompiledHeadersDir)/base.h" />
<Partition Include="main.cpp">
<TraverseFiles>@(Headers)</TraverseFiles>
<Namespace>My.Project</Namespace>
<ExcludeFromCrossarch>true</ExcludeFromCrossarch>
<ShowEmitWinmdOutputDetails>true</ShowEmitWinmdOutputDetails>
</Partition>
</ItemGroup>
</Project>
Any ideas? |
This comment was marked as outdated.
This comment was marked as outdated.
@NuSkooler In this case, because of missing inherited -interface MyService {
+interface MyService: IUnknown {
HRESULT MyMethod(
handle_t hbind,
[out] PCONTEXT* phContext
);
}; |
@riverar Thanks for jumping on this so quick! I'm not a COM expert by any means, so I might be misunderstanding something here: The When I add |
This comment was marked as outdated.
This comment was marked as outdated.
@NuSkooler Here's an RPC example: base.idl: import "wtypesbase.idl";
[
uuid(6e3125bb-9df7-4c8c-976c-0b5626bc8194),
version(1.0)
]
interface IBase {
HRESULT BaseMethod();
}; libmappings.rsp (put next to the .proj file):
winmd output: // ...
[DllImport("base_client.dll", ExactSpelling = true, PreserveSig = false)]
public unsafe static extern HRESULT BaseMethod([In][Out] void* IDL_handle); As shown above, you still have the responsibility of compiling the MIDL-generated client stubs (e.g. |
Is there any way to interact with COM API without writing any code manually? In .NET I can just reference COM library and I can use it without writing any code. IIRC there is also a .dll generator for COM libraries made in C++ - Tlbimp.exe. Is such scenario supported with com-rs or do I always need to manually translate everything to Rust (
com::interfaces!
macro) before I'm able to call any method?I think it's related but it's not TBL but TLB... #114
The text was updated successfully, but these errors were encountered: