请问高手这个结构体怎么转换!!(50分)

  • 主题发起人 主题发起人 Junan
  • 开始时间 开始时间
J

Junan

Unregistered / Unconfirmed
GUEST, unregistred user!
typedef struct _CMN5_MULTI_COMMAND {<br> ULONG uCommand;<br> ULONG uBoard;<br> ULONG uChannel;<br> union {<br> ULONG uParam[4];<br> struct {<br> ULONG uParam0;<br> ULONG uParam1;<br> ULONG uParam2;<br> ULONG uParam3;<br> };<br> };<br> BOOL bRet;<br>} CMN5_MULTI_COMMAND;<br>我把它转成下面的格式:<br> TCMN5_MULTI_COMMAND=^_CMN5_MULTI_COMMAND;<br> &nbsp;_CMN5_MULTI_COMMAND=record<br> &nbsp; &nbsp;uCommand &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uBoard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uChannel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;case Integer of<br> &nbsp; &nbsp;0:(uParam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :array [0..3] of DWORD);<br> &nbsp; &nbsp;1:(<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam0 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam1 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam2 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam3 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD);<br> &nbsp; &nbsp; bRet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Boolean;<br> &nbsp;end;<br>可是在倒数第二个声明过不去了.提示出错信息:<br>Undeclared indentifier: &quot;bRet&quot;<br>Duplicate tag value<br>Type expected but &quot;END&quot; found<br>Could not complie used unit 'Unit1.pas'
 
TCMN5_MULTI_COMMAND=^_CMN5_MULTI_COMMAND;<br> &nbsp;_CMN5_MULTI_COMMAND=record<br> &nbsp; &nbsp;uCommand &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uBoard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uChannel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;bRet:Boolean;<br> &nbsp; &nbsp;case Integer of<br> &nbsp; &nbsp;0:(uParam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :array [0..3] of DWORD);<br> &nbsp; &nbsp;1:(<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam0 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam1 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam2 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam3 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br><br> &nbsp; &nbsp;end;
 
楼上这位仁兄你是有试过你的声明可用吗??这样就搞定了我就不会在这儿发帖子了.<br> '=' expected but ':' found<br>'IMPLEMENTATION' expected but ';' found<br>'.' expected but ';' found<br>Text after final 'END.' - ignored by compiler<br> Could not compile used unit 'Unit1.pas'
 
顺便再问一下:UCHAR *pDataBuffer;这种的又该怎么转呢?
 
type<br> &nbsp;TCMN5_MULTI_COMMAND=^_CMN5_MULTI_COMMAND;<br> &nbsp;_CMN5_MULTI_COMMAND=record<br> &nbsp; &nbsp;uCommand &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uBoard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uChannel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;bRet &nbsp; &nbsp; &nbsp;:Boolean;<br> &nbsp; &nbsp;case Integer of<br> &nbsp; &nbsp;0:<br> &nbsp; &nbsp; &nbsp;(uParam:array [0..3] of DWORD);<br> &nbsp; &nbsp;1:<br> &nbsp; &nbsp; (<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam0 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam1 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam2 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam3 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp;);<br> &nbsp; &nbsp;end;<br>没有编译错误啊。UCHAR *应该可以转换成作PCHAR类型的。
 
你把bRet移到上面去,这个结构体的内存分配就不一样了.我其它的Api函数要调用它是不行的.
 
_CMN5_MULTI_COMMAND_PARAM = record<br> &nbsp;case Integer of<br> &nbsp; &nbsp;0:(uParam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :array [0..3] of DWORD);<br> &nbsp; &nbsp;1:(<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam0 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam1 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uParam2 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD;<br> &nbsp; &nbsp; &nbsp; &nbsp;uaram3 &nbsp; &nbsp; &nbsp; &nbsp; :DWORD);<br>end;<br><br>TCMN5_MULTI_COMMAND=^_CMN5_MULTI_COMMAND;<br>_CMN5_MULTI_COMMAND=record<br> &nbsp; &nbsp;uCommand &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uBoard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uChannel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uParam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:_CMN5_MULTI_COMMAND_PARAM;<br> &nbsp; &nbsp;bRet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Boolean;<br>end;
 
楼上这位仁兄你是有试过你的声明可用吗??这样就搞定了我就不会在这儿发帖子了.<br> '=' expected but ':' found<br>'IMPLEMENTATION' expected but ';' found<br>'.' expected but ';' found<br>Text after final 'END.' - ignored by compiler<br> Could not compile used unit 'Unit1.pas'<br>-----<br>针对你这个帖子说的。wlmmlw的方法不错。
 
wlmmlw的方法正确,变体部分必需在记录中其他字段的声明之后,这是DELPHI的语法规则,<br>这点和C中的联合体不一样。
 
这个数据类型是一个SDK中的定义,具体它在API函数内部是怎么调用的我不是太清楚.只想知道这样子声明在内存分配方面不会有问题吗?如果API的内部再进行一次强制转换后再调用其中的成员会不会产生其它的问题呢??请高手指点.
 
用 packed record, 应该是一样的
 
TCMN5_MULTI_COMMAND=^_CMN5_MULTI_COMMAND;<br> &nbsp;_CMN5_MULTI_COMMAND=record<br> &nbsp; &nbsp;uCommand &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uBoard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;uChannel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:DWORD;<br> &nbsp; &nbsp;0:(uParam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :array [0..3] of DWORD);<br> &nbsp; &nbsp; bRet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Boolean;<br> &nbsp;end;<br>不要变体,pascal是不允许变体后再有其他的.<br>这样子声明在内存分配方面不会有问题,使用时进行一次强制转换后再调用其中的成员不会产生其它的问题
 
好的谢谢各位高手指点.UCHAR *pDataBuffer可以转成pDataBuffer:PChar吗??
 
多人接受答案了。
 
后退
顶部