Click here to Skip to main content
15,890,123 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralIs this a homework assignment? Pin
JWood5-Sep-03 3:43
JWood5-Sep-03 3:43 
GeneralHelp!!! Pin
jimsleon3-Sep-03 18:54
jimsleon3-Sep-03 18:54 
GeneralRe: Help!!! Pin
Magnus Westin3-Sep-03 21:20
Magnus Westin3-Sep-03 21:20 
GeneralRe: Help!!! Pin
Dudi Avramov4-Sep-03 0:59
Dudi Avramov4-Sep-03 0:59 
GeneralRe: Help!!! Pin
Dudi Avramov3-Sep-03 22:58
Dudi Avramov3-Sep-03 22:58 
Questiondll and installation? Pin
theCapt3-Sep-03 18:12
susstheCapt3-Sep-03 18:12 
QuestionBSTR question? Pin
theCapt3-Sep-03 18:06
susstheCapt3-Sep-03 18:06 
AnswerRe: BSTR question? Pin
TrickyFishy3-Sep-03 18:48
TrickyFishy3-Sep-03 18:48 
It is because the BSTR that is being passed to you is not owned by you, that is the memory for it was not allocated by you. That's what I mean by you don't own it.

The caller is passing you a BSTR and then freeing it which is why your LPWSTR is now pointing at garbage.

To fix this, you need to allocate some memory that is pointed at by your LPWSTR then copy the contents of the BSTR to your new memory.

Since you appear to be using ATL, why not just use a CComBSTR instead of the LPWSTR? The overhead is minimal and it will take care of the memory allocation and freeing.

Here are both examples:

// don't forget to free this mem in FinalRelease or something
DWORD ccb = ::SysStringByteLen(newVal);
m_sLPWSTRString = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, ccb);
CopyMemory(m_sLPWSTRString, newVal, ccb);

OR

// in you .h file
CComBSTR m_bsServiceName;

// in your .cpp file
STDMETHODIMP CBluetooth::put_ServiceName(BSTR newVal)
{
// CComBSTR takes care of both allocation and
// memory copy and will also free itself on destruction
m_bsServiceName = newVal;

return S_OK;
}
AnswerRe: BSTR question? Pin
Braulio Dez3-Sep-03 23:56
Braulio Dez3-Sep-03 23:56 
QuestionCFormView + CDialogBar ?????? Pin
kumaru_san3-Sep-03 18:00
kumaru_san3-Sep-03 18:00 
GeneralTTFTODXF Pin
wow99993-Sep-03 17:14
wow99993-Sep-03 17:14 
GeneralRe: TTFTODXF Pin
Iain Clarke, Warrior Programmer3-Sep-03 22:41
Iain Clarke, Warrior Programmer3-Sep-03 22:41 
QuestionHow do i pass data to a view from an independent class? Pin
Member 4048133-Sep-03 15:13
Member 4048133-Sep-03 15:13 
QuestionWhere to put the menu handler in multi-view SDI application? Pin
Binayak3-Sep-03 13:48
Binayak3-Sep-03 13:48 
AnswerRe: Where to put the menu handler in multi-view SDI application? Pin
John M. Drescher3-Sep-03 14:15
John M. Drescher3-Sep-03 14:15 
GeneralRe: Where to put the menu handler in multi-view SDI application? Pin
Binayak3-Sep-03 14:18
Binayak3-Sep-03 14:18 
GeneralRe: Where to put the menu handler in multi-view SDI application? Pin
John M. Drescher3-Sep-03 15:53
John M. Drescher3-Sep-03 15:53 
Generalwhere will I find dbgheap.c etc Pin
Member 5314143-Sep-03 13:45
Member 5314143-Sep-03 13:45 
GeneralRe: where will I find dbgheap.c etc Pin
Brad Sokol3-Sep-03 14:42
Brad Sokol3-Sep-03 14:42 
Generaloutput file in VC++ Pin
mr20033-Sep-03 11:05
mr20033-Sep-03 11:05 
GeneralRe: output file in VC++ Pin
Hosam Aly Mahmoud3-Sep-03 11:37
Hosam Aly Mahmoud3-Sep-03 11:37 
GeneralRe: output file in VC++ Pin
Abin3-Sep-03 22:53
Abin3-Sep-03 22:53 
GeneralHyperlink Pin
Turtle Hand3-Sep-03 10:44
Turtle Hand3-Sep-03 10:44 
GeneralRe: Hyperlink Pin
Jason Henderson3-Sep-03 19:04
Jason Henderson3-Sep-03 19:04 
GeneralRe: Hyperlink Pin
Turtle Hand4-Sep-03 2:21
Turtle Hand4-Sep-03 2:21 

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.