问题描述
大家好,
现在的问题有所不同.我使用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,
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
推荐答案
这篇关于在IDL中使用mscorlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!