以下 c(++)-struct 如何转换为 C# 以供 p/invoke 使用
我试图包装一个较旧的 dll,但遇到了表示它在 C# 中使用的结构的问题。我尝试过的一切似乎都不起作用。有魔法师可以帮忙吗?
typedef struct _PARAM_BYNAME_DATA
{
n_char *szPntName; /* (in) point name */
n_char *szPrmName; /* (in) parameter name */
n_long nPrmOffset; /* (in) parameter offset */
PARvalue *pupvValue; /* (in/out) parameter value union */
n_ushort nType; /* (in/out) value type */
n_long fStatus; /* (out) status of each value access */
} PARAM_BYNAME_DATA;
如果有帮助的话,下面是一个 VB 端口。
Type param_byname_data
point_name As String
param_name As String
param_offset As Long
padding1 As Long 'for byte alignment between VB and C
param_value As Variant
param_type As Integer
padding2 As Integer 'for byte alignment between VB and C
status As Long status As Long
End Type
还有下面的 Delphi...
PARAM_BYNAME_DATA=record
PntName:pchar; // (in) point name
PrmName:pchar; // (in) parameter name
PrmOffset:longword; // (in) parameter offset
pValue:pointer; // (out) parameter value union
nType:word; // (out) value type
fStatus:longword; // (out) status of each value access */
end;
Im trying to wrap an older dll and am running into issues representing a structure it uses in C#. Nothing I have tried seems to be working. Any magicians able to help?
typedef struct _PARAM_BYNAME_DATA
{
n_char *szPntName; /* (in) point name */
n_char *szPrmName; /* (in) parameter name */
n_long nPrmOffset; /* (in) parameter offset */
PARvalue *pupvValue; /* (in/out) parameter value union */
n_ushort nType; /* (in/out) value type */
n_long fStatus; /* (out) status of each value access */
} PARAM_BYNAME_DATA;
If it helps the below is a VB port.
Type param_byname_data
point_name As String
param_name As String
param_offset As Long
padding1 As Long 'for byte alignment between VB and C
param_value As Variant
param_type As Integer
padding2 As Integer 'for byte alignment between VB and C
status As Long status As Long
End Type
And the following Delphi as well...
PARAM_BYNAME_DATA=record
PntName:pchar; // (in) point name
PrmName:pchar; // (in) parameter name
PrmOffset:longword; // (in) parameter offset
pValue:pointer; // (out) parameter value union
nType:word; // (out) value type
fStatus:longword; // (out) status of each value access */
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该结构应该看起来像这样...
这是一篇 好文章< /a> 讨论了应该有帮助的结构和对齐。主要的是结构布局和位对齐。自从我不得不从 C++ 中整理值以来已经有一段时间了,但我希望这会有所帮助。
The struct should look something like this...
Here is a good article that talks about structs and alignment that should help. The main thing is the struct layout and the bit alignment. It has been a while since I have had to marshal values out of C++ but I hope this helps.