assertion faliure
-
I am creating an application which will read data from a smart card and send it across to a server on the network it is an MFC dialog based application i am a starter with VC++ whenever i compile my application it shows me error: Assertion failure in afxwin1.inl at line 27 the code at line 27 is: { ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; } if i ignore it my application runs fine but this error is not fine. i am using VC++ 6.0 it comes if i add SCard SCManager; to be a global variable in my app SCard definition is: class SCard : public CWnd { public: SCard(); public: LONG GetDataString(CString &DataStream, DWORD &dwRecvLength); CString GetErrorMessage(LONG lReturn); LONG m_SCardConnect(); void m_SCardSelectReader(); LONG m_SCardReleaseConext(); LONG m_SCardEstablishContext(); CString m_SCardListReaders(); CString m_SelectedReader; // the selected reader SCARDHANDLE m_hCardHandle; // handle to the card SCARDCONTEXT m_hSC; //context handle to the card virtual ~SCard(); protected: CString m_csReaderList; //list of available readers. DECLARE_MESSAGE_MAP() }; please help me
-
I am creating an application which will read data from a smart card and send it across to a server on the network it is an MFC dialog based application i am a starter with VC++ whenever i compile my application it shows me error: Assertion failure in afxwin1.inl at line 27 the code at line 27 is: { ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; } if i ignore it my application runs fine but this error is not fine. i am using VC++ 6.0 it comes if i add SCard SCManager; to be a global variable in my app SCard definition is: class SCard : public CWnd { public: SCard(); public: LONG GetDataString(CString &DataStream, DWORD &dwRecvLength); CString GetErrorMessage(LONG lReturn); LONG m_SCardConnect(); void m_SCardSelectReader(); LONG m_SCardReleaseConext(); LONG m_SCardEstablishContext(); CString m_SCardListReaders(); CString m_SelectedReader; // the selected reader SCARDHANDLE m_hCardHandle; // handle to the card SCARDCONTEXT m_hSC; //context handle to the card virtual ~SCard(); protected: CString m_csReaderList; //list of available readers. DECLARE_MESSAGE_MAP() }; please help me
It's possibly trying to initialise SCManager before your CWinApp instance? Try doing this, see if it makes a difference:
- Declare SCManager as
SCard *SCManager
- In your CWinApp's InitInstance, include the code
SCManager = new SCard;
That way, you're delaying the use of CWinApp in SCManager construction until the CWinApp is constructed? [edit]Forgot to say - global variables are bad, m'kay?[/edit]
- Declare SCManager as
-
It's possibly trying to initialise SCManager before your CWinApp instance? Try doing this, see if it makes a difference:
- Declare SCManager as
SCard *SCManager
- In your CWinApp's InitInstance, include the code
SCManager = new SCard;
That way, you're delaying the use of CWinApp in SCManager construction until the CWinApp is constructed? [edit]Forgot to say - global variables are bad, m'kay?[/edit]
thanks for your interest but now the code wont compile with 2 errors. error 1: error C2040: 'SCManager' : 'class SCard *' differs in levels of indirection from 'class SCard' AT SCard *SCManager; error 2: error C2582: 'SCard' : 'operator =' function is unavailable AT SCManager = new SCard; ----------------------------------------------------------------------------------- for the 2nd error my opinion is that i will need to override 'operator =' as we do in turbo c++. i also do have an initial guess the inline assert says someting about application name _AFXWIN_INLINE LPCTSTR AFXAPI AfxGetAppName() { ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; } my idea is if i somehow set afxCurrentAppName to NULL wont it rule out??
- Declare SCManager as
-
thanks for your interest but now the code wont compile with 2 errors. error 1: error C2040: 'SCManager' : 'class SCard *' differs in levels of indirection from 'class SCard' AT SCard *SCManager; error 2: error C2582: 'SCard' : 'operator =' function is unavailable AT SCManager = new SCard; ----------------------------------------------------------------------------------- for the 2nd error my opinion is that i will need to override 'operator =' as we do in turbo c++. i also do have an initial guess the inline assert says someting about application name _AFXWIN_INLINE LPCTSTR AFXAPI AfxGetAppName() { ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; } my idea is if i somehow set afxCurrentAppName to NULL wont it rule out??
Well, obviously if you change SCManager from SCard to SCard*, you need to alter the references to it - I thought that went without saying - obviously not.
-
Well, obviously if you change SCManager from SCard to SCard*, you need to alter the references to it - I thought that went without saying - obviously not.
oops sorry didnt see that coming sorry for the lame reply well now i tried id again but with more number of errors. the previous two remain when i have changed all refrences from SCManager.function() to SCManager->function() new error says that scard does not have an overloaded operator -> ??? what exactly to interpret from this? in my dialog class i define variable as extern SCard SCmanager how to deal with that? sorry for the silly questions wont repeat that..
-
oops sorry didnt see that coming sorry for the lame reply well now i tried id again but with more number of errors. the previous two remain when i have changed all refrences from SCManager.function() to SCManager->function() new error says that scard does not have an overloaded operator -> ??? what exactly to interpret from this? in my dialog class i define variable as extern SCard SCmanager how to deal with that? sorry for the silly questions wont repeat that..
Parinay Bansal wrote:
how to deal with that?
Read a good book about C++, it seems you are really lacking some fundamuntal C++ skills yet. If you declare your variable as
extern SCard SCmanager;
then it means it is not a pointer, thus you have to use the dot and not the "->" to access members. If you declare it asSCard* SCmanager
, then you have to use the "->" because it is a pointer. This is basic C++ and if you can't grasp those concepts, I'm afraid nobody will be able to help you.Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Parinay Bansal wrote:
how to deal with that?
Read a good book about C++, it seems you are really lacking some fundamuntal C++ skills yet. If you declare your variable as
extern SCard SCmanager;
then it means it is not a pointer, thus you have to use the dot and not the "->" to access members. If you declare it asSCard* SCmanager
, then you have to use the "->" because it is a pointer. This is basic C++ and if you can't grasp those concepts, I'm afraid nobody will be able to help you.Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++thank you gentlemen i was missing out on the part "extern SCard SCManager" replaced with "extern SCard *SCManager" such a fool i have been yes sir thank you for your advice, i really must go back to my c++ basics. It appears that i have missed out on very basic and important lessons which i sould have taken before starting to develop a full fledged application i will surely do that from now on. but yes thanks to you, now my code runs with no error. i will not forget to get back with any other problems i face in the future.