Click here to Skip to main content
11,477,625 members (76,610 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MFC Python CString BSTR
how to pass two dimensional CString array from MFC to python
Posted 30-Sep-11 1:57am
Edited 30-Sep-11 6:19am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

CString is a c++ class that is rather specific to the MFC framework (and to ATL, for the nitpicks). Therefore, you cannot send a CString outside of MFC (not even to vanilla C++). Well, technically you can send it, but the recipient will not be able to make any sense out of it.

However, CString does have an AllocSysString()[^] member function that will allocate an automation compatible BSTR type string. The API copies the contents of your CString object into this BSTR and returns it.
Albert Holguin at 30-Sep-11 11:07am
Yep, I wouldn't send a CString to an app written in another language, I'd personally go for BSTR or just char* (maybe even std::string)... +5
Espen Harlinn at 30-Sep-11 13:31pm
Good point :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Since you want to pass information from C++ to python you may want to take a look at Boost.Python[^], a C++ library which enables seamless interoperability between C++ and the Python programming language.

Best regards
Espen Harlinn
Albert Holguin at 30-Sep-11 23:42pm
Excellent resource! I didn't even know about this... but I don't use Python... that's my excuse... Boost library has expanded so much over time! +5
Espen Harlinn at 1-Oct-11 4:14am
Thank you, Albert!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 30 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100