I am having one application(Windows service) that was working fine with VS 2003,i am compiling this application with Visual Studio pro 2008 and getting linker error for WNetCancelConnection2.
To supress linker error i have added MPR.LIB,it all work fine but whe its been deployed to server it was giving error
"Dependent Assembly Microsoft.VC80.MFC could not be found and Last Error was
The referenced assembly is not installed on your system ".
I have been trying to adopt certain new MFC classes(version-10.0) into my application (written based on MFC 7.0 originally).
A brief of the context is as below.
I have an application with the main window class, CMainFrame derived from CMDIFrameWnd, and the toolbars created from CToolBar.
These ToolBars are fitted into objects of a class called CMyDialogBar. CMyDialogBar is derived from CDialogBar (which is a child of CControlBar, as you know).
In order to serialize the dock information, in one of the Dlls of my application, CDockState object is used in the code. A pointer to the application's main window is retrieved using AfxGetMainWnd() and dynamic casted to CFrameWnd, and methods like GetDockState() etc. are called against it. Also, CControlBarInfo pointer is used to get each control bar information from CDockState object, and remove a couple of them from the list based on some specific logic before
saving it for persisting.
Now starts the real problem.
I need to incorporate CMFCToolBar instead of CToolBar, and the application's main window is changed to derive from CMDIFrameWndEx instead of CMDIFrameWnd.CMyDialogBar class is now altered to derive from 'CDockablePane' (instead of CDialogBar) as I found in some forums.
I get debug assertion failures, wherever CControlBarInfo is used, and wherever GetDockState() or SetDockState() is called since those methods refer to CControlbar objects/pointers internally.
Sample code from dll, is as shown here:
CFrameWnd* pWnd = DYNAMIC_DOWNCAST( CFrameWnd, OldStyleAfxGetMainWnd());
pWnd->PostMessage( WM_STATUS_UPDATE, 0, 0);
ASSERT( pWnd != NULL);
// Restore from user object//
CProxyUser* pUser = session.GetUserProxy();
if ( pUser != NULL && pUser->GetInstrProfileContext( NAME_LAYOUT_DIALOG_BAR_SERVICE, context) )
if ( context.Exists( NAME_TOOLBAR_STATE) )
if ( context[NAME_TOOLBAR_STATE].Get( data) )
// create a RawByteFile with a pointer to the byte array// reqd as the archive object requires a file not an array//
CRawByteFile file( data.GetSize(), data.GetData());
// create an archive object, set to LOAD//
CArchive ar( &file, CArchive::load);
// extract the toolbar state from the archive//
// Do some pre-processing to ensure that we get no errors//// If our toolbars are hidden they are not restored and so we can get// error conditions in SetDockState. This code just purges// the saved state of any toolbars that don't exist at this time//for ( int i = state.m_arrBarInfo.GetUpperBound(); i >= 0 ; i-- )
CControlBarInfo* pInfo = reinterpret_cast< CControlBarInfo*>( state.m_arrBarInfo[i]);
ASSERT( pInfo != NULL);
pInfo->m_pBar = pWnd->GetControlBar( pInfo->m_nBarID);
if ( pInfo->m_pBar == NULL )
CControlBarInfo* pState = reinterpret_cast< CControlBarInfo*>( state.m_arrBarInfo[i]);
// Finally set toolbar state
In the above sample code, i even tried to replace CFrameWnd pointer to CMDIFrameWndEx pointer, but the method call SetDockState() was giving compilation error, since it is made protected in the new MFC class hierarchy. Since i am standing in a dll, i cannot have my CMainFrame class instantiated here, to call a public method or overridden member function, which in turn can invoke the protected member.
1. Which class i can use for replacing CControlBarInfo in the context of DockablePanes?
2. Why those methods like SetDockState(), GetDockingManager() etc. made protected for CMDIFrameWndEx class in new hierarchy?
3. Is there any other mechanism/classes using which i could achieve the above persistence?
I recently switched to VS2010 and its a big pain. I understand it is more standards compliant etc., but it also seems incredibly fragile. The linker crashes often, the thing that compiled fine yesterday won't compile today, despite me not changing anything. If I leave my compilation running while locking the computer VS2010 crashes. All in all the whole product seems flaky.
Anyway to specifics:
How can I get rid of the MSB8012 warning? Why does MS insist on thinking it knows what I want better than I do? Output a DLL to a non-standard location and it starts freaking out. Also doesn't seem to like relative paths much in these settings.
Is there a way to turn off the use of the path macros?
These are the type of random errors you sometimes experience pre-service packs...
I hope your experience with VS2010 gets better, I've seen a lot of improvements from the usability stand point and the better standard C++ compliance is certainly a great step forward for MS. Good luck!
I guess your project setting in UNICODE. If so, CString will be using wide char (wchar_t) to manipulate strings. The problem is, you are treating them as multibyte characters (char). I suggest you to use TCHAR type instead of hard coding char & wchar_t, as it can be used well in both unicode and multibyte configurations.
what about setting the project as character set : Not set,
in this case, as your suggestion, do I need to replaced all char to TCHAR in the whole project. Thats a lot . . I was trying to avoid much touch in the project implementation
How about having my own class CMyString : public ATL::CString, can i do something in this way to avoid less touch to the project code ? Please note that the current project uses char not wchar_t. Project setting could be change according to our convenience
1. If character set is 'Not Set', i think char will work.
2. CMyString can be alright. Write it to take char only, and internally convert them to wchar_t if the Character Set is 'Unicode' (using APIs like MultiByteToWideChar) and let the CString base class to do the string operations. This will help you to retain all the char types in existing code, provided you are replacing all usage of CString with CMyString. And the implied issue is that you won't be able to manipulate non-english characters with CMyString.
I followed the same way as you suggested. But found a very interesting problem. Following is the explanation:
I should be able to use + operator like below..
strTemp = "aa" + strTemp;
And for this I need to overload the +operator.(Reason:: I get a error which says::
error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const wchar_t '
I am not able to find a appropriate way to call the operator+ of the base class, or any other way to solve the same. [ All I need is, inside operator+ overloading , to convert the char to wchar and then pass it to the base class]
I don't understand why you do not use the CStringT[^] class, which already includes the code for overloading the + operator. What extra functionality does your derived class offer that CStringT does not already include?
I think you need to bite the bullet and convert all your char variables and constants to TCHAR. If you do not, you will continue to have problems like this. If it were easy to solve the multi-byte to Unicode to multi-byte character conversion issues that solution would be part of the CString class.
The changes you need to make are mechanical. You need to put _T() around all your string and character literals. You need to change all your char variables to TCHAR.
I don't know how big your project is, or if you have access to all the source. I suspect you have spent more time trying to avoid the issue than a proper fix would require.
You cannot use casting to convert from a large element type to a smaller one without potential loss of data, you must use some form of conversion. If you stick with the default CString[^] class it will handle either char or wchar_t depending on your project settings. If your project needs to use both Unicode and MBCS then you need to provide conversion functions at the appropriate parts of your application. If it will only ever use one or the other but you need to provide a version that will handle each type then use TCHAR as the type for all your character variables and _T("constant string") macros for all constants. That way you can simply rebuild your project to handle the appropriate encoding.
I need to avoid MFC from my existing project, and convert to ATL. I am using STL for the most of the conversion (defining my own class for MFC type)
CString has been use extensively in the project. So I guess its better to implement my own CString class. So that I dont need to touch all the implementation.
I found out that ATL also has CString
typedef CAtlString CString;
So, if project setting avoids MFC, then CString will be refererd from this ATL CString class. But the problem is I need to touch and convert many code like
"xx" to L"xx"char to wchar_t
Can I have a efficient way, in order to avoid touching much implementation, and character code supportness.
Shall I override this ATL CString class? or better right my own?
considering about the supporting of character type (Unicode/others), could you Please suggest me, or advice me.
The reason you're having those issues is that your original project probably had a setting of "Use Multi-Byte" characters or "ASCII" or something similar and now you seem to be attempting to use unicode. If you change you new project settings to use multi-byte characters or ASCII you won't have that problem but if you must use unicode, then you'll have to face the issue regardless. There may be some macros out there to help you out though, try searching google for them. Macros can be error prone however, so if its your intention to continue with unicode then you'll have to address the character and string definitions.