所以只是想知道,问题是什么?你有任何问题吗?是的,介意分享我们的错误吗? 谢谢。抱歉,麻烦。 - 问候, Chua Wen Ching :) Duncan Mole ;写道:Hi Duncan Mole,So just wondering, what is the problem? Do you face any problems? Is yes, mind to share us the errors?Thanks. Sorry for the trouble.--Regards,Chua Wen Ching :)"Duncan Mole" wrote: 这可能是一个简单的,但它首先是p / invoke。我试图在通话中使用以下C结构: typedef struct {BYTE SRB_Cmd; BYTE SRB_Status, BYTE SRB_HaId; BYTE SRB_Flags; DWORD SRB_Hdr_Rsvd; BYTE HA_Count; BYTE HA_SCSI_ID; BYTE HA_ManagerId [16]; BYTE HA_Identifiyer [16] ; BYTE HA_Unique [16]; BYTE HA_SRsvd1; } SRB_HAInquiry,* PSRB_HAInquiry; 函数原型如下: SendASPI32Command((LPSRB)& srbHAInquiry) 根据文档,LPSRB是指向结构命令的4位通用指针。 堡垒我有: [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Ansi)] 公共课SRB_HAInquiry public const int STRING_LEN = 16; 公共字节SRB_Cmd; 公共字节SRB_Status; publ ic字节SRB_HaId; 公共字节SRB_Flags; 公共UInt32 SRB_Hdr_Rsvd; 公共字节HA_Count; 公共字节HA_SCSI_ID; [MarshalAs(UnmanagedType.ByValTStr,SizeConst = STRING_LEN)] 公共字符串HA_ManagerId =新字符串('''',STRING_LEN); [MarshalAs(UnmanagedType.ByValTStr,SizeConst = STRING_LEN)] 公共字符串HA_Identifier =新字符串('''',STRING_LEN); [MarshalAs(UnmanagedType) .ByValTStr,SizeConst = STRING_LEN)] 公共字符串HA_Unique =新字符串('''',STRING_LEN); 公共UInt16 HA_Rsvd1 = 0; } 我的调用是: [DllImport(" wnaspi32.dll",EntryPoint =" SendASPI32Command", ExactSpelling = true,CharSet = CharSet.Ansi,SetLastError = true)] 私有静态extern UInt32 SendASPI32命令( 参考SRB_HAInquiry str); 和我的电话是: p ublic SRB_HAInquiry ScHaInquiry(int haId) SRB_HAInquiry enq = new SRB_HAInquiry(); enq.SRB_Cmd =(byte)Commands.SC_HA_INQUIRY ; enq.SRB_HaId =(byte)haId; UInt32 result = SendASPI32Command(ref enq); return enq; } 非常感谢任何帮助。 Hi, This is probably an easy one but it iy first bit of p/invoke. I am trying to use the following C struct in a call: typedef struct { BYTE SRB_Cmd; BYTE SRB_Status, BYTE SRB_HaId; BYTE SRB_Flags; DWORD SRB_Hdr_Rsvd; BYTE HA_Count; BYTE HA_SCSI_ID; BYTE HA_ManagerId[16]; BYTE HA_Identifiyer[16]; BYTE HA_Unique[16]; BYTE HA_SRsvd1; } SRB_HAInquiry, *PSRB_HAInquiry; The function prototype is as follows: SendASPI32Command((LPSRB)&srbHAInquiry) According to the docs LPSRB is 4 bit generic pointer to a command strucure. Fort this I have: [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public class SRB_HAInquiry { public const int STRING_LEN = 16; public byte SRB_Cmd; public byte SRB_Status; public byte SRB_HaId; public byte SRB_Flags; public UInt32 SRB_Hdr_Rsvd; public byte HA_Count; public byte HA_SCSI_ID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=STRING_LEN)] public string HA_ManagerId = new string('' '', STRING_LEN); [MarshalAs(UnmanagedType.ByValTStr, SizeConst=STRING_LEN)] public string HA_Identifier = new string('' '', STRING_LEN); [MarshalAs(UnmanagedType.ByValTStr, SizeConst=STRING_LEN)] public string HA_Unique = new string('' '', STRING_LEN); public UInt16 HA_Rsvd1 = 0; } my invokke is : [DllImport("wnaspi32.dll", EntryPoint="SendASPI32Command", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)] private static extern UInt32 SendASPI32Command( ref SRB_HAInquiry str); and my call is: public SRB_HAInquiry ScHaInquiry(int haId) { SRB_HAInquiry enq = new SRB_HAInquiry(); enq.SRB_Cmd = (byte)Commands.SC_HA_INQUIRY; enq.SRB_HaId = (byte)haId; UInt32 result = SendASPI32Command(ref enq); return enq; } Any help would be much appreciated. 我对包含 a字符串数组变量的结构也有类似的问题。 更好看看你是否运行您在.NET 1.1上的应用程序 解决了我的问题。 谢谢, irfanHi,I too had a similar problem with the structure containinga string array variable.Better see if you run your application on .NET 1.1 as thatsolved mine.Thanks,irfan 这篇关于P / Invoke结构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 07:22