|
Have the same problem if i include afxwin.h IN stdafx.h
Could it be that my .dll is a win32 and cannot run MFC classes?
|
|
|
|
|
How would i get around this using a Win32 dll trying to implement an MFC class like CwinThread? If this is not possible, what are my thread options. I am simply creating a waitable timer but wanted to do this in a thread.
thanks,
|
|
|
|
|
If all you are using is CWinThread from MFC, then you really don't need the
entire MFC library. Just use what's appropriate for a given module:
Module uses Use this to create a thread
------------ -------------------------------
MFC: CWinThread
CRT (no mMFC): _beginthread()/_beginthreadex()
No CRT or MFC: CreateThread() Windows API
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
An MFC DLL is a Win32 DLL. Getting it to compile has nothing to do with
the type of DLL.
The MFC header file(s) and/or Windows SDK header files need to be included
in a certain order.
Again, if you need to know for sure how to order the includes correctly,
create a temporary MFC project with the wizard and copy the way
stdafx.h is layed out. It's better than trying to guess.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi ,
I have a requirement , where I want one entity to be persistent in the computer.
I am struggling to decide on what this entity will be .
My model is such that I want to be able to intercept USB device notifications utilizing the WM_DEVICE_CHANGE messages by creating a hidden window in this entity and then update the elements of a system tray icon ( which exposes a Menu ) .
So my requirement does not fit the Client Server model , yet I am leaning towards COM to provide one EXE that does it all . So in other words , this entity will not provide any APIs for other clients to use . Am I unnecessarily using COM ?
So finally I need to finalize the form that this need to take .
Service - actually the Visual Studio 6 gives the option to create a COM Object as a Service.
COM DLL
COM EXE
Standalone EXE ?
Your inputs are really appreciated
Engineering is the effort !
|
|
|
|
|
I think a stand alone exe will do the trick. You can prevent more than one instance running at a time easily enough with a named mutex. You can have the main window as your hidden window which keeps things simple, perhaps one DLL to encapsulate the system tray icon stuff, I've seen that done well although it's not easy unless you're targetting only XP or only Server 200?, and another to encapsulate the USB WM_DEVICE_CHANGE stuff, I've written one like that but it's closed source . I can tell you that you may need to download a DDK to get the correct headers for the defines you might need, again if you use any XP and upward only defines it won't work on earlier system. Win2K in the earliest that has usably reliable USB device stuff although some things work a bit on Win98.
Do you need COM? You might need a little to get the System tray stuff to work, It's been too long since I looked at it, but nothing more complex than emulating a VB enumeration type if that.
A Service? No as long as you can start your app on or near startup and automatically I can't see the need for it being a service. A service shouldn't interact with the UI anyway so not if it's going to have an icon. Remember to scan for already plugged in USB devices on startup and also that they can be reported as fixed or removable, sometimes depending on the chipset revision on the removable media in the removable drive!
Enjoy
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I have two different object CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING. These two classes both inherit four other classes that are similar but not identical. The functions names and parameter of the different inherited classes are identical but the code is not.
I am have difficultly finding a way to create a generic class object pointer and then useing the new operator. I am finding it difficult because, i don't have a way to create a generic base class because of the four other objects inherited(CLX_LENZE_LIFT_INVERTOR,etc.) I was thinking may i could do something with templates or null pointer( void *inverter; inverter = new CLX_MITSUBISHI_POLLING();) Unfortunately, the null pointer did not work. Any recommendations would be greatly a appreciated.
Cheers Scott
<br />
CLX_POLLING *Invertors;<br />
<br />
if( inverter_type == MITSUBISHI )<br />
Invertors = new CLX_MITSUBISHI_POLLING;<br />
else <br />
Invertors = new CLX_LENZE_POLLING;<br />
My CLX_MITSUBISHI_POLLING clases
<br />
#pragma once<br />
#include "windows.h"<br />
#include "ClxThread.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxMitsubishiParameters.h"<br />
#include "ClxMitsubishiLiftInvertor.h"<br />
#include "ClxMitsubishiPitchInvertor.h"<br />
#include "ClxMitsubishiRollInvertor.h"<br />
#include "ClxMitsubishiCounterWeightInvertor.h"<br />
<br />
class CLX_MITSUBISHI_POLLING : <br />
public ClxThread,<br />
public CLX_MITSUBISHI_PITCH_INVERTOR,<br />
public CLX_MITSUBISHI_ROLL_INVERTOR,<br />
public CLX_MITSUBISHI_LIFT_INVERTOR,<br />
public CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR<br />
{<br />
public:<br />
CLX_MITSUBISHI_POLLING(void);<br />
~CLX_MITSUBISHI_POLLING(void);<br />
bool mStartPolling(void){ return CreateNewThread(); } <br />
<br />
<br />
private:
unsigned short m_BaudRate;<br />
int m_CommPort;<br />
int m_SerialPortHandlePolling; <br />
public: <br />
bool mvInitComm( int comm_port, int baud_rate );<br />
bool mvCloseComm( void );<br />
bool mvRestartComm( void ); <br />
void mvSetBaudRate(int value);<br />
unsigned short mvGetBaudRate(void);<br />
void mvSetCommPort(int value);<br />
unsigned short mvGetCommPort(void);<br />
int mvGetSerialPortHandle( void );<br />
void mvSetSerialPortHandle( int );<br />
private:<br />
int mvPutByte( char txdata );<br />
int mvPutPacket( int lenght, char txdata[] ); <br />
int mvGetBytes( void );<br />
int mvFlushRxBuf( void );<br />
int mvFlushTxBuf( void );<br />
int mvGetRxBuf(void);<br />
int mvGetTxBuf(void); <br />
bool mvIsOverrunErrors(void);<br />
bool mvIsParityErrors(void);<br />
bool mvIsRxBufferEmpty(void);<br />
bool mvIsTxBufferEmpty(void);<br />
int mvGetRxBufferSize(void);<br />
int mvGetTxBufferSize(void);<br />
private: <br />
void ThreadRun(void);<br />
CRITICAL_SECTION m_csMitsubishiPolling;<br />
};
My CLX_LENZE_POLLING clases
#pragma once<br />
#include "windows.h"<br />
#include "ClxThread.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxLenzeRollInvertor.h"<br />
#include "ClxLenzeLiftInvertor.h"<br />
#include "ClxLenzePitchInvertor.h"<br />
#include "ClxLenzeCounterWeightInvertor.h"<br />
<br />
<br />
<br />
class CLX_LENZE_POLLING : <br />
public ClxThread,<br />
public CLX_LENZE_PITCH_INVERTOR,<br />
public CLX_LENZE_ROLL_INVERTOR,<br />
public CLX_LENZE_LIFT_INVERTOR,<br />
public CLX_LENZE_COUNTERWEIGHT_INVERTOR<br />
{<br />
public:<br />
CLX_LENZE_POLLING(void);<br />
~CLX_LENZE_POLLING(void);<br />
bool mStartPolling(void){ return CreateNewThread(); } <br />
<br />
private: <br />
void ThreadRun(void);<br />
CRITICAL_SECTION m_csLenzePolling;<br />
<br />
private:
unsigned short m_BaudRate;<br />
int m_CommPort;<br />
int m_AllSerialPortHandle; <br />
public: <br />
bool mvInitComm( int comm_port, int baud_rate );<br />
bool mvCloseComm( void );<br />
bool mvRestartComm( void ); <br />
void mvSetBaudRate(int value);<br />
unsigned short mvGetBaudRate(void);<br />
void mvSetCommPort(int value);<br />
unsigned short mvGetCommPort(void);<br />
int mvGetSerialPortHandle( void );<br />
void mvSetSerialPortHandle( int );<br />
private:<br />
int mvPutByte( char txdata );<br />
int mvPutPacket( int lenght, char txdata[] ); <br />
int mvGetBytes( void );<br />
int mvFlushRxBuf( void );<br />
int mvFlushTxBuf( void );<br />
int mvGetRxBuf(void);<br />
int mvGetTxBuf(void); <br />
bool mvIsOverrunErrors(void);<br />
bool mvIsParityErrors(void);<br />
bool mvIsRxBufferEmpty(void);<br />
bool mvIsTxBufferEmpty(void);<br />
int mvGetRxBufferSize(void);<br />
int mvGetTxBufferSize(void);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
};
All the below classes are identical except for function name which will be Lift, Roll, Pitch, or CounterWeight accordingly. The inherited PARAMETERS contains function to send and recieve packets. It also has a some virtual function such as mvGetByte, mvPutByte. mvSetCommPort. This virtual function are overrided in CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING so the all the inherited classes use the same serial port. The only differents in LENZE or MITSUBISHI is in the individual functions.
CLX_LENZE_PITCH_INVERTOR
CLX_LENZE_ROLL_INVERTOR
CLX_LENZE_LIFT_INVERTOR
CLX_LENZE_COUNTERWEIGHT_INVERTOR
CLX_MITSUBISHI_PITCH_INVERTOR
CLX_MITSUBISHI_ROLL_INVERTOR
CLX_MITSUBISHI_LIFT_INVERTOR
CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR
<br />
#pragma once<br />
#include "Windows.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxMitsubishiParameters.h"<br />
<br />
<br />
class CLX_MITSUBISHI_LIFT_INVERTOR : <br />
public CLX_MITSUBISHI_PARAMETERS<br />
{<br />
public:<br />
CLX_MITSUBISHI_LIFT_INVERTOR(void);<br />
~CLX_MITSUBISHI_LIFT_INVERTOR(void);<br />
<br />
void LiftSetAddress( char address ); <br />
char LiftGetAddress( void ); <br />
<br />
void LiftSetJogFrequency( double value );<br />
double LiftGetJogFrequency( void );<br />
<br />
void LiftSetConfigurationVoltage( int volts ); <br />
int LiftGetConfigurationVoltage( void ); <br />
<br />
bool LiftisConnected( void );<br />
bool LiftisInhibited( void );<br />
bool LiftisActiveFault( void );<br />
bool LiftisBootMode( void );<br />
bool LiftisSerialMode( void );<br />
bool LiftisAnalogMode( void );<br />
bool LiftisUnknownMode( void ); <br />
<br />
bool LiftGetBusVoltage( double *dTemp);<br />
bool LiftGetOutputVoltage( double *dTemp); <br />
bool LiftGetOutputCurrent( double *dTemp); <br />
bool LiftGetOutputFrequencey( double *dTemp); <br />
bool LiftGetOutputTemperature( double *dTemp );<br />
bool LiftGetPoweronTime( double *dTemp); <br />
bool LiftGetOperatingTime( double *dTemp); <br />
<br />
bool LiftGetActiveFault( int *iTemp ); <br />
bool LiftGetLastFault( int *iTemp); <br />
bool LiftGetLastFault2( int *iTemp); <br />
bool LiftGetLastFault3( int *iTemp); <br />
<br />
bool LiftInitDefaultsCmd(void); <br />
bool LiftDriveStateCmd(void); <br />
bool LiftAutotuneCmd(void); <br />
bool LiftEnableCmd( void ); <br />
bool LiftDisableCmd( void ); <br />
bool LiftAnalogModeCmd( void ); <br />
bool LiftAnalogBrakeNormalCmd( void ); <br />
bool LiftAnalogBrakeInvertedCmd( void );<br />
bool LiftSerialModeCmd( void ); <br />
bool LiftSerialBrakeNormalCmd( void ); <br />
bool LiftSerialBrakeInvertedCmd( void ); <br />
bool LiftResetFaultsCmd( void ); <br />
bool LiftJogCwCmd( void ); <br />
bool LiftJogCcwCmd( void ); <br />
bool LiftJogStopCmd( void ); <br />
<br />
void LiftDisableParity( void ) { DisableParity(); }<br />
void LiftEnableParity( void ) { EnableParity(); }<br />
bool LiftGetParity( void ) { GetParity(); }<br />
void LiftSetRxTimeout( unsigned long value ) { SetReceiveTimeout(value); }<br />
int LiftGetRxTimeout( void ) { return GetReceiveTimeout(); }<br />
void LiftSetRxRetryNum( int value ); <br />
int LiftGetRxRetryNum( void );<br />
<br />
void LiftRun( void );<br />
<br />
private:<br />
bool LiftActivateCmd( char incmd );<br />
<br />
ClxSafeQue<char> m_sqCmdQue;<br />
CRITICAL_SECTION m_csLock; <br />
<br />
char m_cAddress;
double m_dJogFrequency;
int m_cConfigurationVoltage; <br />
bool m_bActiveFault;
bool m_bConnected;
bool m_bInhibited;
bool m_bIsBootMode;
bool m_bIsSerialMode;
bool m_bIsAnalogMode;
bool m_bIsUnknownMode;
bool m_bValidDriveState; <br />
double m_dBusVoltage;
bool m_bValidBusVoltage; <br />
double m_dOutputVoltage;
bool m_bValidOutputVoltage; <br />
double m_dOutputCurrent; <br />
bool m_bValidOutputCurrent; <br />
double m_dOutputFrequencey; <br />
bool m_bValidOutputFrequencey; <br />
double m_dOutputTemperature; <br />
bool m_bValidOutputTemperature; <br />
double m_dOperatingTime; <br />
bool m_bValidOperatingTime; <br />
double m_dPowerOnTime;
bool m_bValidPowerOnTime; <br />
int m_iActiveFault;
bool m_bValidActiveFault; <br />
int m_iLastFault; <br />
bool m_bValidLastFault; <br />
<br />
int m_iLastFault2;
bool m_bValidLastFault2; <br />
<br />
int m_iLastFault3;
bool m_bValidLastFault3; <br />
<br />
<br />
unsigned long m_lCurrentNumTxPktFailed; <br />
unsigned long m_iMaxinumNumTxPktFailures; <br />
unsigned long m_lTotalNumTxPktFailed; <br />
unsigned long m_lTotalNumTxPktCount; <br />
char m_cPollingCommandIndex;<br />
<br />
<br />
};<br />
<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Are you sure you provided the smallest amount of code required to understand your problem?
From "How to get an answer to your question":
#4 Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
led mike
|
|
|
|
|
It's not a easy simple C++ Question.
Scott
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
|
|
Mark Salsbery wrote: See what I've done here?
No, but I can picture you flopping all around inside his boat.
led mike
|
|
|
|
|
|
Mark Salsbery wrote: We need a fish smiley!
That would be so great, I'd ask Chris for one if I thought there was any chance of getting it.
led mike
|
|
|
|
|
Hello. there is the variable app.previnstance in visualbasic 6 to know if the application is already open. How can i do that using Win32 API?
i saw there's a variable in the winmain() function called hPrevInstance, but i do not know how to use it.
Any help would be welcome.
thanks
|
|
|
|
|
I use a semaphore to detect if there is already an instance of the application running.
Heres what I use:
CString szGuid;
szGuid= _T("Create your own unique GUID here, I used guidgen.exe");
m_hSem=CreateSemaphore(NULL, 1, 1, szGuid);
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
TCHAR szCaption[_MAX_FNAME];
LoadString(m_hInstance,AFX_IDS_APP_TITLE,szCaption,_MAX_FNAME);
CWnd* pwndFirst = CWnd::FindWindow(NULL,szCaption);
if (pwndFirst)
{
CWnd* pwndPopup = pwndFirst->GetLastActivePopup();
pwndFirst->SetForegroundWindow();
if (pwndFirst->IsIconic())
{
pwndFirst->ShowWindow(SW_SHOWNORMAL);
pwndFirst->PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
if (pwndFirst != pwndPopup)
{
pwndPopup->SetForegroundWindow();
pwndPopup->PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
}
CloseHandle(m_hSem);
return FALSE;
}
Note that this code will bring the previous instance to the foreground.
Don't forget to CloseHandle(m_hSem) when your application exits.
-Randor (David Delaune)
|
|
|
|
|
|
You cannot use hPrevInstance , the reason why is here.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
There's only one way I know of that is bullet proof:
http://www.flounder.com/nomultiples.htm[^]
The other ways may fail if certain conditions are not satisfied. You can the reasons why in the article above.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I am a total stranger to windows service development.
I needed to understand the limitations .
1. Is it possible to have MFC support in Service code?
2. Can I create a hidden window in a Service ?
My basic requirement is to intercept WM_DEVICE_CHANGE notifications to process this message.
Engineering is the effort !
|
|
|
|
|
Yes, you can (1 and 2), you must set the service to be able to interact with the desktop.
Moreover you can use XYNTService (you can easily find it here) in order to use any app as a service.
Hope this helps.
|
|
|
|
|
No need to interact with the desktop for hidden windows.
That's only if you want a user to see the windows, which is really frowned upon
from services going forward with Vista+.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hello,
long title, short story: a rather old third-party library uses the following code to register its own edit control class:
static const TCHAR BASED_CODE szEdit[] = _T("GXEDIT");<br />
WNDCLASS wcls;<br />
if (!::GetClassInfo(hResource, szEdit, &wcls))<br />
{<br />
VERIFY(::GetClassInfo(NULL, _T("edit"), &wcls));<br />
<br />
wcls.style |= GX_GLOBALCLASS;<br />
wcls.hInstance = hResource;<br />
wcls.lpszClassName = szEdit;<br />
<br />
AfxRegisterClass(&wcls);
This works fine unless XP themes are enabled.
If they are and I use GetWindowText(CString-variable) with this edit control, the CString destructor causes a heap corruption because ::GetWindowTextLength reports less bytes than ::GetWindowText actually receives, and thus CString::GetBufferSetLength allocates not enough memory.
Is there a simple solution to change the above code so that this GXEDIT works with XP themes?
I already tried rewriting it using WNDCLASSEX instead, but that didn't help.
adTHANKSvance, Jens
|
|
|
|
|
Are you sure there is such a bug affecting GetWindowTextLength ? I cannot find related info.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|