|
Hello All, I have client and server programs. They used NamedPipe to communicate.
Here little bit about what each program does.
Server:
- has 2 buttons, print and stop
- Once the print button get pressed, create the thread and call the thread function.
here the thread function,
<br />
UINT PrintingThreadFunction(LPVOID lParam)<br />
{ <br />
CServerDlg *s = ((CServerDlg *)lParam);<br />
s->m_smain.OpenNewPipe(); <br />
while(!stopprinting)<br />
{ <br />
s->m_smain.ClientPrinting();
if(stopprinting == (int)YES)<br />
{<br />
s->m_smain.CloseThePipe(); <br />
break;<br />
}<br />
} <br />
stopprinting = (int)NO;
return (0);<br />
}<br />
The ClientPrinting() calls ConnectNamedPipe() which waits for the client to connect and then once the client connect to the pipe, it returns.
Client:
Client gets the file name from database and print it out. Then send the file name to Server using the same pipe.
Server has no problem Client's getting connected and sending a printed file name for 9 times. But at 10th time, Server get error message at ConnectNamePipe() which is
Unhandled exception at 0x0043e4cb in Server.exe: 0xC0000005: Access violation reading location 0x000000e4.
How can I eliminate this error?
I am thinking of using PostMessage(). But how the program also listen to the user click on Stop button?
Is stopping what the programs is doing for 10 seconds so the user can click on the quit button will help?
Thank you
|
|
|
|
|
I am thinking of using PostMessage(). But how the program also listen to the user click on Stop button?
Not sure of what the "stopprinting" is but would suggest to use event instead like this
<br />
if(WaitForSingleObject(<br />
yourStopEventHandle,<br />
INFINITE<br />
)== WAIT_OBJECT_0)<br />
{<br />
}<br />
check the event tutorial avail.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Having trouble getting this to work.
Need to control backlight level of LCD display.
Followed instructions for IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS and not getting any errors, but not getting any 'levels' back either.
Has anyone else tried using this API yet?
|
|
|
|
|
Hi !
I have to variables of type long. now i need to exponent the first with the second and then modulus a third long. how can i realize this ???
please Help
MFG
RedDragon2k
Unix and C are the ultimate computer viruses.
Visit me: www.programming.info.ms
|
|
|
|
|
long value = pow(long1, long2) % long3;
you need to include <math.h>
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thx. But when i compile it i get the following error :
'%': Illegal, left operand has type 'double'
Unix and C are the ultimate computer viruses.
Visit me: www.programming.info.ms
|
|
|
|
|
MSDN says: The modulus operator (%) has a stricter requirement in that its operands must be of integral type.
just cast the pow() function to a (long)
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Try this...
long value = ((long)pow(long1, long2)) % long3;
Jeremy Falcon
|
|
|
|
|
I suggest you do it manually with repeated multiplings and the apply the modulus
gabby
|
|
|
|
|
I am creating a small application that is going to run on a network. I need to know the number of people that are running the application on the network. I had tried looking for an example on how to this but I can’t find any. Any help!!!
|
|
|
|
|
When the application is started, you could simply write a "counter" number to some file. There are obviously lots of implications in doing this, but it is simple.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
HMODULE hm = LoadLibrary("http://some.server.net/downloads/a.dll");
Of course I know that the above does not work. Implementing the HTTP part is no problem, but how do I simulate LoadLibrary without an actual file?
(storing the downloaded DLL in a temporary file is not an option, I want real "zero footprint")
|
|
|
|
|
when i need cast cstring into float , i always use sscanf(mystr,"%f",ftype)//float ftype
fype=atof(mystr)
but which is better ,what is the difference between them?
|
|
|
|
|
atof() will be faster because it does not have to parse a format string like sscanf() does.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
atof is faster and smaller since it does not have the overhead of a format string scanner - I would think that sscanf calls atof when it finds the %f in a format string. FYI, you are not doing a cast, you are doing a conversion.
Steve
|
|
|
|
|
hi:i create a dialog such as CMyDlg, i define a variable :CBrush m_brush,
then i in onInitDialog :m_brush.CreateSolidBrush(RGB(255,255,0))
then HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_STATIC)
{// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0));
// Set the background mode for text to transparent
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object
hbr = m_brush;
}
return hbr;
}
but the text color is not i expected,and at the back of the text ,always exist white ?how to modify?but if i do these work in main dialog ,all is ok.
|
|
|
|
|
Seems brushing is ok, so it should work. Though I want to point out two things;
1) Do not use pWnd->GetDlgCtrlID() == IDC_STATIC condition unless you assign a unique id to a static control (e.g. IDC_MYSTATIC). Instead, if you want to consider all the static controls, test against nCtlColor == CTLCOLOR_STATIC.
2) Why not to set the text color;
pDC->SetTextColor( some rgb );
--
=====
Arman
|
|
|
|
|
|
Hi
modified 12-Sep-18 21:01pm.
|
|
|
|
|
how to cast cstring into long,double?
|
|
|
|
|
_atol() , _atof()
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Hello,
I am very new to VC++6 and have a problem that is driving me crazy.
I have class defined as so:
#define True 1
#define False 0
#ifndef CLASSIFER_H_INCLUDED__
#define CLASSIFER_H_INCLUDED__
class CClassifier
{
public:
//--------------------------------------------------------------------------
// constructor
//--------------------------------------------------------------------------
CClassifier
(
LPCTSTR szCommand,
CEdit *pEdit,
LPCTSTR szCurrentDirectory = NULL
);
//--------------------------------------------------------------------------
// destructor
//--------------------------------------------------------------------------
virtual ~CClassifier();
//--------------------------------------------------------------------------
// public member functions
//--------------------------------------------------------------------------
// virtual void Run();
virtual void Run(CString& cfn);
virtual void Stop();
...
I do some processing in the Run function, and eventually have a CString variable called 'classification' that gets assigned to 'cfn' before I return.
Now, the problem is in WinXP, when I try to use an AfxMessageBox to have a debug look at the value of 'classification' inside CClassifier.Run, i.e.,
text.Format(_T("Inside Classifier.Run\nclassification = %s"),classification);
AfxMessageBox(text);
the message box fires, but 'text' has no value. Under Win2k, it works fine, just not undet WinXP.
I call the Run function like so:
m_pClassify = new CClassifier((LPTSTR)(LPCTSTR)FileBuf, &m_EditOutput);
m_pClassify->Run(classified);
where FileBuf is a CString.
The return value 'classified' does not get a value under WinXP, but it does under Win2K.
This is driving me crazy and holding up progress on my project, so I really would appreciate some help with this.
Thanks,
Murrah Boswell
|
|
|
|
|
Your problem is likely a bug in your code. You don't really give enough information to try and debug it.
XP has new memory allocator that exposes bugs in your code that previously worked. Typically, these are uninitialized pointers, re-use of deleted pointers, use of stack variables that have already been "popped", etc..
You're also using some weird casting there. Why are you casting a constant to a non-const in the constructor? Over-casting is usually a sign of error as well.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
Hello,
Thanks for the reply!
How much code do you need/want to look at? In the Run function, I am using CreateProcess to open up read/write pipes to dos batch files. I use the batch files to run a .exe file with various switches. Hence the separate batch files. The .exe file reads in files stored on disk.
Then I capture the output from the batch files (actually the .exe file) and parse it for certain key words and based on occurances of the key words, I classify the files read from disk into categories.
I will send this code if you want.
As far as the casting in the constructor, I assume you are talking about
LPCTSTR szCurrentDirectory = NULL
This is how Microsoft describes how to use the szCurrentDirectory variable in CreateProcess:
LPCTSTR lpCurrentDirectory
[in] Pointer to a null-terminated string that specifies the full path to the current directory for the process. The string can also specify a UNC path.
If this parameter is NULL, the new process will have the same current drive and directory as the calling process.
(This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.)
I really do need some help on the original problem of why WinXP returns zilch, so if you want to look at some of the code, I would appreciate it.
Thanks again,
Murrah Boswell
|
|
|
|