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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. based pointer crashed my app

based pointer crashed my app

Scheduled Pinned Locked Moved C / C++ / MFC
17 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K KarstenK

    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

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #8

    but GlobalAlloc() is not portable...


    Don't know where to start ?
    Refer the Forums Guidelines and ask a friend

    [VisualCalc 3.0][Flags Beginner's Guide]

    1 Reply Last reply
    0
    • K KarstenK

      Try use GlobalAlloc()/GlobalFree, but check/test it on Vista. Read the MSDN.

      Greetings from Germany

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #9

      What about GlobalAlloc()/GlobalFree changed on Vista? I see nothing in the PSDK. Mark

      1 Reply Last reply
      0
      • D David Crow

        Alex Cutovoi wrote:

        Teste __based(vValue) * Single;

        So what address is 4 bytes from vValue? Unless it is the beginning of ExibeMsg(), 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

        A Offline
        A Offline
        Alex Cutovoi
        wrote on last edited by
        #10

        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

        D 1 Reply Last reply
        0
        • A Alex Cutovoi

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #11

          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 reference ExibeMsg(), but references m_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

          A 1 Reply Last reply
          0
          • D David Crow

            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 reference ExibeMsg(), but references m_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

            A Offline
            A Offline
            Alex Cutovoi
            wrote on last edited by
            #12

            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).

            D 1 Reply Last reply
            0
            • A Alex Cutovoi

              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).

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #13

              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

              1 Reply Last reply
              0
              • A Alex Cutovoi

                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;     &

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #14

                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?

                A 1 Reply Last reply
                0
                • M Michael Dunn

                  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?

                  A Offline
                  A Offline
                  Alex Cutovoi
                  wrote on last edited by
                  #15

                  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.

                  M 1 Reply Last reply
                  0
                  • A Alex Cutovoi

                    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.

                    M Offline
                    M Offline
                    Michael Dunn
                    wrote on last edited by
                    #16

                    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?

                    A 1 Reply Last reply
                    0
                    • M Michael Dunn

                      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?

                      A Offline
                      A Offline
                      Alex Cutovoi
                      wrote on last edited by
                      #17

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

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