|
e-DJ wrote: It seems, that the = operator is not working.
operator = is not inherited. You should redefine it in your derived class.
|
|
|
|
|
Since now, I have not been working with operators. So how should my operator= be defined?
Juergen
|
|
|
|
|
e-DJ wrote: I want to create a new class derived from CTime.
Be careful not to get caught in the "is a" vs. "has a" trap.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all.
I write win service and I have simple code:
<br />
void main(void)<br />
{<br />
SERVICE_TABLE_ENTRY DispatcherTable[] =<br />
{<br />
{<br />
(LPWSTR)MYServiceName,<br />
(LPSERVICE_MAIN_FUNCTION)ServiceMain<br />
},<br />
{<br />
NULL,<br />
NULL<br />
}<br />
};<br />
<br />
printf("Sample of simple service\n(C) D. Bagaturia, 2007, Email: dato_baga@mail.ru\n");<br />
<br />
<br />
if(!StartServiceCtrlDispatcher(DispatcherTable))<br />
{<br />
CloseHandle(hMutex);<br />
return;<br />
}<br />
<br />
}<br />
Problem is that: Wen 'ServiceMain' function ends control go to main() function, and wen main() ends program ends, sow I get thet my service works less than second.
I try to write:
<br />
void main(void)<br />
{<br />
HANDEL hThread;<br />
SERVICE_TABLE_ENTRY DispatcherTable[] =<br />
{<br />
{<br />
(LPWSTR)MYServiceName,<br />
(LPSERVICE_MAIN_FUNCTION)ServiceMain<br />
},<br />
{<br />
NULL,<br />
NULL<br />
}<br />
};<br />
<br />
printf("Sample of simple service\n(C) D. Bagaturia, 2007, Email: dato_baga@mail.ru\n");<br />
<br />
<br />
if(!StartServiceCtrlDispatcher(DispatcherTable))<br />
{<br />
CloseHandle(hMutex);<br />
return;<br />
}<br />
<br />
do{<br />
GetExitCodeThread(hThread,
lpExitCode);<br />
if(*lpExitCode == STILL_ACTIVE)<br />
Sleep(150);<br />
else<br />
break;<br />
<br />
}while(1);<br />
<br />
}<br />
But in this time I get runtime error.
Wen I try to start or stop my service in ServiceManager, I get error message.
I know thet I blocked the service in case two, but I need this service more then 1 second.
Sow I have:
case 1: service runs less 1 second.
case 2: service runs but, it is blocked.
I know that I made som mistake, but whot?
|
|
|
|
|
Your original main was correct. The loop should be in the ServiceMain routine. Before entering the loop, your ServiceMain routine should call RegisterServiceCtrlHandlerEx to establish a callback routine for the SCM to call when the OS needs to change the state of your service. Typically, the ControlHandler sets some kind of signal, like an event. The loop in the ServiceMain then periodically checks for that signal.
Judy
|
|
|
|
|
Thanks all for reply, it help me.
I test my service on 'windows service 1998' and I think that my service is 'Ok', but it dont run on this operation system.
I have some manager exe file for this service and I think this exe have problem to 'operation system', sow wen I start service by this manager exe I get error code that service cant start.
Can this be true?
Tahnks again for your reply.
|
|
|
|
|
I'm asuming when you say "windows service 1998" that you are refering to Windows 98. I've never even tried to use one under anything earlier the NT4. Also, the MSDN documentation for the service control functions (both those from within the service like StartServiceCtrlDispatcher and those used by the calling program such as StartService) states they are NT4 or higher also. Looks like 98 is out.
Services are not the easiest things to debug. You just can't "start" them in the debugger. I typically put an ASSERT(false) in the very beginning of my _main function to force an exception and then begin debugging from there, putting break points into my ServiceMain function.
From your earlier post, it looks like you haven't done much with services before. Here is a basic outline of what one should look like. Note that I've omitted the error checking.
SERVICE_STATUS_HANDLE glb_sshStatusHandle;
SERVICE_STATUS glb_ssStatus;
VOID WINAPI MMServiceMain (DWORD dwArgc, LPTSTR *lpszArgv);
DWORD WINAPI MMServiceControl (DWORD dwCtrlCode, DWORD dwEventType,
LPVOID lpEventData, LPVOID lpContext);
int _tmain (int argc, TCHAR* argv[], TCHAR* envp[])
{
SERVICE_TABLE_ENTRY dispatchTable[] = {
{ "MMService", (LPSERVICE_MAIN_FUNCTION) MMServiceMain},
{ NULL, NULL} };
StartServiceCtrlDispatcher (dispatchTable);
glb_ssStatus.dwCheckPoint = 0;
return 0;
}
void WINAPI MMServiceMain (DWORD dwArgc, LPTSTR *lpszArgv)
{
glb_ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
glb_ssStatus.dwServiceSpecificExitCode = 0;
glb_sshStatusHandle = RegisterServiceCtrlHandlerEx (
"MMService", MMServiceControl, NULL);
glb_ssStatus.dwControlsAccepted = 0;
glb_ssStatus.dwCurrentState = SERVICE_START_PENDING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 5000;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
if (!Init ()) {
glb_ssStatus.dwCurrentState = SERVICE_STOPPED;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
return;
}
glb_ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
glb_ssStatus.dwCurrentState = SERVICE_RUNNING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
Run ();
glb_ssStatus.dwCurrentState = SERVICE_STOPPED;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
return;
}
DWORD WINAPI MMServiceControl (DWORD dwCtrlCode, DWORD dwEventType,
LPVOID lpEventData, LPVOID lpContext)
{
if (dwCtrlCode == SERVICE_CONTROL_STOP) {
glb_ssStatus.dwCurrentState = SERVICE_STOP_PENDING;
glb_ssStatus.dwWin32ExitCode = NO_ERROR;
glb_ssStatus.dwWaitHint = 0;
glb_ssStatus.dwCheckPoint = glb_ssStatus.dwCheckPoint++;
SetServiceStatus (glb_sshStatusHandle, &glb_ssStatus);
SetEvent (hStopEvent);
return NO_ERROR;
}
else
return ERROR_CALL_NOT_IMPLEMENTED;
}
bool Init ()
{
hStopEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
return true;
}
void Run ()
{
while (WaitForSingleObject (hStopEvent, 1) != WAIT_OBJECT_0)
{
}
CloseHandle (hStopEvent);
return;
}
|
|
|
|
|
Thanks for your help.
|
|
|
|
|
Dear all.
I install one driver that has one thread in it.
But the priority of driver is low and when I use user program which uses that driver capabilities , I find that because of low priority of driver, my program doesn't work properly.
I dont have the source code of drivers.
But I want to set my driver priority to real time .
Is it possible to do this.
If it is possible please let me know how I can do it.
I use following functions to install driver.
to install driver I use :
hService = ::CreateService(hSCManager, "Webcam",
"Webcam", SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, PathOfDriver,
NULL, NULL, NULL, NULL, NULL)))
to start driver I use :
2. hService=OpenService(hscManager,NT_DRIVER_FILE,SERVICE_START)
in application which uses th capabilities of driver I use following functions to make programs priority high.
SetPriorityClass()
SetThreadPriority()
|
|
|
|
|
hi
I have enumed all computer in my workgroup by API function NetServerEnum,but i can't enum more about another workgroup's computer.
so my question is how can i get all computer in lan.
my code is here
CString strTemp;
CString strname="";
LPSERVER_INFO_101 pBuf = NULL;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_DOMAIN_ENUM ;
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
unsigned short * pszServerName = NULL;
char szOut[2048];
// DWORD i;
// DWORD dwServerType = SV_TYPE_DOMAIN_ENUM; // all servers
// LPSERVER_INFO_101 pTmpBuf;
// Call the NetServerEnum function to retrieve information
// for all servers, specifying information level 101.
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
NULL,
&dwResumeHandle);
thanks!
|
|
|
|
|
|
Hi,
Can anybody tell me what is the difference between DirectX sdk and DirectX interfaces that is If iam using DirectX Dec 2006 release sdk and DirectX8 interface(what is the difference between this two)???
Thanks in Advance.
Siddharth
|
|
|
|
|
The SDK is the software development kit. DirectX8 refers to major version 8 of the directX
runtime. For the most part, DirectX interfaces are backward-compatible - if you are using
version 8 then that includes all previous versions.
So, if you are developing using a version of the SDK that supports DirectX version 8 and you run
your software on a machine with DirectX version 9 installed then you're fine. Using version 9
interfaces on a machine with version 8 installed wll not work.
Did that make any sense?
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi,
I need to draw something in the background area of the edit control.
I tried to do it in the OnEraseBkgnd. But the text has its own background, so i just made the bk mode transparent using SetBkMode in the CtlColor. Now I could draw the background but the antialiasing of text makes problem. Also there is repainting problem while scrolling.
- NS -
|
|
|
|
|
You need to change the backgroundcolor of a Textbox?
|
|
|
|
|
Not simply the background color. But want to draw some lines, etc., (for eg. some grid lines of 2 pixel spacing) in the background.
- NS -
|
|
|
|
|
You can use of WM_CTLCOLOREDIT for change color of text and background
|
|
|
|
|
Hello,
If I have
class A
{
A();
};
A::A()
{
}
Now I want an object which I get like this
A *Aobject = new A;
But If I have a template class B whose type is A* then
while initializing the template class B the constructor A() has to be called.
But what happens is that the constructor A() is not called while initializing template class B.What must be the problem.
The same template class works for my other classes where there is no use of new operator.
In what way should I incorporate new in the costructor A,since I want A* as my template type.
Prithaa
|
|
|
|
|
prithaa wrote: But If I have a template class B whose type is A* then
while initializing the template class B the constructor A() has to be called.
Then you need to do it. I think you should first review how template works, this has nothing to do with inheritance.
How is your template 'parameter' used ? Is it a template member of your class B ? Something like this:
template <class T>
class B
{
...
...
T* m_Object;
};
And used this way ?
B<A> classB;
If yes, then you will need to instanciate the object in the constructor of B.
But, this highly depends of how you are using your template... Can you post some code so that we have a better view of your problem ?
|
|
|
|
|
Hello,
Thanks for you reply
This is my code snippet
class CRICH : public CRichEditCtrl
{
// Construction
public:
CRICH();
void Fill(CFont& H,Variant Data);
void Create1(CView *pView,CRect Rect,int index);
bool operator =(CRICH& c);
};
The following is a template class
template <class T> class TDataTable
{
public:
TDataTable();
TDataTable(int m, int n);
void constructor(int m,int n);
void clear() {m_numRow=m_numCol=0; TData.clear();};
void InsertRow(int rowno);
void DeleteRow(int rowno);
void AddRow();
int numRow() {return m_numRow;};
int numCol() {return m_numCol;};
T& operator() (int i,int j) {return TData[m_numCol*i+j];}
vector<T> GetOneRow(int i);
//virtual ~TDataTable();
private :
int m_numRow, m_numCol;
vector<T>TData;
T tdefault;
};
The following is the function constructor which I want to call while initializing objects in a vector
template <class T> void TDataTable<T>::constructor(int m, int n)
{
tdefault = T();
m_numRow = m; m_numCol = n;
TData.assign(m_numRow*m_numCol, tdefault);
}
If I call the function constructor() like the following
TDataTable<crich*> m_TableForDisplay;
m_TableForDisplay.constructor(row,col);
now TData is not initialized and while debugging if I press F11 at the point
tdefault = T();
then the constructor of CRICH is not called.
but for other of my classes their respective constructors
are called and tdefault gets initialized
Thanks
Prithaa
|
|
|
|
|
Can any one tell to me thet how to use SetPrinterDataEx() function to set the registry value. i am trying to do this:
DWORD dw=SetPrinterDataEx(hPrinter,"PrinterDriverData","monica",REG_BINARY,(PBYTE)p,1);
it compiled overall prgram but not set registry key(name "monica").it returns 'dw =5'. what is meaning of '5 value of dw'.
Thanks
Monica
|
|
|
|
|
mo_nica881 wrote: DWORD dw=SetPrinterDataEx(hPrinter,"PrinterDriverData","monica",REG_BINARY,(PBYTE)p,1);
Can you show how variable p is defined ?
mo_nica881 wrote: what is meaning of '5 value of dw'.
Access denied.
Check you have all right to do this operation.
|
|
|
|
|
Hello,
If I have a class
class A
{
int *myint;
};
I can initialize the above member variable like this
int *myint = new int;
so that a pointer is initialized on the heap and I will have to delete it.
But if I have to initialize the member variable in the constructor of a class how should I do it using new?
Thanks
Prithaa
|
|
|
|
|
Exactly the same but in the constructor:
A::A()
{
myint = new int;
}
Don't forget to destroy it in the destructor of your class then.
|
|
|
|
|
Although you can simply write,
myint = new int;
Be aware while using assignment operator or copy constructor. If you are not cautious, will end up with dangling pointers.
|
|
|
|
|