473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with threads

Hi All,

I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com

This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads

The code basically looks like this

HANDLE killServiceEvent;
HANDLE hGinaThread, hTrayIconThread;
char * szPinNumber;

void main() {
DWORD idGina, idTrayIcon;

hGinaThread=CreateThread(0,0,(LPTHREAD_START_ROUTI NE)GinaThread,0,0,&idGina);

hTrayIconThread=CreateThread(0,0,(LPTHREAD_START_R OUTINE)TrayIconThread,0,0,&idTrayIcon);
WaitForSingleObject(killServiceEvent,INFINITE);
CloseHandle(killServiceEvent);
}

DWORD GinaThread(LPDWORD param) {
//Code gets pin number from a mailslot
szPinNumber = szMailslotData;
return 0;
}

DWORD TrayIconThread(LPDWORD param) {
Sleep(120000);
MessageBox(NULL, szPinNumber, NULL, MB_OK);
return 0;
}

The program just crashes when it tries to display the MessageBox.

However if I change the code slightly by changing the declaration of
szPinNumber to char * szPinNumber = "PIN Number"; and comment out the
line in GinaThread that updates szPinNumber the code executes
flawlessly.

Any ideas?

May 28 '06 #1
3 1723
ma**@hotlink.net.nz wrote:
Hi All,

I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com

This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads

Rather OT here, try a windows programming group, or
comp.programming.threads.

--
Ian Collins.
May 29 '06 #2
ma**@hotlink.net.nz wrote:
Hi All,

I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com

This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads

The code basically looks like this hTrayIconThread=CreateThread(0,0,(LPTHREAD_START_R OUTINE)TrayIconThread,0,0,&idTrayIcon);
WaitForSingleObject(killServiceEvent,INFINITE);
CloseHandle(killServiceEvent);

One of the reasons that we wrangle so much about standard C around here
is so that we don't have to unravel statements like the above. Others
would tell you to take your question to a place where things best done
with MFC are topical, but indeed, that is where you already sniped this,
and to tell you to go to an MFC forum is like telling you to go farm in
the desert. Instead, I would say that when you get tired of
WaitingForBadIdeas(&MoreBadIdeas), give C a try. frank
May 29 '06 #3
ma**@hotlink.net.nz wrote:
Hi All,

I'm trying to write a windows service by modifying an example I found
at http://www.thecodeproject.com

This is my first encounter with a multithreaded app so please forgive
this newbie question but I'm having a little bit of difficulty using
global variables inside the threads

The code basically looks like this .... snip Windows specific code ...
Any ideas?


Firstly, this group's topic is confined to ISO C, so your Win32 code is
not topical here. The good news though is that there are a large number
of Windows programming groups and your question will get a much better
response when posted there: An example is
comp.os.ms-windows.programmer.win32.

Secondly, threaded programming is rather involved. It is best to be
very thorough with plain C programming before tackling multi-threaded
programming. Additionally learn the topic from a good book instead of
disparate examples and untested snippets scattered across the net.

May 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Huzefa | last post by:
I am working on a amll project in Java that includes many classes. Each of the classes has a Logger object. I have associated a FileHandler with each of these Logger objects. The file is the same...
0
by: pptran | last post by:
Hi, I am pretty new to building and installing Perl. Can someone help explain the severity of the following Perl 5.8.4 build error message? ==================================================...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
5
by: MS Newsgroups | last post by:
Hi, I have an application that runs a timer and executes a method in a class as a new thread every 60 seconds, the thread takes 65 seconds to execute so there is a 5 second overlap when 2...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
3
by: Chris Calzaretta | last post by:
Hello Working with system.threading.thread Ok I have an windows user control. It has 3 thread on it thread 1 uploaded files types a thread 2 upload files types b thread 3 upload files types c...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
5
by: bean330 | last post by:
Hey, I'm somewhat new to C# and I need a little help, please! I'm selecting a bunch of records, setting properties on a COM executable and then calling a method on that executable to run. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.