PDA

View Full Version : [ask]Error Message Mean?


nekok
01-21-2011, 02:01 AM
:)Dear all, may you have a great day

I work on my project, the idea is remote computer/remote desktop, using indy.
I'm testing one of the features which is sending message directly into the server desktop interface [write on the desktop].

I run both the server and the client, make the connection, and try the send desktop message feature. Once I execute the command, the message shown at server desktop [it works], but then suddenly and error come up and the program need be reset. :(

here the error message project target.exe raised exception class EOleSysError with message 'CoInitialize has not been called'. here the code phrase:
//=============[9]FOR DESKTOP MESSAGE==========//
if command='desktopmessage' then
begin //condition 16
//takedata from client
//coordinate x
messages:=AThread.Connection.ReadLn;
s1:=messages;
x:=strtoint(s1);
//coordinate y
messages:=AThread.Connection.ReadLn;
s2:=messages;
y:=strtoint(s2);
//message detail
messages:=AThread.Connection.ReadLn;
s:=messages;
//desktop canvas create
DeskTopCanvas:=TCanvas.Create;
DeskTopCanvas.Handle:=GetDC(HWND_Desktop);
Handle:=GetDesktopWindow;
Dc:=GetWindowDC(Handle);
ACanvas:=TCanvas.Create;
try
//write at desktop
ACanvas.Handle:=DC;
BeginPath(ACanvas.Handle);
ACanvas.Font.Color:=clRed;
ACanvas.Font.Name:='Tahoma';
ACanvas.Font.Size:=40;
SetBkMode(ACanvas.Handle,TRANSPARENT);
EndPath(ACanvas.Handle);
ACanvas.TextOut(x,y,s);
finally
//release memory
ReleaseDC(Handle,ACanvas.Handle);
ACanvas.Free;
end;
AThread.Connection.WriteLn('lost');
command:='';
narations:='A Message Sent to Your Desktop';
NARATION(narations);
end;
plase help me, what this error mean, and what probably the solution to it.:confused:

thanks in advance

Norrit
01-21-2011, 06:50 AM
You're working with threads, they need to be synchronized... This is done by the CoInitialize... The error states for itself, it's a procedure you need to call...

nekok
01-21-2011, 06:54 AM
Mr.Norrit, nice to see you again

how to solve that? what should I do, i mean to call the preocedure.
there's no procedure named Coinitialize

thanks

Norrit
01-21-2011, 07:00 AM
CoInitialize() is a procedure, my guess is that it's in ActiveX... But I have no Delphi running at the moment, so I cannot verify

nekok
01-21-2011, 07:13 AM
then what should i do next, find information about procedure CoInitialize()?
I had trace the whole LOC, but there's no CoInitialize or AcitiveX.

nekok
01-21-2011, 08:41 AM
Partly done. :)

I try, then i found the solution.
I remove these LOC

narations:='A Message Sent to Your Desktop';
NARATION(narations);

by making it as comments, put // before

//narations:='A Message Sent to Your Desktop';
//NARATION(narations);
the error message gone, but another problem come.:(

that code above is used for my text to speech procedure.
narations is assigned with the words that I need to be spoken, and NARATION, is the procedure.

by the way, I found CoInitialize in ComObj.

what should i do next?:confused:

Norrit
01-21-2011, 09:12 AM
Normally you should call CoInitialize() in the constructor (MainForm.Create or even in the .dpr)
For this you obviously need to add ComObj to the uses list...

nekok
01-21-2011, 09:24 AM
I already add ComObj since the beginning.

How to call CoInitialize(), I mean the syntax, sorry i don't really know.

thanks Norrit

vcldeveloper
01-22-2011, 10:44 AM
CoInitialize is required when you access COM objects within a thread. By default, Delphi does this for your main thread in Application.Initialize, but for other threads which you build, you need to call CoInitialize at the beginning of execution code of the thread, and CoUninitialize at the end of thread execution.

As far as I can see, you are trying to use Text-to-Speech engine which is a COM object, and that's why you need CoInitialize in your code.

CoInitialize is defined in ActiveX unit. You should add that unit to your uses clause. Execute method of your thread class should look like this:

CoInitialize(nil);
try
{Add your code here}
finally
CoUninitialize();
end;

nekok
01-23-2011, 02:40 AM
Thanks a lot vcldeveloper :)

I've add CoInitialize(nil) before read your replay, but not the CoUnInitialize() yet.
I'll try it first, thanks a lot.

Actually, I still facing a lot of trouble here, and I'll ask it later