Just starting out? Need help? Post your questions and find answers here.
Josh
Addict
Posts: 1183 Joined: Sat Feb 13, 2010 3:45 pm
Post
by Josh » Sat Nov 25, 2017 9:22 pm
I have this C-Structure:
Code: Select all
typedef struct tagFUNCDESC {
MEMBERID memid;
SCODE *lprgscode;
ELEMDESC *lprgelemdescParam;
FUNCKIND funckind;
INVOKEKIND invkind;
CALLCONV callconv;
SHORT cParams;
SHORT cParamsOpt;
SHORT oVft;
SHORT cScodes;
ELEMDESC elemdescFunc;
WORD wFuncFlags;
} FUNCDESC, *LPFUNCDESC;
I translated this to Pb with 2 structures:
Code: Select all
Structure ELEMDESCARRAY
ElemDescParam.ELEMDESC[0]
EndStructure
Structure FUNCDESC Align #PB_Structure_AlignC
MemId.l
*rgScode
*ElemDescParams.ELEMDESCARRAY
FuncKind.l
InvKind.l
CallConv.l
cParams.w
cParamsOpt.w
oVft.w
cScodes.w
ElemDescFunc.ELEMDESC
FuncFlags.w
EndStructure
This works, but it looks a little bit ugly using following code
Code: Select all
Flags = *FuncDesc\ElemDescParams\ElemDescParam[Index]\ParamDesc\ParamFlags
Is there an other way for translating the structure?
sorry for my bad english
skywalk
Addict
Posts: 3972 Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA
Post
by skywalk » Sun Nov 26, 2017 3:17 am
You did not show all types defined within the struct?
Code: Select all
MEMBERID
SCODE
ELEMDESC
FUNCKIND
INVOKEKIND
CALLCONV
ELEMDESC
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Josh
Addict
Posts: 1183 Joined: Sat Feb 13, 2010 3:45 pm
Post
by Josh » Sun Nov 26, 2017 7:50 am
Hi Sky,
MEMBERID is a DispId, I need this only for compare with other structures, so the .l is enough for me. Nothing to do
SCODE, I don't need, so the Pb-* is enough for me. Nothing to do
ELEMDESC is a structure. The content doesn't matter for my problem, but for the sake of completeness the C-structure here:Code: Select all
typedef struct tagELEMDESC {
TYPEDESC tdesc;
union {
IDLDESC idldesc;
PARAMDESC paramdesc;
};
} ELEMDESC, *LPELEMDESC;
FUNCKIND is a Enumeration. Nothing to do
INVOKEKIND is a Enumeration. Nothing to do
CALLCONV is a Enumeration. Nothing to do
As shown in my small example in my first posting, the problem is that I had to split the C-structure into two Pb-structures. With this split the Pb call looks a bit strange:
Code: Select all
Flags = *FuncDesc\ElemDescParams\ElemDescParam[Index]\ParamDesc\ParamFlags
Look at the double call
ElemDescParams \ ElemDescParam[Index] , what is in C only one call. This works, but maybe there is a better way to implement the structure in Pb.
sorry for my bad english
cas
Enthusiast
Posts: 597 Joined: Mon Nov 03, 2008 9:56 pm
Post
by cas » Sun Nov 26, 2017 1:38 pm
Another option is to use macro. I, personally, would not bother too much about this double call ElemDescParams \ ElemDescParam[Index] and just leave it as it is now.
nco2k
Addict
Posts: 1344 Joined: Mon Sep 15, 2003 5:55 am
Post
by nco2k » Sun Nov 26, 2017 4:45 pm
shouldnt it work like this?
Code: Select all
Flags = *FuncDesc\lprgelemdescParam(Index)\paramdesc\wParamFlags
edit: updated.
Code: Select all
Structure TYPEDESC Align #PB_Structure_AlignC
StructureUnion
*lptdesc;.TYPEDESC
*lpadesc;.ARRAYDESC
hreftype.l
EndStructureUnion
vt.w
EndStructure
Structure ARRAYDESC Align #PB_Structure_AlignC
tdescElem.TYPEDESC
cDims.w
StructureUnion
rgbounds.SAFEARRAYBOUND[0]
dummyrgbounds.SAFEARRAYBOUND[1]
EndStructureUnion
EndStructure
Structure IDLDESC Align #PB_Structure_AlignC
*dwReserved
wIDLFlags.w
EndStructure
Structure PARAMDESCEX Align #PB_Structure_AlignC
cBytes.l
varDefaultValue.VARIANT
EndStructure
Structure PARAMDESC Align #PB_Structure_AlignC
StructureUnion
*pparamdescex.PARAMDESCEX
*dummypparamdescex; to avoid pb-bug
EndStructureUnion
wParamFlags.w
EndStructure
Structure ELEMDESC Align #PB_Structure_AlignC
tdesc.TYPEDESC
StructureUnion
idldesc.IDLDESC
paramdesc.PARAMDESC
EndStructureUnion
EndStructure
Structure FUNCDESC Align #PB_Structure_AlignC
memid.l
StructureUnion
*lprgscode.Long
*dummylprgscodex; to avoid pb-bug
EndStructureUnion
Array lprgelemdescParam.ELEMDESC(0)
funckind.l
invkind.l
callconv.l
cParams.w
cParamsOpt.w
oVft.w
cScodes.w
elemdescFunc.ELEMDESC
wFuncFlags.w
EndStructure
c ya,
nco2k
Last edited by
nco2k on Mon Nov 27, 2017 10:09 am, edited 3 times in total.
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Josh
Addict
Posts: 1183 Joined: Sat Feb 13, 2010 3:45 pm
Post
by Josh » Sun Nov 26, 2017 7:32 pm
cas wrote: I, personally, would not bother too much about this double call ElemDescParams \ ElemDescParam[Index] and just leave it as it is now.
Yeah, I'll leave it as it is. Maybe you know that, there's a simple solution and you just don't see it. That's why I actually asked
nco2k wrote: shouldnt it work like this?
Sorry, doesn't work
Thank you all for your efforts.
sorry for my bad english
cas
Enthusiast
Posts: 597 Joined: Mon Nov 03, 2008 9:56 pm
Post
by cas » Sun Nov 26, 2017 8:30 pm
nco2k wrote: shouldnt it work like this?
Here is sample code that can be compiled and shows the "problem". You can experiment on it.
Code: Select all
EnableExplicit
Structure element
x.l
y.l
z.l
EndStructure
Structure elementsArray
ElemDescParam.element[0]
EndStructure
Structure main
a.l
b.l
c.l
d.l
*ElemDescParams.elementsArray
f.l
EndStructure
DataSection ;do not modify datasection!
struct_a:
Data.l 1,2,3,4,?struct_b,5
struct_b:
Data.l 100,101,102
Data.l 200,201,202
Data.l 300,301,302
Data.l 400,401,402
EndDataSection
Define *struct.main=?struct_a
Debug *struct\a ;1
Debug *struct\b ;2
Debug *struct\c ;3
Debug *struct\d ;4
Debug *struct\f ;5
Debug *struct\ElemDescParams\ElemDescParam[0]\x ;100
Debug *struct\ElemDescParams\ElemDescParam[1]\x ;200
Debug *struct\ElemDescParams\ElemDescParam[2]\x ;300
Debug *struct\ElemDescParams\ElemDescParam[3]\x ;400
;can ElemDescParams\ElemDescParam[index] in last 4 debug lines be shortened?
One solution with macro (only downside is no autocomplete after "ElemDesc[index]\"):
Code: Select all
Macro ElemDesc
ElemDescParams\ElemDescParam
EndMacro
Define *struct.main=?struct_a
Debug *struct\ElemDesc[0]\x ;100
Debug *struct\ElemDesc[1]\x ;200
Debug *struct\ElemDesc[2]\x ;300
Debug *struct\ElemDesc[3]\x ;400
nco2k
Addict
Posts: 1344 Joined: Mon Sep 15, 2003 5:55 am
Post
by nco2k » Mon Nov 27, 2017 9:02 am
Code: Select all
EnableExplicit
Structure element
x.l
y.l
z.l
EndStructure
Structure main
a.l
b.l
c.l
d.l
Array ElemDescParams.element(0)
f.l
EndStructure
DataSection ;do not modify datasection!
struct_a:
Data.l 1,2,3,4,?struct_b,5
struct_b:
Data.l 100,101,102
Data.l 200,201,202
Data.l 300,301,302
Data.l 400,401,402
EndDataSection
Define *struct.main=?struct_a
Debug *struct\a ;1
Debug *struct\b ;2
Debug *struct\c ;3
Debug *struct\d ;4
Debug *struct\f ;5
Debug *struct\ElemDescParams(0)\x ;100
Debug *struct\ElemDescParams(1)\x ;200
Debug *struct\ElemDescParams(2)\x ;300
Debug *struct\ElemDescParams(3)\x ;400
i also updated the previous code, added a missing structure and removed some unnecessary stuff.
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
cas
Enthusiast
Posts: 597 Joined: Mon Nov 03, 2008 9:56 pm
Post
by cas » Mon Nov 27, 2017 4:02 pm
Yes, that is the solution. So simple. I completely forgot about using Array keyword in structure.
Josh
Addict
Posts: 1183 Joined: Sat Feb 13, 2010 3:45 pm
Post
by Josh » Tue Nov 28, 2017 9:20 am
Tried with Array. Doesn't work.
No problem, it runs like it is ^^
sorry for my bad english
nco2k
Addict
Posts: 1344 Joined: Mon Sep 15, 2003 5:55 am
Post
by nco2k » Tue Nov 28, 2017 9:23 am
then you are doing something wrong. hard to help without any example code.
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf