|
This is a new one for me.
I have a buffer, i.e., char buffer[100]. I need to copy the contents of the buffer into a BSTR that is already allocated and already has a value. Basically, I need to change the value of the BSTR before I send it to another method that requires a BSTR. I cannot figure out how to do this? Any advice?
Thanks for any help,
Shanti
|
|
|
|
|
comutils.h includes a wrapper class called _bstr_t. You can do this:
HRESULT MyFunc(/*[in, out]*/BSTR * bstr)
{
_bstr_t b_tWrap(*bstr, false); // FALSE means the _bstr_t takes ownership
b_tWrap = mycharbuffer;
*bstr = b_tWrap.Release();
}
Something like that.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
I was interested in this answer too. But, how do you do it in C? Also, how would you convert a BSTR or Variant to a char buffer?. Kind of hard to find examples on how to do these things in C cuz all examples in MSDN etc. only use C++. I'm modifying an existing C program to use COM/OCX and keep running into these kinds of problems.
|
|
|
|
|
JohnnyG wrote:
Also, how would you convert a BSTR or Variant to a char buffer?.
I don't know. There are a range on conversion functions, but I do not know if they are C or C++.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Hey, I tried looking up your signature....in regards to a quote from Chris Losinger thinking that must have been an interesting thread but on Nov 7th, 2002, huh???? 11/7/2002 hasn't occurred yet. Typo or deliberate? Hee, hee.
|
|
|
|
|
I don't know the country breakdown for different date formats, but in Australia it's dd/mm/yyyy.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
This will work in a *.c file
#include <windows.h>
int foo(BSTR string)
{
char buf[255];
int len = *(long *)(string-2);
memset(buf,0,sizeof(buf));
strcpy(buf,"Hello World");
mbstowcs(string, buf, len);
return 0;
}
|
|
|
|
|
Thanks, Mel. I'll give that a try.
|
|
|
|
|
Hi I'm trying to reposition like so:
void CForm2View::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
m_editbox1.MoveWindow(0,0,cx,cy,TRUE );
}
except that I modified the code at
http://www.codetools.com/docview/centermdiwnd.asp
to make the CFormView fit exactly and immovably in my MDI frame (took away draggability of the view as well).
The above is causing a debug assertion.
The foll shows the messagebox but doesnt like setwindowtext either:
void CForm2View::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
//MessageBox("aaaa");
// m_editbox1.MoveWindow(0,0,cx,cy,TRUE );
m_editbox1.SetWindowText ("moving!!");
MSDN says:
Example
// Resize the list control contained in the view to
// fill the entire view when the view's window is
// resized. CMyView is a CView derived class.
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// Resize list to fill the whole view.
m_List.MoveWindow (0, 0, cx, cy);
}
So I am confused. Please respond!
|
|
|
|
|
I see...
The problem is that OnSize() is call a first time when the view is created.
I tested that with a simple dialog based containing a button...
And it's OK...
bool m_bWait => a member of CMyDialog (which is a CDialog derived class)
CButton m_ctrlButton => a member of CMyDialog
class CMyDialog : public CDialog
{
public:
CMyDialog(CWnd* pParent = NULL) {
...
m_bWait = false; // initialize in the construtor
}
...
}
void CMyDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if(m_bWait)
m_ctrlButton.MoveWindow(0, 0, cx, cy, TRUE);
m_bWait = true;
}
I hope that can help you
Hello World!!!
from Raphaël
|
|
|
|
|
Yuck. Much better to do this:
void CMyDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (::IsWindowVisible(*this))
m_ctrlButton.MoveWindow(0, 0, cx, cy, TRUE);
}
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Of course... It's really better...
Hello World!!!
from Raphaël
|
|
|
|
|
Thank you very much. Your approach works, and I also ran into http://www.codeguru.com/mfc/faq/comments/485.shtml, so the issue is resolved. Much appreciation for your testing!
Thanks,
ns
|
|
|
|
|
I have a CTreeCtrl. There are many many children of the root, and many children of those children and many children of those children and so on. I was wondering if there is a way to find out which position that a selected item is at. I currently get the parent of the parent of the parent and so on until I get a NULL. Is there an easier way?
-Raffi
|
|
|
|
|
What do you mean by "Selected Position".
Normski. - Professional Windows Programmer
|
|
|
|
|
Hi
I try to find informations which can help me to create a simple app (with VC++ 6.0) which invite another user (connected on a network) to reboot his PC...
Can somebody help me?
In advance thank you...
Hello World!!!
from Raphaël
|
|
|
|
|
Something like this:
bool CCyberPC::ShutDown(LPCTSTR szMsg, bool bReboot)
{
if( m_strComputerName.IsEmpty() )
return false;
CString msg;
if (szMsg)
msg = szMsg;
else
msg.LoadString(IDS_SHUTDOWN);
BOOL bResult = InitiateSystemShutdown(
(LPTSTR)(LPCTSTR)GetPCAddress(),
(LPTSTR)(LPCTSTR)msg,
10,
TRUE /*bForceAppsClosed*/,
(int)bReboot
);
return bResult ? true:false;
}
Hope this helps.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Thanks...
That's work for my own PC (locally thus) but when I use it to another IP adress (from my network) that doesn't work : bResult is false...
I think that comes from Privilege, but I'm not sûr.
See : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/Security/authorization_functions.asp
Hello World!!!
from Raphaël
|
|
|
|
|
Yes, you'll need Administrator permissions to reboot another machine.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
For the last week or so, my Visual Studio 6.0 decides to shut itself down in the middle of a debugging session. Both the VS and the program I'm debugging gets killed instantly and I'm looking at my wallpaper all of a sudden. Had this ever happened to anyone ?
Funny thing is the exact same thing happened to a co-worker today.
|
|
|
|
|
Suicidal not suidical
|
|
|
|
|
What OS? Do you have the latest service pack (5) installed?
- Shog9 - Aaah... It's time to relax. You know what that means: a glass of beer, your favorite ergo chair... And of course, The Code Project loaded on your Personal Computer System. So go on, and indulge yourself, put your feet up. Lean back and just enjoy the articles. After all, CP sooths even the savage
|
|
|
|
|
Win XP and SP5
Very weird problem
|
|
|
|
|
I have an aboutBox. It's a simple CDialog we all
know and love.
I can color the background of the aboutBox using
OnCtrColor(). In the resource editor, I notice
faint, light blue lines that surround the aboutBox with about a half-inch indentation. I
saw in a program the other day white background
coloring up to those blue lines, then the
standard grey that surrounds it and a border. How
can you make it fill the background of a CDialog
up to the light blue lines?
Please, any response anyone can give me will be
greatly appreciated. I tried changing various
settings in the dialog resource, but nothing
worked.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
I read the article N-Tier application using Managed C++ and ASP.NET - A Tutorial
By Ranjan Banerji
that can be found at the address: http://www.codeproject.com/dotnet/N_Tier_Web_Service.asp
Everything worked smoothly, and it introduced me very well on the web-services with SQL world.
What I want to know is how I can build a client using C++.
How I manage the data in the DataSet?
The function in the WebService returns a DataSet, how I get the data out of it and fill, let's say, an edit control with those data?
Thx!
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|