based pointer crashed my app
-
if it is in the same app/process it is OK, but he didnt say that. In the same app I would use a global (memory) object.
Greetings from Germany
but GlobalAlloc() is not portable...
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
Try use GlobalAlloc()/GlobalFree, but check/test it on Vista. Read the MSDN.
Greetings from Germany
What about GlobalAlloc()/GlobalFree changed on Vista? I see nothing in the PSDK. Mark
-
Alex Cutovoi wrote:
Teste __based(vValue) * Single;
So what address is 4 bytes from
vValue
? Unless it is the beginning ofExibeMsg()
, there's no way that the following could work:ttt->ExibeMsg();
What you're doing seems very unreliable and dangerous. What is the receivng window supposed to do with the data it receives?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
The code that I put in my question is the same for both windows. It doesn't change. If the way I choose is unreliable and dangerous, what you suggest for me to solve this?? I need a big help
-
The code that I put in my question is the same for both windows. It doesn't change. If the way I choose is unreliable and dangerous, what you suggest for me to solve this?? I need a big help
Alex Cutovoi wrote:
The code that I put in my question is the same for both windows.
Which is irrelevant. What matters is that
vValue
plus 4 bytes does not referenceExibeMsg()
, but referencesm_cMsg
instead. Again I ask, what is it that you are trying to do?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Alex Cutovoi wrote:
The code that I put in my question is the same for both windows.
Which is irrelevant. What matters is that
vValue
plus 4 bytes does not referenceExibeMsg()
, but referencesm_cMsg
instead. Again I ask, what is it that you are trying to do?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Ok, I need to pass an entire object between 2 windows. In both windows they recieve different handles. I only get to pass structs(which is very easy).
-
Ok, I need to pass an entire object between 2 windows. In both windows they recieve different handles. I only get to pass structs(which is very easy).
Try this:
// the structure to pass around
class MyStruct
{
public:
MyStruct()
{
m_pMsg = new char[128];
lstrcpy(m_pMsg, "Hello World");
}~MyStruct() { delete \[\] m\_pMsg; m\_pMsg = NULL; } char \*m\_pMsg; void Exec( void ) { AfxMessageBox(m\_pMsg); }
};
// on the sending end
MyStruct myStruct;
COPYDATASTRUCT dataToSend;dataToSend.cbData = sizeof(MyStruct);
dataToSend.lpData = &myStruct;
dataToSend.dwData = 0;::SendMessage(GetSafeHwnd(), WM_COPYDATA, (WPARAM) GetSafeHwnd(), (LPARAM)&dataToSend);
// on the receiving end
COPYDATASTRUCT *dataReceived = (COPYDATASTRUCT *)pCopyDataStruct;
MyStruct *pStruct = (MyStruct *) dataReceived->lpData;
pStruct->Exec();
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi for all I'm trying to pass some data between 2 windows. This is the class that I pass between my 2 windows. It's just a single class with a based pointer:
#ifndef TESTE_H #define TESTE_H #include void * vValue; class Teste { public: Teste(); ~Teste(); void SetMsg(char * cMsg); void ExibeMsg(); Teste __based(vValue) * Single; private: char * m_cMsg; char * m_cClassName; }; Teste::Teste() { if(m_cClassName == 0)m_cClassName = "Classe Teste"; } Teste::~Teste(){} void Teste::SetMsg(char * cMsg) { m_cMsg = cMsg; } void Teste::ExibeMsg() { if(m_cMsg != NULL)MessageBox(NULL, m_cMsg, "msg", MB_OK);} #endif TESTE_H
This is the code that sends the data and handles the data:case WM_COPYDATA: { COPYDATASTRUCT * dataReceived = (COPYDATASTRUCT*)lParam; Teste * tempTeste = (Teste*)dataReceived->lpData; Teste * ttt = tempTeste->Single; char cResult[256] = {0}; int nCount = 0; if(ttt != NULL) { MessageBox(NULL, "exibindo msg janela 1", "", MB_OK); ttt->ExibeMsg(); } break; } case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_BUTTON1: { char cLength[20], cSize[5]; if(HIWORD(wParam) == BN_CLICKED) { if(GetDlgItemText(hwnd, IDC_EDIT1, cLength, 20) != 0) { Teste teste1; teste1.SetMsg("aaa"); vValue = (void*)&teste1; COPYDATASTRUCT dataToSend; &
You cannot pass a pointer between processes. All the data has to be self-contained in the block of memory that you refer to in the
COPYDATASTRUCT
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
-
You cannot pass a pointer between processes. All the data has to be self-contained in the block of memory that you refer to in the
COPYDATASTRUCT
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
Exactly, like I said to toxcct, if I do this, I lost the control of the pointer. And I did this before, Michael, can you tell me how can I solve? I've tested with structures, works very fine, but what I want is a object. Hence I'm trying to solve this using based pointers. It's my very first time using based pointers.
-
Exactly, like I said to toxcct, if I do this, I lost the control of the pointer. And I did this before, Michael, can you tell me how can I solve? I've tested with structures, works very fine, but what I want is a object. Hence I'm trying to solve this using based pointers. It's my very first time using based pointers.
You cannot pass a pointer between processes. A based pointer doesn't solve this, because it's just an offset from another pointer.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
-
You cannot pass a pointer between processes. A based pointer doesn't solve this, because it's just an offset from another pointer.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
That means, it's not possible to send an object to another window right? If an object is a pointer, there's not a way to send it. My app actually is passing structs, but what I want to pass is an object.