Click here to Skip to main content
15,923,374 members
Home / Discussions / COM
   

COM

 
GeneralRe: Overwriting COM Pin
Ramu Pulipati29-Jun-02 4:15
Ramu Pulipati29-Jun-02 4:15 
GeneralRe: Overwriting COM Pin
Sam Hobbs1-Jul-02 13:50
Sam Hobbs1-Jul-02 13:50 
GeneralATL - Class Factory and Interface Implementation Seperation Pin
Marc Bednar27-Jun-02 9:57
Marc Bednar27-Jun-02 9:57 
GeneralFiring an event from an MFC ActiveX control Pin
twomagiclovers27-Jun-02 8:59
twomagiclovers27-Jun-02 8:59 
GeneralRe: Firing an event from an MFC ActiveX control Pin
Ernest Laurentin27-Jun-02 19:29
Ernest Laurentin27-Jun-02 19:29 
GeneralSimple Srting Conversion Pin
Ryan B.27-Jun-02 5:19
Ryan B.27-Jun-02 5:19 
GeneralRe: Simple Srting Conversion Pin
Ernest Laurentin27-Jun-02 19:27
Ernest Laurentin27-Jun-02 19:27 
GeneralRe: Simple Srting Conversion Pin
Stuart Dootson3-Jul-02 14:37
professionalStuart Dootson3-Jul-02 14:37 
If you #include <atlbase.h> & <atlconv.h>, you can use the ATL string conversion macros. These convert strings 'on-the-fly':
const char* s;
BSTR s = ::SysAllocString(A2COLE(s));
LPCTSTR ts;
BSTR s = ::SysAllocString(T2COLE(ts));

They 'do the right' thing wrt conversion to/from Unicode & ASCII & use the stack for temporary string allocation (so are reasonably efficient and deallocate the temporaries automatically).

Alternatively, the CComBSTR or _bstr_t classes seem to work pretty well (I tend to use _bstr_t because it's got char* & wchar_t* extraction operators). The following code should properly allocate a BSTR for use in a C struct
struct {
....
BSTR bs;
....
} thing;
char* s;
thing.bs = CComBSTR(s).Detach();

Just remember to make sure that the BSTR is properly deallocated - using SysFreeString if you do it yourself. For this reason, you'd be better having a CComBSTR in your struct if that's at all practical, as the CComBSTR will deallocate the BSTR in it's destructor.

HTH



Stuart Dootson

'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
GeneralRe: Simple Srting Conversion Pin
Jeremy Pullicino4-Jul-02 4:57
Jeremy Pullicino4-Jul-02 4:57 
GeneralNo Matching DLGINIT Pin
ssirisha27-Jun-02 4:35
ssirisha27-Jun-02 4:35 
GeneralRe: No Matching DLGINIT Pin
Prem Kumar28-Jun-02 4:39
Prem Kumar28-Jun-02 4:39 
GeneralRe: No Matching DLGINIT Pin
ssirisha28-Jun-02 6:29
ssirisha28-Jun-02 6:29 
GeneralSAFEARRAY in Variant Pin
Hans Ruck26-Jun-02 5:18
Hans Ruck26-Jun-02 5:18 
GeneralRe: SAFEARRAY in Variant Pin
Ramu Pulipati26-Jun-02 6:24
Ramu Pulipati26-Jun-02 6:24 
GeneralDCOM port restriction Pin
MrGlover24-Jun-02 13:46
MrGlover24-Jun-02 13:46 
GeneralCOM Exe that "stays" Pin
[Shadow]24-Jun-02 2:28
[Shadow]24-Jun-02 2:28 
GeneralRe: COM Exe that "stays" Pin
Ernest Laurentin24-Jun-02 4:29
Ernest Laurentin24-Jun-02 4:29 
GeneralRe: COM Exe that "stays" Pin
Jason Henderson24-Jun-02 9:16
Jason Henderson24-Jun-02 9:16 
GeneralRef to ActiveX control using C Pin
JohnnyG23-Jun-02 14:17
JohnnyG23-Jun-02 14:17 
GeneralRe: Ref to ActiveX control using C Pin
soptest24-Jun-02 8:30
soptest24-Jun-02 8:30 
GeneralRe: Ref to ActiveX control using C Pin
JohnnyG24-Jun-02 8:59
JohnnyG24-Jun-02 8:59 
GeneralRe: Ref to ActiveX control using C Pin
soptest24-Jun-02 9:21
soptest24-Jun-02 9:21 
GeneralRe: Ref to ActiveX control using C Pin
JohnnyG30-Jun-02 14:31
JohnnyG30-Jun-02 14:31 
GeneralRe: Ref to ActiveX control using C Pin
Amit Dey1-Jul-02 6:44
Amit Dey1-Jul-02 6:44 
QuestionActiveX is "unsafe" huh? Pin
Philip Patrick22-Jun-02 6:08
professionalPhilip Patrick22-Jun-02 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.