-7
UINT XyzApp::DlgThread(void* pThis)
{
       XyzDlg* pDlg = new XyzDlg(*(XyzApp*)pThis);
       ((XyzApp*)pThis) -> m_pDlg = pDlg;
       pDlg -> DoModal()
       ((XyzApp*)pThis) -> m_pDlg = NULL;
       ((XyzApp*)pThis) -> m_pthreadDlg = NULL;
}

In the above code:

  1. XyzApp and XyzDlg are both class
  2. Pthis is a pointer of type void*

This is a Visual C++ project developed in Visual Studio 2017. Initially it was developed in Visual Studio 2015, but later i ported it to VS2017 and was working fine.

There was code which was used to send a data from this project to a hardware device. I wanted to use this same code in a different page. So i copy-pasted it to the other page. When i tried executing i am getting the error mentioned below.

I am getting the error at the line when the DoModal() function is being called saying "Unhandled exception at 0x7DAD68FF in Xyz.exe : 0xC0000005: Access Violation executing location 0x7DAD68FF"

If more information is required to debug this problem, please let me know, since this is a big project i have mentioned the problem statement in a concise manner.

  • 2
    [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jesper Juhl Sep 02 '23 at 13:36
  • `XyzDlg(*(XyzApp*)pThis)` Is `XyzApp` passed by reference or value? – drescherjm Sep 02 '23 at 13:38
  • Copy-pasting code you don't understand is not a good idea. And to be honest, I don't understand it either, despite having written C++ code for decades. What is a `pThis`, and how is it different from a normal `this`? – BoP Sep 02 '23 at 14:12
  • 1
    The likeliest explanation is that one of your pointers is NULL. Use a debugger to find out which and why. There's nothing that is obviously wrong in the posted code. – john Sep 02 '23 at 14:33
  • I have added some more info into the question, if you need some more info please let me know. Meanwhile i will see on how to use the debugger and find out which pointers is getting NULL. As per my knowledge the DoModal function is returning NULL value which is getting stored in the pDlg pointer. – Abhishek Jakabal Sep 02 '23 at 15:54
  • Also the code that i pasted is working in the first page but when i copy the code to another page and run it the exception starts popping. – Abhishek Jakabal Sep 02 '23 at 15:56
  • You most likely have to spend some more time with your debugger. I doubt we can help because we don't have a [mcve] and what little code we do have is not enough to see any problem. – drescherjm Sep 02 '23 at 20:29

0 Answers0