Re: How do I stop a TSP written in Delphi crashing on Add Provider?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Bram,

Many thanks for your reply. Its good to know that somebody has had
the same problems and managed to solve them. I thought I had already
solved the TSPI_providerUIIdentify problem in my code (and it is
amazingly similar to the code you produced)

function TSPI_providerUIIdentify(var lpszUIDLLName : LPWSTR) :
Longint; stdcall;
var
returnCode : Longint;
dllNameLength : Integer;
pDLLPath : PChar;
dllPath : String;

begin
Log('Entering TSPI_providerUIIdentify', DEBUG);

GetMem(pDLLPath, MAX_PATH);
dllNameLength := GetModuleFilenameA(HInstance, pDLLPath,
MAX_PATH);

if(dllNameLength <> 0) then
begin
dllPath := String(pDLLPath);
Log('The TSP is ' + dllPath, DEBUG);
StringToWideChar(dllPath, lpszUIDLLName, MAX_PATH-1);
returnCode := SUCCESS;
end
else
begin
returnCode := LongInt(LINEERR_OPERATIONFAILED);
// or could be LINEERR_NOMEM?
end;

FreeMem(pDLLPath);
//pDLLPath := nil; if any code could use it :)

Log('Ending TSPI_providerUIIdentify, returning ' +
decodeReturnValue(returnCode), DEBUG);

Result := returnCode;
end;

I have used the following code (in another project) to test it and
it works fine:

function TSPI_providerUIIdentify(var lpszUIDLLName : LPWSTR):
Longint; stdcall; external 'C:\WINDOWS\system32\PSTSP.TSP';

procedure TForm1.Button1Click(Sender: TObject);

var buffer : PWideChar;

begin
GetMem(buffer, MAX_PATH);
TSPI_providerUIIdentify(buffer);
ShowMessage(WideCharToString(buffer));
FreeMem(buffer);
end;

Looking at your code, you have used an array instead of a PChar, so
I will try your method and see if that helps me.

I will make my TAPI Service run in a separate Svchost as Andreas has
suggested as I had already found out that kill process destroys
other stuff too in a previous set of tests.

Another point to note is that I didn't realise that I needed to
implement TSPI_lineSetDefaultMediaDetection,
TSPI_providerGenericDialogData, TUISPI_providerGenericDialog,
TUISPI_providerConfig or TSPI_providerConfig (i.e. as Andreas stated
in an earlier post all TSPI/TSPUI pairs must be implemented and as
you stated in your list below).

I will check the link you posted, however most of the skeleton I
need is in place.

Thanks to both you and Andreas for all of the help so far, I will
let you know how it goes once I've "implemented" all of the
suggested things. I will then look at Open Sourcing my TSP skeleton.
I'm feeling quite confident now :-)

Regards

Paul

----- Original Message -----
From: "B. T. Heerebout" <bram@xxxxxxxxxxxx>
Newsgroups: microsoft.public.win32.programmer.tapi
Sent: Thursday, April 28, 2005 9:24 AM
Subject: Re: How do I stop a TSP written in Delphi crashing on Add
Provider?


Hey Paul,
I think I can help you. I have been working on a TSP in delphi
myself
and all though I am still having some problems I have solved the
problems you're having. I started out with the sdk example and that
prooved diffucult enough. You can read about in an earlier post in
this
group (subj: Writing a TSP ). I also had Alexander Staubo's skeleton
TSP which dated back to 1996. (download here:
http://www.delphi32.com/vcl/20­60/) This skeleton didn't work right
away. I worked on it and finally I succeeded in compiling my own TSP
which could be added and removed without any crashes etc. The most
important function is TSPI_providerUIIdentify which uses
WideStrings.
And if you're returning the TSP's own filename you should export
TUISPI_providerConfig. You should also export
TSPI_lineSetDefaultMediaDetection. It is required for TSPI_lineOpen
to
succeed. MSDN tells you to in the small print with the TSPI_lineOpen
page. Why, if this function is required, this isn't in very big
print
on the missing "how to build a tsp yourself in 5 simple steps page"
is
a mystery to me but lucky for us there are newsgroups :-).

Now to address you're questions:

1. Almost. Everything works fine (makecall) on my pc (XP SP2) but
doesn't always on others (i.e. w2k server). I suspect it might have
something to do with the telephony server settings (which user
account
it uses and the interact with desktop setting).

2. I'm afraid I can't share all my code. It's not mine; It belongs
to
my employer. I'll share this though:

function TSPI_providerUIIdentify(lpszUIDLLName : LPWSTR) : LONG;
stdcall;
var
Buffer: array[0..MAX_PATH] of Char;
Size: Integer;
FileName: String;

begin
Size:= GetModuleFileName(SysInit.HInstance, Buffer, MAX_PATH-1);
if (Size < MAX_PATH) then
begin
FileName:= Buffer;
end else begin
Result:= Long(LINEERR_OPERATIONFAILED);
exit;
end;

Result:= 0;
StringToWideChar(FileName, lpszUIDLLName, length(FileName) + 1);
Log('TSPI_providerUIIdentify-FileName=' + FileName);
end;

This code could have saved me a long time. If you're experimenting
with
this code you really should have the telephony service run in it's
own
scvhost. Andreas' FAQ tells you precisely how (Thanks Andreas). If
your
function uses standard delphi ansi strings this function fails, the
service might hang. The only way to get thing going is to kill the
process it's in (use tasklist /svc in the XP command prompt to find
out
which process it is). Running in non exclusive mode some other
services
might be colleterally damaged after which you have to reboot. You
probably know by now it's really QUITE frustratating to have to
reboot
after each build.
As said I can't share all my code but if you would be willing, you
could share yours and I might be able to fix yours. This could be a
good help for the delphi community.

3.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tapi/tspi/tspi_basic_telephony_functions.asp

This lists all functions that are required for basic tapi. However
very
unfindable small print somewhere states a few more functions are
required to even be able to install your tsp:
TSPI_lineSetDefaultMediaDetection
TSPI_providerEnumDevices
TSPI_providerFreeDialogInstance
TSPI_providerGenericDialogData
TSPI_providerUIIdentify
TUISPI_providerConfig
TUISPI_providerGenericDialog
TUISPI_providerGenericDialogData
TSPI_providerConfig

4. Yes I have and the problem was the WideString in the
TSPI_providerUIIdentify



This has become a lengthy post. I hope it helps you and maybe some
others. If you have more questions please post them.

Good luck, and as Vito says: "Some day, and that day may never come,
I'll call upon you to do a service for me."
;-)

Bram


.



Relevant Pages

  • Re: switch to display (or not) the configuraion UI of a TSP
    ... with Andreas' help I was able to worked out a solution regarding my problem: ... Peter ... > lpszUIDLLName parameter generally. ... > Best regards, ...
    (microsoft.public.win32.programmer.tapi)
  • =?iso-8859-1?q?Re:_Schnelleinf=FChrung_Delphi_gesucht?=
    ... Andreas schrieb: ... > Beim Umstieg auf Delphi ist der Bereich OOP ... Prev by Date: ... Next by Date: ...
    (de.comp.lang.delphi.misc)
  • Re: How do I stop a TSP written in Delphi crashing on Add Provider?
    ... I have been working on a TSP in delphi myself ... something to do with the telephony server settings (which user account ... Andreas' FAQ tells you precisely how. ... function uses standard delphi ansi strings this function fails, ...
    (microsoft.public.win32.programmer.tapi)
  • Re: Can someone explain this?
    ... Another solution is to install Andreas Hausladen's Delphi Speedup: ... It allows you to cancel code completion by pressing Escape. ...
    (borland.public.delphi.non-technical)
  • Re: moving from D7 to D2008
    ... jump from D7 to D2006 made me completely unproductive again. ... The component palette is still a PITA to use. ... Andreas has some add-ins for Delphi that makes life much easier when working with Delphi ...
    (borland.public.delphi.non-technical)