tlbimp.exe将HWND转换为_RemotableHandle [英] tlbimp.exe converts HWND to _RemotableHandle

查看:77
本文介绍了tlbimp.exe将HWND转换为_RemotableHandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的COM组件接口具有下一个方法:

Our COM component interface has the next method:

HRESULT CreatePluginWindow([in] HWND hParent, [in] RECT* prcView);

我们将在.NET应用程序中使用它,但此接口的互操作看起来像这样:

We are going to use it in .NET application but interop for this interface is looking like this:

void CreatePluginWindow(ref interop.alfrontx._RemotableHandle hParent, ref interop.alfrontx.tagRECT prcView)

根据我的调查,没有不安全的代码就无法使用此方法。
我不想更改COM接口以便将hParent使用HWND类型以外的其他类型,因为它已在许多C ++组件中使用。
我不想在互操作中进行更改,因为它们会在每次构建时自动编译。

According my investigation there is no way to use this method without unsafe code. I'd not like to change COM interface in order to use other than HWND type for hParent, because it's used in many C++ components. I'd not like to make changes in interop because they are compiled automatically on each build.

还有其他方法可以解决此问题吗?

Is there any other way to solve this problem?

推荐答案

不是Tlbimp这样做,这是在构建非托管COM服务器时由midl.exe注入的。窗口句柄是一个互操作障碍,因为它是32位程序中的32位值和64位程序中的64位值。像所有句柄一样。

It is not Tlbimp that does this, this was injected by midl.exe when you built the unmanaged COM server. A window handle is an interop obstacle because it is a 32-bit value in a 32-bit program and a 64-bit value in a 64-bit program. Like all handles.

看看Windows SDK include目录中的wtypes.idl文件,您会在此处找到_RemotableHandle。再往下看,您将看到将HWND映射到RemotableHandle的#define:

Take a look at the wtypes.idl file in the Windows SDK include directory, you'll find _RemotableHandle declared there. A bit further down, you'll see the #define that maps the HWND to a RemotableHandle:

#ifndef _MIDL_DECLARE_WIREM_HANDLE
DECLARE_WIREM_HANDLE( HWND );
// etc..
#endif

据我所知,将/ D _MIDL_DECLARE_WIREM_HANDLE传递给midl.exe时,您将获得一个没有RemoteHandle包装器的类型库。坦白地说,我不太了解这应该如何工作。

As near as I can tell, when you pass the /D _MIDL_DECLARE_WIREM_HANDLE to midl.exe then you'll get a type library without the RemoteHandle wrapper. Admittedly I don't really understand how this is supposed to work.

这篇关于tlbimp.exe将HWND转换为_RemotableHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆