[comp.sys.mac.comm] Comm Toolbox Confusion.

jay@argosy.UUCP (Jay O'Conor) (03/31/91)

I'm writing my first Comm Toolbox program and I've run into some
confusion.  I'm just using the Connection Manager.
To create a Connection Record, I need to call CMNew(), right?  Well, to
call CMNew, I need to know the procID of a tool - no problem, I'll just
call CMChoose to let the user choose a tool, and then I'll have a
procID.  BUT CMCHOOSE NEEDS A VALID CONNECTION RECORD!!!
What am I missing here?  This would appear to be something of a
catch-22.  Initially, I thought CMChoose would create the Connection
record for me but this doesn't appear to be the case.
CMChoose is declared as CMChoose(VAR hConn:ConnHandle; where:Point;
idleProc:ProcPtr):INTEGER.  I'm passing the address of where I want the
handle returned, the location where I want the dialog, and NIL for the
idleProc.
Does CMChoose create a Connection Record?  If not, how do I call CMNew
without knowing a tool name?

Thanks

Jay O'Conor
Maspar Computer Corporation
jay@maspar.com

dorner@pequod.cso.uiuc.edu (Steve Dorner) (04/01/91)

In article <1062@argosy.UUCP> jay@armada.UUCP () writes:
>To create a Connection Record, I need to call CMNew(), right?  Well, to
>call CMNew, I need to know the procID of a tool - no problem, I'll just
>call CMChoose to let the user choose a tool, and then I'll have a
>procID.  BUT CMCHOOSE NEEDS A VALID CONNECTION RECORD!!!
>What am I missing here?

CMGetProcID.  Perhaps this fragment will be of some use:

  CMBufferSizes bs;
  ConnectionHandle CnH;
  short CTBErr;
  
  /*
   * find the tool to use
   */
  if (!*GetRStr(toolName,CTB_TOOL_STR)) return(CTBErr = 1);
  
  if ((procID=CMGetProcID(toolName))<0)
  {
    CRMGetIndToolName(classCM,1,toolName);
    if (!*toolName)
      return(WarnUser(NO_CTB_TOOLS,CTBErr=1));
    else if ((procID=CMGetProcID(toolName))<0)
      return(WarnUser(COULDNT_GET_TOOL,CTBErr=1));
  }
  
  /*
   * create a connection record
   */
  WriteZero(bs,sizeof(bs));
  if (!(CnH = CMNew(procID,cmNoMenus|cmQuiet,bs,nil,nil)))
    return(WarnUser(MEM_ERR,CTBErr=MemError()));
    
You'll have to infer what some of my library routines do.  The basic idea is
that I grab the name of the tool that was last in use (CTB_TOOL_STR), and
try to get its procID (CMGetProcID(toolName)).  If that fails, then
I ask for 'any old connection tool' (CRMGetIndToolName(classCM,1,toolName))
and try again.  Once I have a valid procID, then I can call CMNew, and later
CMValidate or CMChoose.
--
Steve Dorner, U of Illinois Computing Services Office
Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner