Many thanks for your help, Arno. I didn't reply earlier as I wanted to
investigate some more.

Your comment about the HInstance global variable being unique for module
did not match what I was experiencing in one of my threads. I googled a
bit, not that there is much about this variable online (Embarcadero don't
document 'extern PACKAGE HINSTANCE HInstance;'). It became apparent that
the fault is not anything to do with ICS, but is to do with my thread's
incorrect HInstance. The thread in question had an HInstance of NULL, yet
the HInstance for the main (VCL) thread had an address. Both threads are in
the same module (no DLLs).

I decided to take a risk and assign HInstance in my thread using

    HInstance = GetModuleHandle(NULL);

This assigns the same value to HInstance as is found in the main thread. At
this point I can create a new instance of TWSocket without the exception.
Hopefully it is all threadsafe :)

I've no idea why my thread's value of HInstance was NULL. I may never know.
Possibly an Embarcadero XE4 problem.

Thanks again for pointing me in the right direction. I was really
struggling with this one.

Cheers,

Richard


On 29 August 2013 18:07, Arno Garrels <arno.garr...@gmx.de> wrote:

> On Thursday, August 29, 2013 4:06 PM [GMT+1=CET],
> Richard Gallois wrote:
>
> > I apologise in advance if this problem has been reported and solved
> > before. I've looked through the archive and can't find anything quite
> > the same.
>
> You are welcome.
>
> > Unable to register TIcsWndControl hidden window class. Error #1410.
> >
> > My understanding is that the HInstance in OverbyteIcsWndControl.pas is
> > different for each thread.
>
> That cannot be. HINSTANCE is unique for the instance and the module in
> memory. Should be always the same value in any thread-context of your
> application AFAIK.
>
> > Consequently the AllocateHWnd procedure
> > thinks that the IcsWndControlWindowClass class has not been
> > registered. When it then tries to register the class I get the Error
> > #1440 (Class already exists).
>
> Very strange, that should never happen and I'm unable to reproduce it
> in Delphi. In "very strange" cases I suggest to disable or uninstall
> the anti-virus and (so called) security software. They are often the
> source of very strange errors.
>
> If that doesn't help please write a very basic test case in C++
> that reproduces the error and send it to me as PM, something like this
> Delphi code:
>
> {code}
> unit Unit1;
>
> interface
>
> uses
>   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
>   System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
>   Vcl.StdCtrls;
>
> type
>   TMyThread = class(TThread)
>   protected
>     procedure Execute; override;
>   end;
>
>   TForm1 = class(TForm)
>     Button1: TButton;
>     procedure Button1Click(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;
>
> var
>   Form1: TForm1;
>
> implementation
>
> {$R *.dfm}
>
> uses
>   OverbyteIcsWSocket;
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   with TMyThread.Create(False) do
>     FreeOnTerminate := True;
>   with TMyThread.Create(False) do
>     FreeOnTerminate := True;
> end;
>
> { TMyThread }
>
> procedure TMyThread.Execute;
> var
>   W: TWSocket;
> begin
>   inherited;
>   w := TWSocket.Create(nil);
>   try
>     Sleep(5000);
>   finally
>     w.Free;
>   end;
> end;
>
> end.
> {code}
>
> --
> Arno
> --
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
>
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to