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. Getting the data from a CString into an LPVOID data type

Getting the data from a CString into an LPVOID data type

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
20 Posts 5 Posters 1 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 kyledunn

    If I pass a quoted string variable to the LPVOID argument of a method it accepts it but if I pass a CString to the LPVOID augument I get a compiler error, cannot convert from 'CString' to 'LPVOID'. Can anyone help me with getting the data from a CString into an LPVOID data type? Kyle

    M Offline
    M Offline
    mystro_AKA_kokie
    wrote on last edited by
    #2

    Convert first to LPCTSTR then maybe LPSTR then to LPVOID.

    1 Reply Last reply
    0
    • K kyledunn

      If I pass a quoted string variable to the LPVOID argument of a method it accepts it but if I pass a CString to the LPVOID augument I get a compiler error, cannot convert from 'CString' to 'LPVOID'. Can anyone help me with getting the data from a CString into an LPVOID data type? Kyle

      K Offline
      K Offline
      kyledunn
      wrote on last edited by
      #3

      Tom Archer shared this answer with me so I wanted to share it with others. Thanks Tom! It's easy. Just call the CString::GetBuffer function. Here's an example where I have a function that takes an LPVOID and another function that calls it twice (once passing a hard coded literal and then with a CString). Note that I'm using VC7. You might need to call GetBuffer(0) in VC6. void CallTest() { Test("abc"); CString str = "def"; Test(str.GetBuffer()); // This is what you need to do in your case. } void Test(LPVOID lp) { AfxMessageBox((const char*)lp); } That should set you up. Cheers, Tom It did! Thanks again Tom.

      T N 2 Replies Last reply
      0
      • K kyledunn

        If I pass a quoted string variable to the LPVOID argument of a method it accepts it but if I pass a CString to the LPVOID augument I get a compiler error, cannot convert from 'CString' to 'LPVOID'. Can anyone help me with getting the data from a CString into an LPVOID data type? Kyle

        M Offline
        M Offline
        mystro_AKA_kokie
        wrote on last edited by
        #4

        Convert first to LPCTSTR then maybe LPSTR then to LPVOID. These are all pointers, CString isn't so you need to convert to a pointer first. The internal data structure of a cstring object is an LPCTSTR pointer; you acess it directly by calling GetBuffer(int nmax),but you also have to call ReleaseBuffer() after .

        1 Reply Last reply
        0
        • K kyledunn

          Tom Archer shared this answer with me so I wanted to share it with others. Thanks Tom! It's easy. Just call the CString::GetBuffer function. Here's an example where I have a function that takes an LPVOID and another function that calls it twice (once passing a hard coded literal and then with a CString). Note that I'm using VC7. You might need to call GetBuffer(0) in VC6. void CallTest() { Test("abc"); CString str = "def"; Test(str.GetBuffer()); // This is what you need to do in your case. } void Test(LPVOID lp) { AfxMessageBox((const char*)lp); } That should set you up. Cheers, Tom It did! Thanks again Tom.

          T Offline
          T Offline
          Tom Archer
          wrote on last edited by
          #5

          You're welcome, mate. Like I say in the Acknowledgements section of my C# book, being able to share code and help each other on sites like this is one very big reason that programming remains fun after all these years. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

          N 1 Reply Last reply
          0
          • K kyledunn

            Tom Archer shared this answer with me so I wanted to share it with others. Thanks Tom! It's easy. Just call the CString::GetBuffer function. Here's an example where I have a function that takes an LPVOID and another function that calls it twice (once passing a hard coded literal and then with a CString). Note that I'm using VC7. You might need to call GetBuffer(0) in VC6. void CallTest() { Test("abc"); CString str = "def"; Test(str.GetBuffer()); // This is what you need to do in your case. } void Test(LPVOID lp) { AfxMessageBox((const char*)lp); } That should set you up. Cheers, Tom It did! Thanks again Tom.

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #6

            kyledunn wrote: Tom Archer shared this answer with me so When and where? Nish


            Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

            T K 2 Replies Last reply
            0
            • T Tom Archer

              You're welcome, mate. Like I say in the Acknowledgements section of my C# book, being able to share code and help each other on sites like this is one very big reason that programming remains fun after all these years. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #7

              Hey Tom He said you helped him, but I cant see where :-( It puzzles me no end! Nish


              Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

              T 1 Reply Last reply
              0
              • N Nish Nishant

                kyledunn wrote: Tom Archer shared this answer with me so When and where? Nish


                Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                T Offline
                T Offline
                Tom Archer
                wrote on last edited by
                #8

                Answered in your other query for same :) Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                N 1 Reply Last reply
                0
                • N Nish Nishant

                  Hey Tom He said you helped him, but I cant see where :-( It puzzles me no end! Nish


                  Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                  T Offline
                  T Offline
                  Tom Archer
                  wrote on last edited by
                  #9

                  On another thread he had asked about how to use the registry and I sent him a simple class (CRegistry) I had written for my MFC book (Visual C++.NET Bible). He then asked how to call one of the member functions (WriteString) that takes an LPVOID since the value he wants to pass is in a CString. He must have posted the question here at the same time he emailed me. When I responded, he then updated this thread. Can you tell that I've been writing books for too long? :) I can't say good morning to someone in less than 50 words any more! Damn editors and their request for more detail!! :laugh: Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                  J N 2 Replies Last reply
                  0
                  • N Nish Nishant

                    kyledunn wrote: Tom Archer shared this answer with me so When and where? Nish


                    Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                    K Offline
                    K Offline
                    kyledunn
                    wrote on last edited by
                    #10

                    I emailed Tom directly. He responded shortly before I posted his help here. Kyle

                    1 Reply Last reply
                    0
                    • T Tom Archer

                      On another thread he had asked about how to use the registry and I sent him a simple class (CRegistry) I had written for my MFC book (Visual C++.NET Bible). He then asked how to call one of the member functions (WriteString) that takes an LPVOID since the value he wants to pass is in a CString. He must have posted the question here at the same time he emailed me. When I responded, he then updated this thread. Can you tell that I've been writing books for too long? :) I can't say good morning to someone in less than 50 words any more! Damn editors and their request for more detail!! :laugh: Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                      J Offline
                      J Offline
                      Joao Vaz
                      wrote on last edited by
                      #11

                      Tom Archer wrote: Visual C++.NET Bible So, Tom , in this book, you are writing specifically about MFC 7 ??? Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                      T 1 Reply Last reply
                      0
                      • J Joao Vaz

                        Tom Archer wrote: Visual C++.NET Bible So, Tom , in this book, you are writing specifically about MFC 7 ??? Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                        T Offline
                        T Offline
                        Tom Archer
                        wrote on last edited by
                        #12

                        Yes, the VC++.NET book is 95% MFC. I have about 5 chapters at the end on ME, but that's not the focus of the book. Those chapters are more like "if you're interested in this here's some stuff to get you started". Personally, I don't think many people are going to to use ME so I wanted to keep the book focus on MFC. I really hate that publishers are not making this clear in their book titles. I wish the ME books would state in the title (Managed Extensions). As it is now, the readers have no idea just by looking at the title. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                        J 1 Reply Last reply
                        0
                        • T Tom Archer

                          On another thread he had asked about how to use the registry and I sent him a simple class (CRegistry) I had written for my MFC book (Visual C++.NET Bible). He then asked how to call one of the member functions (WriteString) that takes an LPVOID since the value he wants to pass is in a CString. He must have posted the question here at the same time he emailed me. When I responded, he then updated this thread. Can you tell that I've been writing books for too long? :) I can't say good morning to someone in less than 50 words any more! Damn editors and their request for more detail!! :laugh: Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                          N Offline
                          N Offline
                          Nish Nishant
                          wrote on last edited by
                          #13

                          Thanks Tom. Now my confusion has gone :-) Nish


                          Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                          T 1 Reply Last reply
                          0
                          • T Tom Archer

                            Yes, the VC++.NET book is 95% MFC. I have about 5 chapters at the end on ME, but that's not the focus of the book. Those chapters are more like "if you're interested in this here's some stuff to get you started". Personally, I don't think many people are going to to use ME so I wanted to keep the book focus on MFC. I really hate that publishers are not making this clear in their book titles. I wish the ME books would state in the title (Managed Extensions). As it is now, the readers have no idea just by looking at the title. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                            J Offline
                            J Offline
                            Joao Vaz
                            wrote on last edited by
                            #14

                            To be totally honest with you ,IMHO I think that you should need badly the money(the pool isn't in a great shape), personally I don't like the publisher of your forthcoming book , and I hate their Bible Series . Apart from that what will be intended level of audience of the book? Beginner/Intermediate? Now concerning your Inside C#, 2nd, I don't have any doubt that it rocks, although, for money constraints, I will only buy your book on the next 3 months (very optimistic way, by the end of this month) :( , my company insists in delaying my bonus payment (2 salaries) that I and my fellow colleagues have right :( Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                            T 1 Reply Last reply
                            0
                            • T Tom Archer

                              Answered in your other query for same :) Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                              N Offline
                              N Offline
                              Nish Nishant
                              wrote on last edited by
                              #15

                              Tom Archer wrote: Answered in your other query for same Thanks. I saw it. In the confuision I forgot my original reason. You told him to use GetBuffer, but I think you didnt tell him about RelkeaseBuffer :-) Nish


                              Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                              T 1 Reply Last reply
                              0
                              • N Nish Nishant

                                Thanks Tom. Now my confusion has gone :-) Nish


                                Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                                T Offline
                                T Offline
                                Tom Archer
                                wrote on last edited by
                                #16

                                Er....remember when I recommended that you not leave yourself so open :) Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                1 Reply Last reply
                                0
                                • N Nish Nishant

                                  Tom Archer wrote: Answered in your other query for same Thanks. I saw it. In the confuision I forgot my original reason. You told him to use GetBuffer, but I think you didnt tell him about RelkeaseBuffer :-) Nish


                                  Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                                  T Offline
                                  T Offline
                                  Tom Archer
                                  wrote on last edited by
                                  #17

                                  Call ReleaseBuffer is not necessary in this context. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                  1 Reply Last reply
                                  0
                                  • J Joao Vaz

                                    To be totally honest with you ,IMHO I think that you should need badly the money(the pool isn't in a great shape), personally I don't like the publisher of your forthcoming book , and I hate their Bible Series . Apart from that what will be intended level of audience of the book? Beginner/Intermediate? Now concerning your Inside C#, 2nd, I don't have any doubt that it rocks, although, for money constraints, I will only buy your book on the next 3 months (very optimistic way, by the end of this month) :( , my company insists in delaying my bonus payment (2 salaries) that I and my fellow colleagues have right :( Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                                    T Offline
                                    T Offline
                                    Tom Archer
                                    wrote on last edited by
                                    #18

                                    Joao Vaz wrote: To be totally honest with you ,IMHO I think that you should need badly the money(the pool isn't in a great shape), personally I don't like the publisher of your forthcoming book , and I hate their Bible Series That's cool. However, I think if you look at my MFC book, you'll definitely like it. It's really a labour of love at this point. You see, this was the first book I was ever a part of. The book was never strong overall and so I always wanted to redo it by myself. I've almost completely rewritten it and it is much stronger now. There are a couple of chapters still are still held over from the other author, but 95% of this 1300 page book is solid. Joao Vaz wrote: Apart from that what will be intended level of audience of the book? Beginner/Intermediate? The book can be used by beginners as I do have some beginner level chapters to start the text. However, you can easily skip over those to get to the meaty stuff. For example, there's some really cool stuff on controls, dialogs, COM/ATL (9 chapters), database access, DLLs, COM+, etc. I hope I don't sound immodest here, but my book answers about 50% of the questions I've seen on this board and I would definitely compare it to any other MFC book (including Prosise's) in terms of completeness. (By the way, note that I know Jeff personally and mean that with a great deal of respect for his work.) Joao Vaz wrote: I will only buy your book on the next 3 months No problem. I'll need sales then too :) Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                    J 1 Reply Last reply
                                    0
                                    • T Tom Archer

                                      Joao Vaz wrote: To be totally honest with you ,IMHO I think that you should need badly the money(the pool isn't in a great shape), personally I don't like the publisher of your forthcoming book , and I hate their Bible Series That's cool. However, I think if you look at my MFC book, you'll definitely like it. It's really a labour of love at this point. You see, this was the first book I was ever a part of. The book was never strong overall and so I always wanted to redo it by myself. I've almost completely rewritten it and it is much stronger now. There are a couple of chapters still are still held over from the other author, but 95% of this 1300 page book is solid. Joao Vaz wrote: Apart from that what will be intended level of audience of the book? Beginner/Intermediate? The book can be used by beginners as I do have some beginner level chapters to start the text. However, you can easily skip over those to get to the meaty stuff. For example, there's some really cool stuff on controls, dialogs, COM/ATL (9 chapters), database access, DLLs, COM+, etc. I hope I don't sound immodest here, but my book answers about 50% of the questions I've seen on this board and I would definitely compare it to any other MFC book (including Prosise's) in terms of completeness. (By the way, note that I know Jeff personally and mean that with a great deal of respect for his work.) Joao Vaz wrote: I will only buy your book on the next 3 months No problem. I'll need sales then too :) Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                      J Offline
                                      J Offline
                                      Joao Vaz
                                      wrote on last edited by
                                      #19

                                      Tom Archer wrote: It's really a labour of love at this point It isn't very difficult for you, you are a complet programmer freak ;P Tom Archer wrote: but 95% of this 1300 page book is solid. :omg: , a trully effort without a doubt and synonym of endless coding and writing nights ... Tom Archer wrote: but my book answers about 50% of the questions I've seen on this board It's better that it succeds , with 1300 pags ! Serioulsly ,if it answers 50% then is a certainly a good book . Tom Archer wrote: I would definitely compare it to any other MFC book (including Prosise's) in terms of completeness Now that's enough !!!! (conspiracy theory) You certainly want your name immortalized as great programming author , first with Inside C# , then with VC++ .Net Bible, then , who knows MC++ ? Shame on you , you bad boy ! You are respected more than enough by your peers, MFC and C# programmers , and you want more !!!!! I caught you, you want to say I'm the king of the world !!! I'll defend the CPians with all my ... scratching ... but I'm corruptible ... if you offer me your 2nd of Inside C# with a signed autograph, then I'll forget and let you do what your evil mind planned . Tom Archer wrote: No problem. I'll need sales then too Every penny is welcome :laugh: Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                                      T 1 Reply Last reply
                                      0
                                      • J Joao Vaz

                                        Tom Archer wrote: It's really a labour of love at this point It isn't very difficult for you, you are a complet programmer freak ;P Tom Archer wrote: but 95% of this 1300 page book is solid. :omg: , a trully effort without a doubt and synonym of endless coding and writing nights ... Tom Archer wrote: but my book answers about 50% of the questions I've seen on this board It's better that it succeds , with 1300 pags ! Serioulsly ,if it answers 50% then is a certainly a good book . Tom Archer wrote: I would definitely compare it to any other MFC book (including Prosise's) in terms of completeness Now that's enough !!!! (conspiracy theory) You certainly want your name immortalized as great programming author , first with Inside C# , then with VC++ .Net Bible, then , who knows MC++ ? Shame on you , you bad boy ! You are respected more than enough by your peers, MFC and C# programmers , and you want more !!!!! I caught you, you want to say I'm the king of the world !!! I'll defend the CPians with all my ... scratching ... but I'm corruptible ... if you offer me your 2nd of Inside C# with a signed autograph, then I'll forget and let you do what your evil mind planned . Tom Archer wrote: No problem. I'll need sales then too Every penny is welcome :laugh: Cheers, Joao Vaz Frustrated TCL programmer,good c++ programmer wannabe

                                        T Offline
                                        T Offline
                                        Tom Archer
                                        wrote on last edited by
                                        #20

                                        Joao Vaz wrote: It isn't very difficult for you, you are a complet programmer freak Very true :) It's so cool for our jobs to also be our hobbies. Joao Vaz wrote: a trully effort without a doubt and synonym of endless coding and writing nights You got the endless night bit, right. I am so glad to be done. It's been fun, but it's time to move on to another project. Joao Vaz wrote: Now that's enough !!!! (conspiracy theory) You certainly want your name immortalized as great programming author , first with Inside C# , then with VC++ .Net Bible, then , who knows MC++ ? ...you want to say I'm the king of the world !!! I guy's gotta have a plan :) Joao Vaz wrote: I'll defend the CPians with all my ... scratching ... but I'm corruptible ... if you offer me your 2nd of Inside C# with a signed autograph, then I'll forget and let you do what your evil mind planned :laugh: Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                        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