Menu

#40 CM_Get_Parent crashes cause of wrong declaration

open-postponed
Chris
None
5
2010-03-22
2009-12-15
Anonymous
No

declaration now:
function CM_Get_Parent(var dnDevInstParent: DEVINST; dnDevInst: DEVINST; ulFlags: ULONG): CONFIGRET; stdcall;
have to be:
function CM_Get_Parent_fix(dnDevInstParent: PDEVINST; dnDevInst: DEVINST; ulFlags: ULONG): CONFIGRET; stdcall;

"CM_Get_Parent
The CM_Get_Parent function obtains a device instance handle to the parent node of a specified device node (devnode) in the local machine's device tree.
CMAPI CONFIGRET WINAPI
CM_Get_Parent(
OUT PDEVINST pdnDevInst,
IN DEVINST dnDevInst,
IN ULONG ulFlags
);"
see: http://msdn.microsoft.com/en-us/library/ms791198.aspx (as u know, i'm sure about this ;D)

u should not use var parameters -> causes some problems.

regards
Peter

Discussion

  • Chris

    Chris - 2010-01-21
    • assigned_to: nobody --> dezipaitor
     
  • Chris

    Chris - 2010-01-21

    I do not see why this should crash. Var is just fine because the parameter is not optional (cannot be NULL).
    Otherwise all the other functions should also crash in the same way.

     
  • Chris

    Chris - 2010-03-22
    • status: open --> pending-postponed
     
  • Chris

    Chris - 2010-03-22

    The problem may be the fact that the function parameter was declared as VAR but should have been OUT instead.

     
  • Oliver Schneider

    Hi there,

    OUT in the declarations from the SDK is either an empty macro or expands to a SAL annotation on newer MS compilers. It makes no difference whether it's there, it is just to aid readability. In Delphi out and var used to do the same, i.e. pass the respective argument as a pointer to the given type *if* if was a struct/record type. I think for integral types the rules for out and var diverged, but I'm too long out of it now.

    Digging for a declaration of DEVINST in the Delphi units I noticed:

    836 PSPDevInfoData = ^TSPDevInfoData;
    837 SP_DEVINFO_DATA = packed record
    838 cbSize: DWORD;
    839 ClassGuid: TGUID;
    840 DevInst: DWORD; // DEVINST handle
    841 Reserved: ULONG_PTR;
    842 end;

    This will fault on x64 ... well, if the makers of Delphi ever support it ;)

    Haven't found the declaration, but a short snippet of disassembly from a call of this function in the resulting binary would help to see what's going on.

     
  • Oliver Schneider

    • status: pending-postponed --> open-postponed
     

Log in to post a comment.