Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
M

Mark Jones

@Mark Jones
About
Posts
8
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Get number of 1s in a set of binary numbers
    M Mark Jones

    This should do what you want. int GetHighBitCount(int i) { int iResult=0; while (i) { // Mask for least significant bit of 'i' if (i & 0x00000001) iResult++; // Right shift 'i' by one bit i >>= 1; } return iResult; } Mark Jones Software Engineer Hampshire UK

    C / C++ / MFC question

  • Documenting design and code
    M Mark Jones

    I am looking for suggestions regarding a tool (commercial or free) that I can use to better document the Visual C++ project I have been working on for the last two years. I am familiar with UML and have tried UML Studio from Rogue Wave. However, I need to document more than just the class diagrams. I am not looking for any silver bullets - I know the task ahead of me is considerable and will require much effort whichever tool gets used. I'm looking particularly for diagramming capability, with integration with VC6 if poss. I have around 300 classes, around 100000 lines of code, and need to get the knowledge in my head disseminated in a form other programmers can use. The app makes heavy use of multiple threads and producing a model of this behaviour is paramount. Mark Jones Software Engineer Hampshire UK

    IT & Infrastructure c++ design

  • Simple Custom Control Question
    M Mark Jones

    Thanks Tomasz, that's just what I was looking for. Mark Jones Software Engineer Hampshire UK

    C / C++ / MFC question debugging json

  • Simple Custom Control Question
    M Mark Jones

    Thanks for your reply, Michael. In answer to your first question - I am using CNewEdit::OnCreate(LPCREATESTRUCT lpCreateStruct), I was trying to be brief in my post - my mistake. I have now overrided the: virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); function but I still cannot breakpoint in this fn or the WM_CREATE handler. I am using the CNewEdit object in a dialog, whose resource template I have designed in the resource editor. I dragged the standard CEdit control from the resource toolbar onto the dialog. I have looked in the .rc file and have found the resource is identified as a 'EDITTEXT' control - the same as for normal CEdit controls. I have added a CNewEdit member variable to the dialog class using class wizard. I am not calling the Create function in my code. I think the creation of the window for the CNewEdit control occurs somewhere in CDialog::OnInitDialog(). Is there another mechanism brought into play when controls are created inside dialog boxes? Mark Jones Software Engineer Hampshire UK

    C / C++ / MFC question debugging json

  • Simple Custom Control Question
    M Mark Jones

    I am developing my first custom control, CNewEdit derived from CEdit, which will use a non-system font for display. I want to create the font and then call CWnd::SetFont() after the control's window has been created. I don't want to do this outside the CNewEdit class (by adding code to the dialog class that is containing my CNewEdit control). My instinct is to provide a handler in CNewEdit for WM_CREATE. However, although Class Wizard allows me to define this message handler, I can't get execution to breakpoint inside CNewEdit::OnCreate(). The rest of the class is working as I have customised the background and text colours and these are ok. I find it strange that if I add a handler for WM_DESTROY to CNewEdit I can breakpoint successfully in OnDestroy(). So why not OnCreate()? Mark Jones Software Engineer Hampshire UK

    C / C++ / MFC question debugging json

  • First-Chance Exception
    M Mark Jones

    Having looked on MSDN at: http://support.microsoft.com/support/kb/articles/Q105/6/75.asp and http://support.microsoft.com/support/kb/articles/Q250/5/63.ASP I am still no clearer as to how I can disable the first-chance exception notifications in the Output Window of VC6. The articles above talk about the 'Encompass Monitor' service, but this is not running on my NT4 SP6 machine and neither encmonitor.exe or monitor.exe are present on my hard drive. I noticed that neither of these articles specify NT4 in their 'information is this article applies to...' header. I use a third-party ActiveX control that causes first-chance exceptions like no tomorrow and I would dearly like to prevent these from appearing in my output window. Can someone please assist as it's driving me up the wall. Thankyou Mark Jones Software Engineer Hampshire UK

    C / C++ / MFC com

  • Thread & Message pb?
    M Mark Jones

    Hi Ori, I agree with the other poster who mentions that your user message definitions should start at WM_APP, rather than WM_USER. I actually start at WM_APP+0x100 just to be sure of no clash. However, I do not think this is the problem, and I don't think we can put the problem down to differences between win 9x and win nt. The problem you described can be caused if the destruction of the sString object is not *guaranteed* to be determined by the code receiving MY_MSG in the main program. For example, allocating sString on the stack in a worker thread would be bad news. This is because you don't know if sString has been destructed when the main program gets round to pumping its message queue sufficiently to get hold of MY_MSG. On some program runs it might work - others it won't, such is the realm of multi-threaded programming. This can be avoided by using SendMessage, which will block your worker thread until the main program has processed MY_MSG, thus guaranteeing sString points to valid memory for the duration of execution of the MY_MSG handler. I'll give an example of how I'd do this using PostMessage. If I've got the wrong end of the stick - sorry - please post me and I'll try again - this is my first post to CodeProject. void CWorkerThread::SomeFunction() { CString* pstrText=new CString(_T("Test")); int iSomeNumber=0; // Transfer ownership of the memory pointed to by // pstrText to the receiver of MY_MSG, ie he who // processes MY_MSG must do 'delete pstrText'. ::PostMessage(MY_MSG, (WPARAM)pstrText, (LPARAM)iSomeNumber); // This thread does not control the lifetime of the // memory pointer to by pstrText now. So... // we mustn't delete pstrText here // we shouldn't dereference pstrText here // and probably should just deny all knowledge // that *pstrText ever existed... nullify pstrText! pstrText=NULL; } LRESULT CMainProgram::OnMyMsg(WPARAM wParam, LPARAM lParam) { // Document the fact that the memory pointed to by // pstrText is now 'owned' by this function. CString* pstrText=(CString*)wParam; int iSomeNumber=(int)lParam; // do some stuff with pstrText and iSomeNumber // .... // because we own pstrText, we must delete it delete pstrText; pstrText=NULL; // just for safety return 0; } Does this help? Mark

    C / C++ / MFC help tutorial question

  • Read a single serial byte into COMM-Port
    M Mark Jones

    Dieter Are you using overlapped or non-overlapping i/o on your com port? If you are using overlapped i/o I do have some code which may help you out. I use overlapped i/o because I need simultaneous i/o on multiple COM ports. This is not possible when using non-overlapped i/o, as the relevant WinAPI fns block if two threads try to access them simultaneously. I have had immense trouble with serial comms myself. Part of the problem I had was getting code that worked both with winNT and win9x - without using conditional compilation. The code below should work with either. Below is a description of how I deal with serial comms. My code runs in a worker thread which is responsible for comms on one COM port. There are as many worker threads as there are serial devices connected to the PC. The serial devices are typically GSM (cellphone) modems. I have two functions: 1. UINT CSerialPort::ReadAByte( BYTE &bAcquiredByte) 2. UINT CSerialPort::WaitForCharacter(DWORD dwTimeout) (BYTE is defined as unsigned char, DWORD is defined as unsigned long) ReadAByte() passes back through its bAcquiredByte parameter the byte read in. The return values that are possible are: WAIT_OBJECT_0: Byte read in successfully WAIT_TIMEOUT: No Byte read in WAIT_FAILED: An error occurred ReadAByte() calls ::ReadFile() only if there is a byte currently sitting in the incoming byte queue for the COM port. The result of this is that ReadAByte returns immediately with or without a newly acquired byte. Now when ReadAByte returns WAIT_TIMEOUT what it is really saying is there are no bytes currently in the COM port in queue. WaitForCharacter() is called with a parameter passed determining timeout in milliseconds. The return values that are possible are: WAIT_OBJECT_0: One Byte has arrived at the COM port within the specified timeout. WAIT_TIMEOUT: No Byte has arrived at the COM Port within the specified timeout. WAIT_FAILED: An error occurred Decide on a timeout to use with WaitForCharacter, say 10ms. To sum up how you would read in a stream of bytes: 1. Call ReadAbyte - If you get WAIT_OBJECT_0, then a byte has been read in successfully. Call ReadAByte again to get the next byte. If you get WAIT_TIMEOUT back call WaitForCharacter(). 2. If WaitForCharacter() returns WAIT_OBJECT_0, then you're clear to call ReadAByte again (this time there will DEFINITELY be a byte waiting for you). 3. Otherwise, if WaitForCharacter() returns WAIT_TIMEOUT, then no bytes have been received on the

    C / C++ / MFC help c++ com data-structures question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups