API question: EnumPorts_()

Just starting out? Need help? Post your questions and find answers here.
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

API question: EnumPorts_()

Post by Saboteur »

Does anybody know how to use EnumPorts_ function?
I do this:

Code: Select all

*buffer=AllocateMemory(0,2000)
pcbNeeded.l=0
pcReturned.l=0

EnumPorts_(#null, 1, @buffer, 2000, @pcbNeeded, @pcReturned)
Debug pcbNeeded
Debug pcReturned

FreeMemory(0)
but it seems the function don't accept that parameters...
This is the function:

BOOL EnumPorts(
LPTSTR pName, // pointer to server name
DWORD Level, // specifies type of port info structure
LPBYTE pPorts, // pointer to buffer to receive array of port info. structures
DWORD cbBuf, // specifies size, in bytes, of buffer
LPDWORD pcbNeeded, // pointer to number of bytes stored into buffer (or required
// buffer size)
LPDWORD pcReturned // pointer to number of PORT_INFO_*. structures stored into buffer
);

Please help help help sos sos.... :? :? :?
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Little logical error in the call...

You receive the memory address with a pointer, called *buffer, but at your call, you use @buffer. This refers to 2 different things.

*buffer is a pointer (not a variable)
@buffer gives you the pointer to a variable called buffer, but that is not the
same as the *buffer pointer.

This would be the right call:

EnumPorts_(#null, 1, *buffer, 2000, @pcbNeeded, @pcReturned)

Timo
quidquid Latine dictum sit altum videtur
Hi-Toro
Enthusiast
Enthusiast
Posts: 265
Joined: Sat Apr 26, 2003 3:23 pm

Weird...

Post by Hi-Toro »

Maybe PB's definition is wrong. The Win32 help docs and the M$DN site both say this is the correct number of parameters...
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

@Freak

yes, you are right. First time I used *buffer, but changing the code I let @buffer, which is not right. The problem is the number of parameters, Win32 Docs say that this is ok, but PB no. Perhaps @Hi-Toro is right and is a problem of PB's definition.

Thanks for your replies.... :wink:
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

Yep, there is a problem - the command doesnt acceppt the last argument.

@Fred: you read that ??

Working example (debug on):

Code: Select all

Structure _PORT_INFO_2
    pPortName.l
    pMonitorName.l
    pDescription.l
    fPortType.l
    Reserved.l
EndStructure

Dim buffer._PORT_INFO_2(1000)

pcbNeeded.l=0
pcReturned.l=0

!PUSH dword v_pcReturned
If EnumPorts_(0,2,@buffer(),SizeOf(_PORT_INFO_2)*1000,@pcbNeeded.l)
  For a = 0 To pcReturned-1
    If buffer(a)\pPortName
      Debug "FOUND:  "+PeekS(buffer(a)\pPortName)
      Debug "    - "  +PeekS(buffer(a)\pMonitorName)
      Debug "    - "  +PeekS(buffer(a)\pDescription)
      Select buffer(a)\fPortType
        Case #PORT_TYPE_WRITE        : Debug "    - "+"PORT_TYPE_WRITE"
        Case #PORT_TYPE_READ         : Debug "    - "+"PORT_TYPE_READ"
        Case #PORT_TYPE_REDIRECTED   : Debug "    - "+"PORT_TYPE_REDIRECTED"
        Case #PORT_TYPE_NET_ATTACHED : Debug "    - "+"PORT_TYPE_NET_ATTACHED"
      EndSelect
    EndIf
  Next a 
  Debug "END."
Else
  Error$ = Space(1000)
  FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM,#FORMAT_MESSAGE_FROM_HMODULE,GetLastError_(),0,Error$,Len(Error$),0)
  MessageRequester("ERROR",Error$,#MB_ICONERROR)
EndIf
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I will fix that.
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

Hummm.... good report Sherlock "Danilo" Holmes :lol:
Post Reply