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. CStringArray problem

CStringArray problem

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialannouncement
5 Posts 4 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.
  • N Offline
    N Offline
    Nguyen Minh Luan
    wrote on last edited by
    #1

    Hi all, I have a trouble with CStringArray class, it is so difficult to me that I'd like to get help from you. My project has a DLL and a Exe file. In the DLL, threre is a function that used to get a list of strings, I use CStringArray to get the list strings. For example : __declspec( dllexport ) void GetCStringArr(CStringArray* pCStringArr) { CString cstrText; for (int i=0; i< 100;i++) { cstrText.Format("%d",i); pCStringArr->SetAtGrow(i,cstrText); } } In the application project, I call GetCStringArr function to get the list string, after calling GetCStringArr function, I have the needed list string and can access all strings in the list(CStringArray),everthing is OK but when I release the CStringArray object, my project has a exception : // m_ArrText is a CStringArray object, it is a member variant of //CTestCstringArrDlg class void CTestCstringArrDlg::OnGetButton() { GetCStringArr(&m_ArrText); for (int i=0;i<10;i++) { MessageBox(m_ArrText.GetAt(i)); } CTestCstringArrDlg.RemoveAll(); // This line code has exception } If I declare, use and release CStringArray variant in only application or only in Dll, everything is OK. I don't known why when I declare CStringArray in App but add it's item string in Dll, I can get all Item string in CStringArray but when I release CStringArray I alway have problem. Please help me to solve the problem!:(

    R J G 3 Replies Last reply
    0
    • N Nguyen Minh Luan

      Hi all, I have a trouble with CStringArray class, it is so difficult to me that I'd like to get help from you. My project has a DLL and a Exe file. In the DLL, threre is a function that used to get a list of strings, I use CStringArray to get the list strings. For example : __declspec( dllexport ) void GetCStringArr(CStringArray* pCStringArr) { CString cstrText; for (int i=0; i< 100;i++) { cstrText.Format("%d",i); pCStringArr->SetAtGrow(i,cstrText); } } In the application project, I call GetCStringArr function to get the list string, after calling GetCStringArr function, I have the needed list string and can access all strings in the list(CStringArray),everthing is OK but when I release the CStringArray object, my project has a exception : // m_ArrText is a CStringArray object, it is a member variant of //CTestCstringArrDlg class void CTestCstringArrDlg::OnGetButton() { GetCStringArr(&m_ArrText); for (int i=0;i<10;i++) { MessageBox(m_ArrText.GetAt(i)); } CTestCstringArrDlg.RemoveAll(); // This line code has exception } If I declare, use and release CStringArray variant in only application or only in Dll, everything is OK. I don't known why when I declare CStringArray in App but add it's item string in Dll, I can get all Item string in CStringArray but when I release CStringArray I alway have problem. Please help me to solve the problem!:(

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Objects allocated within the DLL should only be released by the DLL. Expose a new method in your DLL that frees up a CStringArray and call that on m_ArrText. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      N 1 Reply Last reply
      0
      • N Nguyen Minh Luan

        Hi all, I have a trouble with CStringArray class, it is so difficult to me that I'd like to get help from you. My project has a DLL and a Exe file. In the DLL, threre is a function that used to get a list of strings, I use CStringArray to get the list strings. For example : __declspec( dllexport ) void GetCStringArr(CStringArray* pCStringArr) { CString cstrText; for (int i=0; i< 100;i++) { cstrText.Format("%d",i); pCStringArr->SetAtGrow(i,cstrText); } } In the application project, I call GetCStringArr function to get the list string, after calling GetCStringArr function, I have the needed list string and can access all strings in the list(CStringArray),everthing is OK but when I release the CStringArray object, my project has a exception : // m_ArrText is a CStringArray object, it is a member variant of //CTestCstringArrDlg class void CTestCstringArrDlg::OnGetButton() { GetCStringArr(&m_ArrText); for (int i=0;i<10;i++) { MessageBox(m_ArrText.GetAt(i)); } CTestCstringArrDlg.RemoveAll(); // This line code has exception } If I declare, use and release CStringArray variant in only application or only in Dll, everything is OK. I don't known why when I declare CStringArray in App but add it's item string in Dll, I can get all Item string in CStringArray but when I release CStringArray I alway have problem. Please help me to solve the problem!:(

        J Offline
        J Offline
        Jose Lamas Rios
        wrote on last edited by
        #3

        It might be because of the EXE and DLL being built with different options or defines... Does sizeof(CString) give the same result in both the EXE and DLL? -- jlr http://jlamas.blogspot.com/[^]

        1 Reply Last reply
        0
        • R Ravi Bhavnani

          Objects allocated within the DLL should only be released by the DLL. Expose a new method in your DLL that frees up a CStringArray and call that on m_ArrText. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          N Offline
          N Offline
          Nguyen Minh Luan
          wrote on last edited by
          #4

          Thanks for your help, I have tried to do as your comment, it is useful for me and is my need. Thank you very much.:)

          1 Reply Last reply
          0
          • N Nguyen Minh Luan

            Hi all, I have a trouble with CStringArray class, it is so difficult to me that I'd like to get help from you. My project has a DLL and a Exe file. In the DLL, threre is a function that used to get a list of strings, I use CStringArray to get the list strings. For example : __declspec( dllexport ) void GetCStringArr(CStringArray* pCStringArr) { CString cstrText; for (int i=0; i< 100;i++) { cstrText.Format("%d",i); pCStringArr->SetAtGrow(i,cstrText); } } In the application project, I call GetCStringArr function to get the list string, after calling GetCStringArr function, I have the needed list string and can access all strings in the list(CStringArray),everthing is OK but when I release the CStringArray object, my project has a exception : // m_ArrText is a CStringArray object, it is a member variant of //CTestCstringArrDlg class void CTestCstringArrDlg::OnGetButton() { GetCStringArr(&m_ArrText); for (int i=0;i<10;i++) { MessageBox(m_ArrText.GetAt(i)); } CTestCstringArrDlg.RemoveAll(); // This line code has exception } If I declare, use and release CStringArray variant in only application or only in Dll, everything is OK. I don't known why when I declare CStringArray in App but add it's item string in Dll, I can get all Item string in CStringArray but when I release CStringArray I alway have problem. Please help me to solve the problem!:(

            G Offline
            G Offline
            GKarRacer
            wrote on last edited by
            #5

            Make sure the DLL is an MFC extension DLL and that the App uses MFC as a shared DLL. This way you will be able to allocate/release memory and objects wherever you want.

            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