|
I want use Timer in my Service prog,and add this code:
SetTimer(NULL, 0, 1000, Timer2);
Timer2 is a function name in my deifned Class.but when the prog compile,it shows that :error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
who can tell me:what is my problem?
class CServiceWnd : public CWinThread
{
void CALLBACK Timer2(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
int m_Timer2;
..................
}
void CALLBACK CServiceWnd::Timer2(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
if(Createsocket())
{
KillTimer(NULL,m_Timer2);
}
}
void CServiceWnd::OnClose()
{
...................
m_Timer2=SetTimer(NULL,0, INTERVAl,Timer2);
}
|
|
|
|
|
Your timer callback function should either be a static member function or a global function. If you want to use a nonstatic member function as a calback then you have to jump through a few hoops. See http://www.codeproject.com/cpp/SoloGenericCallBack.asp[^] for details.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Timer32() should not be a member of the CServiceWnd class. That's why it does not match the required prototype. The this pointer is getting in the way.
One solution would be to pass NULL as the third parameter to SetTimer() , and then provide an OnTimer() function of your CServiceWnd class. From there, you can call CreateSocket() , etc.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I got a program running in multiple processes on the same machine and all of them are writing to the same log file.
I want to make sure that they are not trying to write to the log at the same time.
And need some sort of locking or criticalsection type of thing that works over different processes.
Any one got any tips?
|
|
|
|
|
|
You probably want it to be a named mutex unless your log code is in a common dll and you have declared the mutex in a shared section.
John
|
|
|
|
|
If you are also guarding against multiple USER sessions, you need to be aware of terminal services issues, and also to apply more than 'NONE', EMPTY', or 'NULL DACL' security on the synchronization object or no one else will be able to open it up right all the time.
I am pulling my few remaining hairs out sorting this all out for terminal services and Windows XP Fast User Switching.
|
|
|
|
|
Aside from the mutex, you can open your log file exclusively. I believe the CFile::Open function returns a bool if the file opens, so if your file doesn't open, it means somebody else (another app) is using that file, so just let your app keep trying until it gets access. I wouldn't go trying this on a file where more than a few applications (threads) are going to be using it, but it's a cheap little way of assuring you have exclusive access to your file. However, the code can get a little tricky because you also need to make sure that the file actually exists before you enter a loop that tries to open it exclusively...otherwise your program will go into an infinite loop. The only real benefit of using this method is that you can share your log file on a network, and have your application on multiple computers share it...don't know if you're getting that complex or not (if you are, look into using a database instead.) Good luck
|
|
|
|
|
I'm writing a C++ DLL and am trying to incorporate a call to the FlashWindowEx API. Yet when I compile it errors out that it does not know this API call (error C2065: 'FlashWindowEx' : undeclared identifier). I added the winuser.h file to my code and the user32.lib to my project properties. Still is does not find it.
Has anyone got any suggestions?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
|
Michael
Not sure this pertains to me. As I'm writting this on a laptop that has VS 6.0 and .NET studio with MSDN for .NET 2003 installed on it. Also this app is only intended to run on XP or 2000.
Here is a break down of my app header file:
#ifdef WINSTYLE_EXPORTS<br />
#define WINSTYLE_API __declspec(dllexport)<br />
#else<br />
#define WINSTYLE_API __declspec(dllimport)<br />
#endif<br />
<br />
<br />
<br />
extern WINSTYLE_API char nWinStyle; <br />
WINSTYLE_API int GetCloseWin(char);<br />
WINSTYLE_API int GetOpenWin(char);<br />
WINSTYLE_API int GetCloseApp(char);<br />
WINSTYLE_API int SetWinFocus(char);<br />
WINSTYLE_API int SetWinFocusEx(char);<br />
and my stdafx.h file
<br />
#if !defined(AFX_STDAFX_H__4D8BF925_F169_11D4_8093_0050DA27906F__INCLUDED_)<br />
#define AFX_STDAFX_H__4D8BF925_F169_11D4_8093_0050DA27906F__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
<br />
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers<br />
<br />
#include <windows.h><br />
<br />
<br />
<br />
#endif // !defined(AFX_STDAFX_H__4D8BF925_F169_11D4_8093_0050DA27906F__INCLUDED_)<br />
Do I still need to add the defines even though it will never run on anyhting below W2k?
Thanks for the help.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
Do I still need to add the defines even though it will never run on anyhting below W2k?
Yes, from the FAQ:By default, you can only use functions in Windows 95, NT 3.51, and pre-IE3 common controls. To use APIs introduced in later versions of Windows or the common controls, you need to #define the above symbols correctly before including any Windows headers. To be safe, I always define those symbols no matter what. Some of the headers will override the defaults, for example some headers will have this:
#ifndef _WIN32_IE
#define _WIN32_IE 0x0500
#endif but then you're at the mercy of whoever wrote the header file and what he thought a "good" version was.
Here's what I use:
#define WINVER 0x0500
#define _WIN32_WINDOWS 0x0410
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0501 which enables features in 98+, 2000+, and IE 5+.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
You cannot stop me with paramecium alone!
|
|
|
|
|
I added these define statements before my header files and now I'm down to one error but it's the same one.
One other question. Do I need to add the
Michael Dunn wrote:
#ifndef _WIN32_IE#define _WIN32_IE 0x0500#endif
Statement after the defines statments and insclude all the different defines?
Any other suggestions?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
|
This is really strange. I've added in the defines and it still does not find the function. When I search the winuser.h file for the function is does not exist. It resides in the winuser.h file in the include folder under .NET studio.
According to MSDN is says that it is defined in the winuser.h file and is compatable on 98 on up. If I copy over the file from .NET studio to the VC98 then I get 53 errors.
Has anyone used this function on a regular C++ app before?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi,
I´ve have written an Outlook automation (whith wrapper classes).
After this Outlook crashes sometimes without any known reason.
Outlook starts an dialog where the user can send this report to Microsoft.
What kind of problems could Outlook have after automation ?
Is there a way to find the problem in the report ?
regards, JohnX
|
|
|
|
|
Does anyone know how I can get the VS.Net IDE to show me a list of the available messages for a control that's created dynamically in a view? You know, like you get when you select a control on a dialog or a form in the res editor... It's a pain to code this stuff manually
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
Why not place the control on the form in the res editor, write all the code to handle it, then remove the control from the form?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Well, I'm not using a form, I'm putting the control in a CView. I decided to throw together a junk project and use it to do like you suggested, but I still have to copy/paste in all the wiring. Oh well...
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
yeah, sometimes life can be a bee with an itch.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Where do you allocate the space for nomarchc?
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Yes this code will not even compile. I assume name is incorrect.
John
|
|
|
|
|
sorry
it was wrong i edited it and it still gives me an error
|
|
|
|
|
don't the following work ?
<font style="color:blue;">#include</font> <stdio.h> <font style="color:green;">
<font style="color:blue;">#include</font> <stdlib.h> <font style="color:green;">
<font style="color:blue;">#define</font> MAX_WORD 51
<font style="color:blue;">int</font> main (<font style="color:blue;">void</font>) {
<font style="color:blue;">char</font> nomarchc[MAX_WORD];
printf(<font style="color:gray;">"insert file name:"</font>);
scanf(<font style="color:gray;">"%50s"</font>, nomarchc);
return 0;
}
your problem with free() can come from your
name=(char*)malloc((sizeof(char))*MAX_WORD);<br /> line, where you allocate a memory area, but you store it into name instead of nomarch...
TOXCCT >>> GEII power
|
|
|
|
|
one problem that i can see is that if you type more than MAX_WORD i.e 51 chars it will give problem. free will cry.
|
|
|
|