任何COM Interop GURUS在那里!? - 带有数组的嵌套结构 [英] ANY COM Interop GURUS out there!? - Nested Structs with arrays of

查看:49
本文介绍了任何COM Interop GURUS在那里!? - 带有数组的嵌套结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题的doozie!我和其他人一直试图把这个

搞得太久了,我得出的结论是,我应该看看

获得一些支持..


好​​吧,我有一个用C ++编写的COM组件(我没有源代码只是

二进制文件)并且是从VB引用的。我会说这个COM组件公开的大约99%的
功能在vb .net上工作得很好但是我在调​​用一个有一个参数的方法时遇到了问题是COM组件中定义的结构

。这个结构有一个成员,它是一个结构

,它包含另一个结构的数组。当我调用该方法时,我收到一个

TypeLoadException,其中包含非常少的细节(这就是它)。这是结构的MSIL

..导致问题的成员(我约99%

肯定)是以list结尾的成员


''我删除了以下所有成员我感觉结构是否正确定义了
(我删除了这个结构的大约19个成员)。这样做是为了简单起见



..class public sequential ansi sealed beforefieldinit tcsGroupAttributes_t

extends [mscorlib] System .ValueType

{

..pack 4

..size 0

..field public valuetype Nokia。 TCSapi.tcsSubscriberAddress_t groupAddress

..field public valuetype Nokia.TCSapi.tcsOrgBlockAttributes2List_t

entryRightsList //这个问题! 99%确定!

} //类结束tcsGroupAttributes_t


''这是tcsOrgBlockAttributes2List的定义

..class公共序列ansi密封beforefieldinit

tcsOrgBlockAttributes2List_t

扩展[mscorlib] System.ValueType

{

..pack 2

..size 0

..field public unsigned int16 length

..field public marshal(fixed array [75])valuetype

Nokia.TCSapi.tcsOrgBlockAttributes2_t [] orgBlockAttributes2List

} //类结束tcsOrgBlockAttributes2List_t


''这是tcsOrgBlockAttributes2_t的定义


..class public sequential ansi sealed beforefieldinit tcsOrgBlockAttributes2_t

extends [mscorlib] System.ValueType

{

..pack 2

..size 0

..field public marshal(fixed array [6])unsigned int16 [] orgBlockId

..field public marshal(fixed array [32])unsigned i nt8 [] orgBlockMnemonic

} //类的结束tcsOrgBlockAttributes2_t


(tcsGroupAttributesMask结构是直截了当且类似的对象

在其他调用中工作,所以这个结构不是问题。它是

tcsGroupAttributes)


..method public hidebysig newslot abstract virtual

instance int32 Create([in] valuetype Nokia。 TCSapi.tcsGroupAttributes_t&

groupAttributes,

[in] valuetype Nokia.TCSapi.tcsGroupAttributesMask_t& groupAttributesMask,

[in] int16 cookie)运行时管理内部呼叫

{

}


这是一个令人难以置信的困难问题,并且对任何可以支持$ b的人都非常尊重$ b帮助或解决这个问题。我已经用Google搜索了**,并且已经阅读了几乎每个讨论COM互操作资源的
。我已经尝试编辑了

反汇编的il并将成员的valuetypes设置为IntPtrs,但后来我得到了一个

MissingFieldException ...提前感谢任何帮助!


Aaron

解决方案

Aaron,

这个结构的成员是一个struct
包含另一个struct的数组。




遗憾的是,编组人员不支持。请参阅

http://dotnetinterop.com/faq/ ?q = StructWithStructArray


Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。


首先,感谢Mattias的回应!我一直注意到你

帮助我们解决问题的海报问题,让我说我们非常感谢你帮助我们的

时间。


关于我的问题,我没有COM组件的源代码,所以我不能更改Struct成员的类型定义。这个dll确实没有导出这些方法,所以,如果我正确理解PInvoke,我就不能使用PInvoke,因为该方法没有导出。所以,根据你所提到的链接中包含的信息,知道我现在知道的是什么,如果我能够使用b $ b来展平结构成员(摆脱数组引用,我会

喜欢这样做,因为我总是只是传入1)这个方法将

完成S_OK。 < - :


所以现在的问题是,是否可以_redefine_在COM组件的命名空间中声明的结构是什么?
?所以我可以打电话给

''伪代码

结构MyNewlyRedefinedGroupAttribute

....

。 ...''将数组结构重新定义为非数组

结束结构

将myNewlyRedefinedGroupAttributes变暗为MyNewlyRedefinedGroupAttribute


能够使用我重新定义的扁平结构而没有得到

没有接受这些参数的界面

(myapp.MyNewlyRedefinedGroupAttribute,Nokia.TCSapi.tcsGroupAttributesMask_t,

int16)"


创建(myNewlyRedefinedGroupAttributes,groupAttributesMask,cookie)


是否可以编辑IL并重新组装或我会得到那个

missingfieldexception吗?


先谢谢Mattias!


Aaron
" Mattias Sj ?? gren"写道:

Aaron,

这个结构有一个成员,它是一个结构
,包含另一个结构的数组。 / blockquote>

不幸的是,编组人员不支持。请参阅

http://dotnetinterop.com/faq/ ?q = StructWithStructArray

Mattias

-
Mattias Sj ?? gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请仅回复新闻组。



换句话说,当我没有

的源代码时,我怎么去_flattening_我的结构?用于更改c ++源代码的COM组件,并执行

重新编译。我可以使用IL或切换到TLBIMP.exe吗?任何

帮助升值!


" Aaron"写道:

首先,感谢Mattias的回应!我注意到你一直在帮助我们解决问题的海报,让我说我们非常感谢你们帮助我们的时间。

关于我的问题,我没有COM组件的源代码,因此无法更改Struct成员的类型定义。这个dll也不会导出这些方法,因此,如果我正确理解PInvoke,我就无法使用PInvoke,因为该方法没有导出。所以,从我所提到的链接中包含的信息知道我现在知道的内容,如果我能够展平结构成员(摆脱数组引用,我会这样做)无论如何,因为我总是只是传入1)这个方法将完成S_OK。 < - :

现在的问题是,是否可以_redefine_在COM组件的命名空间中声明的结构?所以我可以调用
''伪代码
结构MyNewlyRedefinedGroupAttribute
......
......''重新定义数组结构为非数组
结束结构将myNewlyRedefinedGroupAttributes变为MyNewlyRedefinedGroupAttribute

能够使用我重新定义的扁平化结构而不会获得
没有接受这些参数的接口
(myapp.MyNewlyRedefinedGroupAttribute ,Nokia.TCSapi.tcsGroupAttributesMask_t,
int16)"

创建(myNewlyRedefinedGroupAttributes,groupAttributesMask,cookie)

是否可以只编辑IL并重新组装或我会得到那个
missingfieldexception吗?

在此先感谢Mattias!

Aaron
Mattias Sj ?? gren写道:

Aaron,

这个结构有一个成员,它是一个结构
,包含另一个结构的数组。 / blockquote>

不幸的是,编组人员不支持。请参阅

http://dotnetinterop.com/faq/ ?q = StructWithStructArray

Mattias

-
Mattias Sj ?? gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请仅回复新闻组。



I''ve got a doozie of a problem! I and others have been trying to figure this
out for too long and I''ve come to the conclusion that I should probably look
for some support..

Ok, I have a COM component written in C++ (I don''t have the source just the
binary) and am referencing it from VB. I would say about 99% of the
functionality exposed by this COM component works fine from vb .net but I am
having a problem calling a method which has a parameter that is a struct
defined in the COM component. This struct has a member which is a struct
which contains an array of another struct. When I call the method I receive a
TypeLoadException with very little detail (thats about it) Here is the MSIL
for the structures.. The members who are causing the problems (i am about 99%
sure) are the members that end in "list"

''I have removed all of the members of the following struct who I feel are
defined correctly (i removed about 19 members of this struct). This is done
for the sake of simplicity

..class public sequential ansi sealed beforefieldinit tcsGroupAttributes_t
extends [mscorlib]System.ValueType
{
..pack 4
..size 0
..field public valuetype Nokia.TCSapi.tcsSubscriberAddress_t groupAddress
..field public valuetype Nokia.TCSapi.tcsOrgBlockAttributes2List_t
entryRightsList //THIS GUYS THE PROBLEM! 99% SURE!
} // end of class tcsGroupAttributes_t

'' Here is the definition of tcsOrgBlockAttributes2List
..class public sequential ansi sealed beforefieldinit
tcsOrgBlockAttributes2List_t
extends [mscorlib]System.ValueType
{
..pack 2
..size 0
..field public unsigned int16 length
..field public marshal( fixed array [75]) valuetype
Nokia.TCSapi.tcsOrgBlockAttributes2_t[] orgBlockAttributes2List
} // end of class tcsOrgBlockAttributes2List_t

''Here is the definition of tcsOrgBlockAttributes2_t

..class public sequential ansi sealed beforefieldinit tcsOrgBlockAttributes2_t
extends [mscorlib]System.ValueType
{
..pack 2
..size 0
..field public marshal( fixed array [6]) unsigned int16[] orgBlockId
..field public marshal( fixed array [32]) unsigned int8[] orgBlockMnemonic
} // end of class tcsOrgBlockAttributes2_t

Ok, Here is the signature of the method that I am calling
(tcsGroupAttributesMask structure is straightforward and similiar objects
work in other calls so this structure is not the problem. Its the
tcsGroupAttributes)

..method public hidebysig newslot abstract virtual
instance int32 Create([in] valuetype Nokia.TCSapi.tcsGroupAttributes_t&
groupAttributes,
[in] valuetype Nokia.TCSapi.tcsGroupAttributesMask_t& groupAttributesMask,
[in] int16 cookie) runtime managed internalcall
{
}

This is an incredibley difficult problem and much respect to anyone that can
help or solve this. I have googled the ** out of this and have read nearly
every resource out there discussing COM interop. I have tried editing the
disassembled il and setting the member valuetypes to IntPtrs but then I get a
MissingFieldException.. Appreciate any help in advance!

Aaron

解决方案

Aaron,

This struct has a member which is a struct
which contains an array of another struct.



That''s unfortunately not supported by the marshaler. See

http://dotnetinterop.com/faq/?q=StructWithStructArray

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


First of all, thanks for the response Mattias! I notice you consistently
help us problem ridden posters and let me just say we really appreciate the
time you take helping us.

Regarding my issue, I don''t have the source code for the COM component so am
unable to change the type definitions for the Struct members. This dll does
not export these methods either, so, if I understand PInvoke correctly, I am
unable to use PInvoke since the method isn''t exported. So, knowing what I
know now from the info contained in the link you referred to, if I were able
to flatten the struct members (get rid of array references, which I would
like to do anyways since I am always just passing in 1) this method would
complete S_OK. <- :s

So the question now is, is it possible to _redefine_ a structure which is
declared in the namespace of the COM component? So I would be able to call
''pseudo code
Structure MyNewlyRedefinedGroupAttribute
....
.... '' redefine the array structure to be non-arrays
end structure
Dim myNewlyRedefinedGroupAttributes as MyNewlyRedefinedGroupAttribute

Be able to use my redefined flattened structure without getting
"There is no interface that accepts these parameters
(myapp.MyNewlyRedefinedGroupAttribute, Nokia.TCSapi.tcsGroupAttributesMask_t,
int16)"

Create(myNewlyRedefinedGroupAttributes, groupAttributesMask, cookie)

Is it possible to just edit the IL and reassemble or will I get that
"missingfieldexception"?

Thanks in advance Mattias!

Aaron
"Mattias Sj??gren" wrote:

Aaron,

This struct has a member which is a struct
which contains an array of another struct.



That''s unfortunately not supported by the marshaler. See

http://dotnetinterop.com/faq/?q=StructWithStructArray

Mattias

--
Mattias Sj??gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



In other words, how do I go about _flattening_ my structure when I don''t have
the source code for the COM component to change the c++ source and do a
recompile. Can I do something with the IL or a switch to the TLBIMP.exe? Any
help appreciated!

"Aaron" wrote:

First of all, thanks for the response Mattias! I notice you consistently
help us problem ridden posters and let me just say we really appreciate the
time you take helping us.

Regarding my issue, I don''t have the source code for the COM component so am
unable to change the type definitions for the Struct members. This dll does
not export these methods either, so, if I understand PInvoke correctly, I am
unable to use PInvoke since the method isn''t exported. So, knowing what I
know now from the info contained in the link you referred to, if I were able
to flatten the struct members (get rid of array references, which I would
like to do anyways since I am always just passing in 1) this method would
complete S_OK. <- :s

So the question now is, is it possible to _redefine_ a structure which is
declared in the namespace of the COM component? So I would be able to call
''pseudo code
Structure MyNewlyRedefinedGroupAttribute
...
... '' redefine the array structure to be non-arrays
end structure
Dim myNewlyRedefinedGroupAttributes as MyNewlyRedefinedGroupAttribute

Be able to use my redefined flattened structure without getting
"There is no interface that accepts these parameters
(myapp.MyNewlyRedefinedGroupAttribute, Nokia.TCSapi.tcsGroupAttributesMask_t,
int16)"

Create(myNewlyRedefinedGroupAttributes, groupAttributesMask, cookie)

Is it possible to just edit the IL and reassemble or will I get that
"missingfieldexception"?

Thanks in advance Mattias!

Aaron
"Mattias Sj??gren" wrote:

Aaron,

This struct has a member which is a struct
which contains an array of another struct.



That''s unfortunately not supported by the marshaler. See

http://dotnetinterop.com/faq/?q=StructWithStructArray

Mattias

--
Mattias Sj??gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



这篇关于任何COM Interop GURUS在那里!? - 带有数组的嵌套结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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