|
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;
}
|
|
|
|
|
Hi,
BSTR's are a real nightmare, I think what could work is:
<br />
m_sLPWSTRString = newVal.Copy();<br />
( or something ilke that), just forget about handling BSTR, just use "_bstr_t" or "CComBSTR", but take care with that as well..., personally I preffer _bstr_t since it allows you to convert from char * to BSTR, a good working code couldbe
<br />
_bstr_t m_sLPWSTRString;<br />
m_sLPWSTRString = newVal;
Good luck
Braulio
|
|
|
|
|
Hello
I have one dilaog bar in my CFormView.
I have embbeded some buttons on my dilog bar.
I have to change the views based on the button selection
from the user.
For example if the user presses button1 from the dialog bar..
I want to diaply another formview with different dialog bar,
for button1...
CFormView1+CDialogBar1
for button 2 ..
CFormView2 + CDialogBar2 ..
for button3...
CFormView3+CDialogBar3
etc...
how to do this?
any idea or code snippets please!!!
"They can because they think they can" - Voltaire
|
|
|
|
|
HI THERE
Where can I find a Program, which include source code, or any information for converting TTF to DXF?
Thanks
|
|
|
|
|
There is information on this site (and elsewhere) about the DXF format.
You can use ::GetGlyphOutline to retrieve the line segments of a particular character.
Putting the two bits of information and some hard work, you'll have your answer.
You never know, there might just be an article in it somewhere!
Iain.
|
|
|
|
|
Hi,
does anyone know the proper way to pass data from one independent class to a view within SDI?
thanks...
|
|
|
|
|
Hi,
In my SDI application I have two Formviews separated by a splitter window. I want users to use the MainMenu (File->Save As etc) to display data etc which depends on both the Views.
For the two views do I need to write the same menu handlers in both the view classes, or, there is better place to put the menu handlers? I can't put it in the document class, as I'll show some popup dialog etc, which are not supported by document class.
Please advise
|
|
|
|
|
Binayak wrote:
I can't put it in the document class, as I'll show some popup dialog etc, which are not supported by document class.
You can popup a dialog class from the document with no problem...
John
|
|
|
|
|
I tried to use the following and got error!! which says can't convert CDoc* to CWnd*
CFileDialog fileDlg(FALSE,"xml", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "XML Files(*.xml)|*.xml||", this );
fileDlg.m_ofn.lpstrTitle = "Save As";
|
|
|
|
|
Instead of this use either NULL or AfxGetMainWnd()
John
|
|
|
|
|
We have some runtime errors and DevSudio
trys to find dbgheap.c. It isn't on my
machine, or anybody elses here either.
Where can we get dbgheap.c and the
other runtime debug files?
|
|
|
|
|
It's part of the C run-time library source.
This is not installed by default with Visual C++ 6. If installed, it is in \Program Files\Microsoft Visual Studio\VC98\CRT\SRC. If not installed, just re-run the installer and install the C run-time source as an additional component.
For Visual C++ 7.x, it's in \Program Files\Microsoft Visual Studio .NET\Vc7\crt\src or \Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src, depending which version you have installed. I can't remember if it's installed as part of the default setup or if you have to drill into the install options to select it.
Brad
|
|
|
|
|
Hi, I am trying to get a few parameters in an output file.
i have included fsteam.h, and iostream.h
my code is:
ofstream out("output.txt");
CMyDoc* pDoc = GetDocument();
out<<"12454 ";
out<<pdoc->X_Position<<"\n";
out<<"y: ";
out<<pdoc->Y_Position<<"\n";
out<<"z: ";
out<<pdoc->Z_Position<<"\n";
the code makes the output file, but its always empty,,
any siggestions?
Ehsan Behboudi
|
|
|
|
|
1) When is the file empty? Do you check while your program is running or afterwards?
2) Make sure you have out.close(); after you finish. This is to make sure everything is output on the file.
Hosam Aly Mahmoud
|
|
|
|
|
First, the contents may be output to some file else if you use relative path like that, you better use absolute path to make sure the destination file is exactly which you expected. So type this instead:
ofstream out("C:\\output.txt"); .
Second, you need to exam the stream first to make sure the destination file is ready to be written, so add this line right after you open it:
ASSERT(out != NULL);
Third, always close a opened file as soon as you are done with it, add this line at the end:
out.close();
I have a strong feeling that your problem was caused by the first issue, you probably will find "output.txt" in your "My Document" folder, lol.
|
|
|
|
|
trying to pass a Hyperlink, part of msword9.h
function prototype:
BOOL WriteHyperlinkToExcel(CString sFileName, Hyperlink hyp);
error:
error C2061: syntax error : identifier 'Hyperlink'
i can create and use a Hyperlink inside a function without errors:
BOOL CHyperlinkApp::WriteHyperlinkToExcel(CString sFileName)
{
Hyperlink hyp;
CString strTemp = hyp.GetAddress();
return TRUE;
}
any thoughts?
<signature>
Josef Wainz
Software Developer
|
|
|
|
|
Is msword9.h included in your .cpp file rather than the .h file?
Jason Henderson "I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it."
- Jack Handey
|
|
|
|
|
in my .cpp file.
<signature>
Josef Wainz
Software Developer
|
|
|
|
|
Your function prototype is in the .h file so if you want to declare Hyperlink as a parameter in a prototype, you will have to include msword9.h there instead of in the .cpp file.
The compiler doesn't know where to look for Hyperlink.
Jason Henderson "I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it."
- Jack Handey
|
|
|
|
|
that fixed it. so when passing parameters from special libraries, include the .h file in the function prototype .h file.
thanks,
<signature>
Josef Wainz
Software Developer
|
|
|
|
|
Recently, I downloaded a sample program from the internet which after compiling it, received a "0 error; 0 warning" result. When I ran the program, it produced a screen (something like a menu) with several options from which to choose. As soon as I selected one of the options (it didn't matter which one), the screen disappeared.
Checking Windows Explorer to see the ".exe" file for the program, I noticed there weren't anything. NOTHING!! There were no ".pch", ".ncb", or ".obj" files (etc.). NOTHING!!
Was there something the author of the program turned off to suppressed the creation of those files, and why did it execute nonetheless (producing the menu screen)?
Is there something I can turn back on to get those files created?
Thanks for any pointer.
William
Fortes in fide et opere!
|
|
|
|
|
WREY wrote:
Was there something the author of the program turned off to suppressed the creation of those files...
They were created, but possibly in a different location. Do another compile and then search for the EXE. Or you could inspect the .DSP file to see if another target folder was specified.
|
|
|
|
|
Thanks for replying.
Your suggestion about searching for another location where the files may possibly be at, turned out to be a very good tip, because doing so revealed the place where the ".exe" file (along with the others) were located.
Having found the ".exe" file, I once more clicked on it and true to form it produced the menu screen. This time however, it didn't wait for a selection to be made before disappearing, it did so automatically the very next second after it came up.
It's like the author did not intend for the person to use the application, but only see the menu.
Thanks again for the good tip you gave.
William
Fortes in fide et opere!
|
|
|
|
|
How can I deselect an Item in a Tree Control
How can I deselect an Item in a Tree Control from the program?
|
|
|
|
|