1

I have developed a TSP to talk to a CTI server. In the most part it works, but when setting the caller/called ID parties, in

function TSPI_lineGetCallInfo(
  hdCall : HDRVCALL;
  lpCallInfo : LPLINECALLINFO
) : LONG;

I am finding the offsets are all corrects but the size fields are NOT. At the end of the function I output (to debugger) the size and offsets of each field and they are what I expect them to be. But when I inspect the values using a TAPI program the sizes are different, (but the offsets are EXACTLY the same as per the debug statements) in fact the size field 5 regardless of what is actually there, whereas the debug statements at the end of the code below shows the correct values...

Any help greatly appreciated.

      lpCallInfo^.dwCallerIDOffset := 0;
      lpCallInfo^.dwCallerIDSize := 0;
      lpCallInfo^.dwCalledIDOffset := 0;
      lpCallInfo^.dwCalledIDSize := 0;
      lpCallInfo^.dwConnectedIDOffset := 0;
      lpCallInfo^.dwConnectedIDSize := 0;

      extnid := thiscall.CallItem.ExtnId;
      phoneno := thiscall.CallItem.DialNum;
      extnid_size := (Length(extnid) + 1) * sizeof(WCHAR);
      phoneno_size := (Length(phoneno) + 1) * sizeof(WCHAR);

      extnidw := StringToWideStringEx(extnid, CP_ACP);
      phonenow := StringToWideStringEx(phoneno, CP_ACP);

      if lpCallInfo^.dwOrigin = LINECALLORIGIN_INTERNAL then
      begin
        {me}
        lpCallInfo^.dwCallerIDOffset := sizeof(TLINECALLINFO);
        lpCallInfo^.dwCallerIDSize := extnid_size;
        Move(ExtnIdw[1], ptr^, extnid_size * 2);
        ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
        {other party}
        if phoneno <> '' then
        begin
          lpCallInfo^.dwCalledIDOffset :=
            sizeof(TLINECALLINFO) + lpCallInfo^.dwCallerIDSize;
          lpCallInfo^.dwCalledIDSize := phoneno_size;
          Move(phonenow[1], ptr^, phoneno_size * 2);
        end;
      end
      else
      begin
        if thiscall.CallItem.CallType = 1 then
        begin {incoming call}
          {agent is the called party}
          lpCallInfo^.dwCalledIDOffset := sizeof(TLINECALLINFO);
          lpCallInfo^.dwCalledIDSize := extnid_size;
          Move(ExtnIdw[1], ptr^, extnid_size);
          ptr := Pointer(integer(ptr) + lpCallInfo^.dwCalledIDSize);
          {other party is the caller}
          if phoneno <> '' then
          begin
            lpCallInfo^.dwCallerIDOffset :=
              sizeof(TLINECALLINFO) + lpCallInfo^.dwCalledIDSize;
            lpCallInfo^.dwCallerIDSize := phoneno_size;
            Move(phonenow[1], ptr^, phoneno_size);
            ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
          end;
        end
        else
        begin
          {agnet is the caller}
          lpCallInfo^.dwCallerIDOffset := sizeof(TLINECALLINFO);
          lpCallInfo^.dwCallerIDSize := extnid_size;
          Move(ExtnIdw[1], ptr^, extnid_size);
          ptr := Pointer(integer(ptr) + lpCallInfo^.dwCallerIDSize);
          {dialed number is the called party}
          if phoneno <> '' then
          begin
            lpCallInfo^.dwCalledIDOffset :=
              sizeof(TLINECALLINFO) + lpCallInfo^.dwCallerIDSize;
            lpCallInfo^.dwCalledIDSize := phoneno_size;
            Move(phonenow[1], ptr^, phoneno_size);
            ptr := Pointer(integer(ptr) + lpCallInfo^.dwCalledIDSize);
          end;
        end;
        if (thiscall.CallItem.CallState = cs_Connected) and
          (phoneno <> '') then
        begin
          lpCallInfo^.dwConnectedIDOffset := sizeof(TLINECALLINFO) +
            lpCallInfo^.dwCallerIDSize + lpCallInfo^.dwCalledIDSize;
          lpCallInfo^.dwConnectedIDSize := phoneno_size;
          Move(phonenow[1], ptr^, phoneno_size);
          ptr := Pointer(integer(ptr) + lpCallInfo^.dwConnectedIDSize);
        end;
      end;
    end;

    DEBUG('TSPI_lineGetCallInfo::dwCallerIDOffset=' + intToStr(lpCallInfo^.dwCallerIDOffset));
    DEBUG('TSPI_lineGetCallInfo::dwCallerIDSize=' + intToStr(lpCallInfo^.dwCallerIDSize));
    DEBUG('TSPI_lineGetCallInfo::dwCalledIDOffset=' + intToStr(lpCallInfo^.dwCalledIDOffset));
    DEBUG('TSPI_lineGetCallInfo::dwCalledIDSize=' + intToStr(lpCallInfo^.dwCalledIDSize));
    DEBUG('TSPI_lineGetCallInfo::dwConnectedIDOffset=' + intToStr(lpCallInfo^.dwConnectedIDOffset));
    DEBUG('TSPI_lineGetCallInfo::dwConnectedIDSize=' + intToStr(lpCallInfo^.dwConnectedIDSize));
hexacyanide
  • 88,222
  • 31
  • 159
  • 162
samanne
  • 309
  • 1
  • 3
  • 8

1 Answers1

1

These are strange results. Your code seems to check out. It may be a longshot but the result could be caused by too few memory reserved for the lpCallInfo structure. What tapi program do you use? Most programs just reserve a large surplus beforehand. However, another commonly used approach is to 'ask' the TSP the exact amount needed by first calling TSPI_lineGetCallInfo and then reserving the exact amount after you set the dwNeededSize and returning LINEERR_STRUCTURETOOSMALL. You don't seem to check the dwTotalSize or set the dwNeededSize and dwUsedSize fields (which is dangerous).

Please look at the : LINEERR constants

and let me know if it solves the issue. If it doesn't, I would be curious to see the structure log from the Tapi Browser, but let's hope it works. Good luck!

SpaghettiCook
  • 673
  • 4
  • 14