CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
CoInitialize has not been called


New User

Jun 12, 2009, 7:37 AM

Post #1 of 3 (636 views)
CoInitialize has not been called Can't Post


I'm creating client / server multi-thread to handle multiple clients in the same time.
But I've got a problem when I'm using OLE in the server. I received the error "CoInitialize has not been called".
It's probably cause by ActiveX but I diddn't find any solutions on the web.
Does someone have an idea of what's doing the CoInitialize?
Which module I have to use?
and where I should put the CoInitialize and CoUnitialize ?
Thanks in advance.

Here is the server code without OLE because it's to sensitive. It may give you an idea.

# Server Program 
use strict;
use IO::Socket::INET;
use JSON;

print ">> Server Program <<\n";

$| = 1;
$SIG{CHLD} = sub {wait ()}; # avoid zombies

my $serverPort = 1234;

# Create the socket
my $server = IO::Socket::INET->new (
Proto => 'tcp',
LocalPort => $serverPort,
Listen => 5,
Reuse => 1
) or die "Could not create socket! Reason: $!.\n";

print "> Server is waiting for clients!\n";
while (my $client = $server->accept())
# Fork process to handle multiple clients
my $pid = fork();
if ($pid == 0)
print ">New client!";
# Read the request from client
my $req = '';
recv($client, my $packet, 100, 0);
print "\n" . 'read > ' . $packet;
$req = $req . $packet;
last if ($req =~ m/\n/);
# Input data deserialization
$req = from_json($req);
print ">Request:\n" . Dumper($req);

# Process some OLE

# Response serialization
my $res = to_json($req);

# Send results to client
print ">Start sending response to client!\n";
while ((length($res) % 100) != 0)
print 'write > ' . substr($res, 0, 100) . "\n";
print $client substr($res, 0, 100, '');
print $client "\n";

print ">Response sent!\n";

exit(0); # Child process exits when it is done.
} # else it's the parent process, which goes back to accept()

close ($server);



Jun 16, 2009, 9:21 AM

Post #2 of 3 (586 views)
Re: [Corendiel] CoInitialize has not been called [In reply to] Can't Post

I'm sorry, I don't know anything about OLE to answer your specific question.

However, I did notice that you're using the JSON module. I'm not sure if it's just the example code you posted, however, I wanted to make sure that in your real code, you're wrapping your from_json() calls within an eval. If your server were to receive an invalid JSON syntax, that module issues a croak(), and thus, your server dies. Additionally, since this is a server, if you haven't already, ensure you're using the JSON::XS components to speed up the parsing.

Good luck

New User

Jun 16, 2009, 10:55 AM

Post #3 of 3 (583 views)
Re: [raxip] CoInitialize has not been called [In reply to] Can't Post

Thanks for the advice.
I'll try this JSON::XS


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives