Page 1 of 1

API question: EnumPorts_()

Posted: Sun Apr 27, 2003 1:55 pm
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.... :? :? :?

Posted: Sun Apr 27, 2003 2:03 pm
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

Weird...

Posted: Sun Apr 27, 2003 2:05 pm
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...

Posted: Sun Apr 27, 2003 2:12 pm
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:

Posted: Mon Apr 28, 2003 10:13 am
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

Posted: Mon Apr 28, 2003 11:41 am
by Fred
I will fix that.

Posted: Mon Apr 28, 2003 2:14 pm
by Saboteur
Hummm.... good report Sherlock "Danilo" Holmes :lol: