在IDL中使用mscorlib [英] Using mscorlib in IDL

查看:116
本文介绍了在IDL中使用mscorlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试在IDL文件中描述我的非托管接口.非托管接口接受托管类(当前,我只需要mscorlib.tlb中的_Type和_Object).虽然使用#import"mscorlib.tlb"可以正常工作,但我在IDL中描述代理存根的接口时遇到了一些问题.

当MIDL编译器成功解析IDL时,创建的文件MyLibrary_h.h和MyLibrary_p.c出现了问题.它报告_Type未知(显然是因为没有要包含的mscorlib.h).

但是我如何描述我的接口具有从mscorlib接受_Type *的功能?


现在的问题有所不同.我使用OleView.exe从mscorlib.tlb创建mscorlib.idl.我使用MIDL从mscorlib.idl创建了一个mscorlib.h.在我的IDL中,我现在引用mscorlib.tlb,并添加了#pragma midl_echo("include \"mscorlib.h\"").使用此设置,我可以创建我的代理存根,并在我的.NET应用程序中正确识别它.现在的问题是,当我调用此函数时,.NET应用程序中出现访问冲突.从我所看到的,这种访问冲突是在调用COM服务器中的函数之前引发的,所以我认为封送程序中的某些问题出了问题.是一些代码:
IDL:

Hello everyone,

Im trying to describe my unmanaged interface in an IDL file. The unmanaged interface accepts managed classes (currently i only need _Type and _Object from mscorlib.tlb). While this works using #import "mscorlib.tlb" i have some problems describing my interface in the IDL for the proxy stub.

While the MIDL-compiler successfully parses the IDL i get problems with the created files MyLibrary_h.h and MyLibrary_p.c. It reports that _Type is not known (obviously because there is no mscorlib.h to include).

But how i can i describe my interface that has a function accepting a _Type* from mscorlib?


The problem is now differently. I used OleView.exe to create the mscorlib.idl from the mscorlib.tlb. Using MIDL i created a mscorlib.h from the mscorlib.idl. In my IDL i am now referencing mscorlib.tlb and i have add #pragma midl_echo("include \"mscorlib.h\""). With this settings i can create my proxy stub and in my .NET-application its correctly recognized. The problem is now that i get an access violation in my .NET-application when i call this function. From what ive seen this access violation is raised before the function in the COM-server is called, so i guess something in the marshaler is going wrong. Is some code:
IDL:

import "oaidl.idl";
import "ocidl.idl";

#pragma midl_echo("#include \"mscorlib.h\"")

[
	uuid(0C585DAB-10CE-4DE6-ABB7-573035CFDAC1),
	version(1.0),
]
library MyAppLib
{
	importlib("mscorlib.tlb");
	importlib("stdole2.tlb");

	[
		version(1.0),
		uuid(1355F0EF-E4DC-4EA5-933F-1B97CE5E2205),
	]
	interface IMyApp : IUnknown {
		[id(1)] HRESULT GetManagedPlugin(_Type* srcType, [out, retval] _Object** ppObject);
	};

	[
		uuid(306DA534-F4F6-4FCC-885E-3D0605EDCA6C)
	]
	coclass MyApp
	{
		[default] interface IMyApp;
	};
};



以及COM-Server中的接口:



And the interface in the COM-Server:

class __declspec(uuid("{1355F0EF-E4DC-4EA5-933F-1B97CE5E2205}"))
IMyApp : public IUnknown
{
public:
	virtual HRESULT STDMETHODCALLTYPE GetManagedPlugin(mscorlib::_Type* pType, mscorlib::_Object** ppObject) = 0;
};



和.NET客户端:



And the .NET-client:

MyApp wp = new MyApp();
wp.GetManagedPlugin(typeof(int)); // <-- Access violation



任何帮助将不胜感激,
Regner



Any help would be appreciated,
Regner

推荐答案

是否可以像不将srcType 声明为[in]一样简单?
could it be something as simple as not declaring srcType as [in] ?


这篇关于在IDL中使用mscorlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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