调用COM接口时,出现“没有布局信息”的错误。

biihc2000 2004-09-20 04:02:32
代码如下:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
namespace STCSAPI
{

[ComImport, Guid("D3DBD0B0-E0E9-4F46-9591-5754D36D5361")]
public class TCSOrganisationBlockManagerClass
{

}


[Guid("6D16C3FF-6787-46ED-AB2E-58919EBA91F8"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ITCSOrganisationBlockManager
{
int Create([In] ref tcsOrgBlockAttributes_t orgBlockAttributes, [In] ref tcsOrgBlockAttributesMask_t orgBlockAttributesMask, [In] short cookie);
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct tcsOrgBlockAttributes_t
{

[MarshalAs(UnmanagedType.ByValArray,SizeConst = 6)]
public ushort [] orgBlockId;

[MarshalAs(UnmanagedType.ByValArray,SizeConst = 32)]
public byte [] orgBlockMnemonic;

[MarshalAs(UnmanagedType.ByValArray,SizeConst = 64)]
public byte[] apn;

public System.UInt32 apnIndex;

public bool apnIndexWithValue;

public tcsApnPoolList_t apnPoolList;

public System.UInt32 homeExchangeId;

[MarshalAs(UnmanagedType.ByValArray,SizeConst = 12)]
public byte[] homeExchangeMnemonic;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct tcsApnPoolList_t
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 10)]
public tcsApnPool_t[] apnPoolList;

public System.UInt16 length;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct tcsApnPool_t
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=16)]
public byte[] apnPoolMnemonic;
public System.UInt16 apnPoolId;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct tcsOrgBlockAttributesMask_t
{
public bool apnIndexPresent;
public bool apnPoolListPresent;
public bool orgBlockMnemonicPresent;
}

}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
调用COM的代码如下:

tcsOrgBlockAttributes_t structOrgAttr = new tcsOrgBlockAttributes_t();
tcsOrgBlockAttributesMask_t structOrgMask = new tcsOrgBlockAttributesMask_t();
TCSOrganisationBlockManagerClass aOrg = new TCSOrganisationBlockManagerClass();
ITCSOrganisationBlockManager iOrg=(ITCSOrganisationBlockManager)aOrg;
iOrg.Create(ref structOrgAttr,ref structOrgMask,32);

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误信息如下:

无法封送类型 STCSAPI.tcsOrgBlockAttributes_t 的字段 apnPoolList:该字段的类型定义没有布局信息。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

请高人帮忙看一下,自己查了n多资料也解决不了,实在是无计可施了,特别请qqchen79(知秋一叶)帮忙看一下,不胜感激!
...全文
73 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
biihc2000 2004-09-21
  • 打赏
  • 举报
回复
谢谢这么多人来关注,昨晚有事,没有及时上来,很抱歉。
特别感谢 qqchen79(知秋一叶) ,但是对于这样的结构,在我要调用的DLL中还有很多,如果都要去修改的话,工作量将相当的大,并且容易出错,有没有其它的办法呢?
qqchen79 2004-09-21
  • 打赏
  • 举报
回复
Well, there IS a dirty solution to the problem:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct tcsApnPoolList_t
{
public tcsApnPool_t apnPoolList1;
public tcsApnPool_t apnPoolList2;
public tcsApnPool_t apnPoolList3;
...
public tcsApnPool_t apnPoolList10; //define 10 items separately.

public System.UInt16 length;
}
yingshis 2004-09-21
  • 打赏
  • 举报
回复
up
happyjun2000 2004-09-21
  • 打赏
  • 举报
回复
up
qqchen79 2004-09-20
  • 打赏
  • 举报
回复
Last time I checked, .NET has some problem dealing with nested structs. I'm not sure whether it's fixed. If it hasn't, you would have to deal with it by yourself. E.g: Allocate a memory block with Marshal.AllocHGlobal, get the struct data, and then use Marshal.PtrToStructure to extract the struct.
otie 2004-09-20
  • 打赏
  • 举报
回复
up

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧