I need some help regarding this bug as I can't figure out what's the cause of my WM_COPYDATA struct data going missing. Every time the computer is restarted, I'll be able to receive the message but with empty data. In order to fix it, I'll end all the related processes manually and restart them manually. Only then it works fine again. Next time PC restarts, same thing happens.
This is the function in a dll that sends the message. Another EXE will be calling this function
So basically, the data that is missing is the one boxed in red. 1002 however can be received on the other end.
Here's the receiving end from V4_APP exe

It will be able to enter this section, but strBatchValues will be empty.
Sorry for I know this may not be adequate information. Please let me know if you need any more details. I'm just trying to garner some insights if anyone has encountered such a situation before. I would appreciate any sort of help. Thanks in advance!
Code Test Below:
[Function in DLL, will be called by another EXE]
int TSECSData::NewBatch(CString strBatchValues)
{
HWND hWnd = ::FindWindow(NULL, V4_APP);
if(hWnd)
{
COPYDATASTRUCT cpd;
char szDataToSend[256];
sprintf_s(szDataToSend, "%S", strBatchValues);
cpd.dwData = 1002;
cpd.cbData = sizeof(szDataToSend);
cpd.lpData = (void*)&szDataToSend;
::SendMessage(hWnd, WM_COPYDATA, NULL,(LPARAM)&cpd);
}
return 1;
}
[Receiving portion in V4_APP]
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
int nMsg = (int)(pCopyDataStruct->dwData);
if(nMsg==1000)
{
CString strRecipe;
strRecipe.Format(_T("%S"), pCopyDataStruct->lpData);
theApp.OnAutoLoadRecipe(strRecipe);
}
else if(nMsg == 1002)
{
CString strBatchValues;
strBatchValues.Format(_T("%S"), pCopyDataStruct->lpData);
CWnd* ptr = CWnd::GetLastActivePopup();
if(ptr == m_StartupPointer) //Confirmation if there are no opened dialogs
{
m_MainPane.NewEndLot(strBatchValues); //Batch only when enabled, else do nothing
}
else
{
BOOL bIsItModeless = m_StartupPointer->IsWindowEnabled();
if(bIsItModeless)
m_MainPane.NewEndLot(strBatchValues); //Batch if any pop up dialog is modeless
}
}
return CFrameWndEx::OnCopyData(pWnd, pCopyDataStruct);
}
