Do you mean a string in hexadecimal format? You can do such a conversion with strtol. If you set the last parameter to 0 it does even automatically detect the number base depending on the first characters, e.g. if you have a string like 0xFF it will be converted to the integer value 255. Here is an example code: const char* szNumber = "0x1234"; char* pHelp; int nNumber = strtol(szNumber, &pHelp, 0);
Regards Konrad
Konrad Windszus
Posts
-
converting Hex to int -
virtual staticI have one abstract class and several classes which are all derived from the abstract class. How can I create all of those classes without calling each constructor? The way I found is via the CRuntimeClass::CreateObject method and enter the RUNTIME_CLASS(Classname) in an array. So I can easily add classes by simply adding them to an array. Is there another solution, because I am not allowed to have any parameters within my constructors with this solution? And how can I detect by a keyword which class to create? The keywords are static member variables in the classes. How can I dynamically compare those keywords with a given keyword without creating the classes and then instanciate the appropriate class? Thanks for any help. Konrad
-
Unicode in CCommandLineInfoThank you very much. That would be an explanation, but obviously it is not right. If you have a look at the code of CWinApp
void CWinApp::ParseCommandLine(CCommandLineInfo& rCmdInfo) { for (int i = 1; i < __argc; i++) { LPCTSTR pszParam = __targv[i]; BOOL bFlag = FALSE; BOOL bLast = ((i + 1) == __argc); if (pszParam[0] == '-' || pszParam[0] == '/') { // remove flag specifier bFlag = TRUE; ++pszParam; } rCmdInfo.ParseParam(pszParam, bFlag, bLast); } }
Here you can see that the parameter is wchar_t* for Unicode and char* for multibyte as parameter. So in every condition the TCHAR variant gets called! Do you have any explanation for this. Regards Konrad -
Unicode in CCommandLineInfoHello, I'm quite irritated by the source and the MSDN Library for CCommandLineInfo. For the documentation of ParseParam it says:
The framework calls this function to parse/interpret individual parameters from the command line. The second version is only available in Unicode projects. virtual void ParseParam( const char* pszParam, BOOL bFlag, BOOL bLast ); virtual void ParseParam( const TCHAR* pszParam, BOOL bFlag, BOOL bLast );
But in the header I find the following declaration:// plain char* version on UNICODE for source-code backwards compatibility virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast); #ifdef _UNICODE virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast); #endif
It is the other way round. Using a char* in Unicode projects and TCHAR* in multibyte projects???That doesn't make sense to me because then one declaration would be enough (TCHAR is actually a char in multibyte projects). But after debugging it with Visul C++ 7.1 it seemed that the code of the MFC doesn't belong to the used MFC library, because independent on wether I build Unicode (with _UNICODE and UNICODE defined) or not the ParseParam with TCHAR is always used. Is this correct? I ask because I want to extend CCommandLineInfo for my own parameters and I don't know which declaration of ParseParam I have to derive. I will build my app as Unicode as well as multibyte string executable. Could someone help me in this issue. Thanks in advance Konrad -
String ProblemsBecause "\" is an escape character prefix you have to write "\\" if you mean the "\". You can also escape other characters with the single \, e.g. \n \r \" Regards Konrad
-
Bidirectional CMapThank you very much. I also found that article, after I posted my request. I already programmed my own CMap extension class, because I use MFC in my project (and therefore don't use STL, because I don't want to mix them). I will write an article about my extension class for codeproject when I have some free time. Regards Konrad
-
Bidirectional CMapIsn't there a simple MFC class somewhere out there as extension to CMap, because I don't want to use the huge boost library? Konrad
-
Bidirectional CMapI need a map where I can find the value to a key and also a key to a value. Since I can't find any article on Codeproject regarding this issue, I ask this question here: Is there a simple solution to this? My idea was to simply use two CMaps: CMap<KEY, KEY&, VALUE, VALUE&> and CMap<VALUE, VALUE&, KEY, KEY&>. Is there a simpler approach? Thanks for any help. Konrad
-
restore IXMLDOMElement from pointerI want to write a simple XML editor with the help of MSXML. I'm using the library with smart pointers. I can read out the xml file and can display its structure within a treectrl, but I want to store a pointer to the specific element in the ItemData (DWORD) of the according treectrl item. What do I have to store (Interface*, IXMLDOMElementPtr) and how do I create the IXMLDomElement from that pointer? Do I have to care about releasing/allocating memory? Sorry for that silly question, but I don't have much experience with COM. Thank you very much in advance, Konrad
-
Synchronization with CTypedPtrArrayDo I have to synchronize access to a CTypedPtrArray which is used from two different threads? Or can I just add items in one thread and delete items in the other? How can that by synchronized the easiest way. Thanks in advance for your help Regards Konrad
-
CSliderCtrl mouseclick positionThanks for your answer. Isn't there any other simple way, than subclassing the control. I think I'm not the first one, who wants to achieve that behaviour. Isn't there a class out there I can use? Konrad
-
CSliderCtrl mouseclick positionIf you click on the sliderbar with the mouse, it will move only one pagesize up/down. How can I change this behaviour, that clicking into a slider bar moves it to exactly that position like in WMPs Position-Ctrl? Is there any simple way to achieve that? Thanks for any answer Konrad
-
localization with satellite dll'sHow can I change the language at run-time. I use resource-only dll's for the different languages and set it in the MFC method CWinApp::InitInstance with AfxSetResourceHandle before the MainFrame is loaded. How can I do this, when the MainFrame is already loaded. What do I have to do besides the AfxSetResourceHandle, that even the Menu and all the dialogs are now in the new language? Thanks for any help. Konrad
-
Bug in CSplitterWndI have one CSplitterWnd inside my CFrameWnd with 3 rows and one column. In the first two rows are two different CFormViews and in the last row is a new CSplitterWnd with 1 row and 2 columns, which contain a CFormView each. The creation works with the following code in CFrameWnd::OnCreateClient:
// create first splitter wnd m_wndSplitterMain.CreateStatic( this, 3, 1 ) ) m_wndSplitterMain.CreateView( 0, 0, RUNTIME_CLASS(CFunctionsDlg), size, pContext ); // second (in the middle) is playlist dialog m_wndSplitterMain.CreateView( 1, 0, RUNTIME_CLASS(CPlaylistDlg), size, pContext ); // create second splitter wnd (as third pane in first splitter wnd) m_wndSplitterBrowser.CreateStatic(&m_wndSplitterMain, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitterMain.IdFromRowCol(2, 0)); // third (on the bottom left) is directory dialog m_wndSplitterBrowser.CreateView(0, 0, RUNTIME_CLASS(CDirectoryDlg), size, pContext); // fourth (on the bottom right) is filelist m_wndSplitterBrowser.CreateView(0, 1, RUNTIME_CLASS(CFilelistDlg), size, pContext);
The problem is, that I use the WM_SIZE messages within the 4 CFormViews to resize the controls, but I don't get a WM_SIZE message for the first two CFormViews (within the first CSplitterWnd), with a safe (GetSafeHwnd() != NULL) handle of the dialog controls of that CFormView. Only the last 2 CFormViews (within the second CSplitterWnd) get correct WM_SIZE messages. Even if I call RecalcLayout( true ); from within CFrameWnd only the last two CFormViews get the WM_SIZE messages. Is that bug already confirmed by Microsoft? What is a workaround for that? Thanks for any help! Konrad -
typedef struct <-> structWhat's the difference between
typedef struct _MYSTRUCT { int nValue; DWORD dwValue2; }MYSTRUCT;
andstruct MYSTRUCT { int nValue; DWORD dwValue2; };
With each of them I can instantiate variables of type MYSTRUCT like:MYSTRUCT myStruct;
And I doesn't need the old C style:struct MYSTRUCT myStruct;
So why should I use typedef combined with struct. Are there any advantages or disadvantages. Thanks for any comment. Konrad -
synchronizing simple typesThanks for your answer, but in the MSDN Library I found the following sentence: Simple reads and writes to properly-aligned 32-bit variables are atomic. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/interlocked_variable_access.asp What about other variables like char (8bit)? Isn't it possible, that during the read process another thread writes to the variable with InterlockedExchange. After this the read thread is reading the second part of the variable. It gets corrupted, because it wasn't an atomic read. What about other variables like 8, 16 bit. Are reads always atomic? And do I need volatile for these variables if I write to them only via InterlockedExchange. Thanks for any answer Konrad
-
synchronizing simple typesThank you very much, that helps. But with InterlockExchange I must write a new value to a variable. What if I just want to read variable and ensure that this is atomic? Do the variable have to be declared as volatile. Sorry but the MSDN library is very short concerning this issue. Konrad
-
synchronizing simple typesBut I think i need to declare the static variable with the keyword volatile, or is this not correct? Konrad
-
synchronizing simple typesDo I need to synchronize simple data types (int, DWORD, bool etc.), when I write to the (static) variable in one thread and read it in another. Does windows ensure that it will not switch to another thread during writing of one value? What do I have to remark. Thanks for any answer. Regards Konrad
-
LINK : fatal error LNK1181: --> How to overcome thisYour path to the lib-files seems to be invalid. Just set the correct path in Visual Studio. If you use version 2003 go to Tool->Options->Projects->Vc++ Directories and set the correct path for library files. In Visual Studio 6 it should be very similar. Konrad