TextOut a BSTR
-
My interface member is a BSTR Sum.
{ // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; }
It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it. -
My interface member is a BSTR Sum.
{ // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; }
It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it.I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S
-
I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S
Thanx. that was a great help to me. I am using Win32 SDK. Is development in Win32SDK has more overhead then that of MFC? I use WIn32SDK because I am able to understand the flow, while I tried MFC at times and it seems to be overwhelming.
-
Thanx. that was a great help to me. I am using Win32 SDK. Is development in Win32SDK has more overhead then that of MFC? I use WIn32SDK because I am able to understand the flow, while I tried MFC at times and it seems to be overwhelming.
Development can take longer using raw SDK. Depends how well you 'grok' the framework. I tend to use WTL rather than MFC, unless I have a particular need for MFC specific features, such as support for OLE compound documents. In many cases, the framework obscures your view of what's happening, until you understand it, and then it accelerates development; class = code you don't have to write. Lots of my test apps though are pure SDK, but short. Steve S
-
I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S
-
Continuing same discussion. What I want to do is to pass a BSTR from a ATL DLL to a Client? Now since Interface method can return only HRESULT. I will store the values in a Global Variable and use it in the client. Is there in Flaw on Design? I need feedback. By the way I didn't see anything like TextOutW in MSDN. Please help
-
Continuing same discussion. What I want to do is to pass a BSTR from a ATL DLL to a Client? Now since Interface method can return only HRESULT. I will store the values in a Global Variable and use it in the client. Is there in Flaw on Design? I need feedback. By the way I didn't see anything like TextOutW in MSDN. Please help
My fellow poster with no name is correct that you can use TextOutW. But unfortunately, if you run your client app on Win9x or WinME, then it won't work, as that doesn't implement TextOutW, which is why I didn't suggest it (you didn't say it was NT/2K/XP/03, so I assumed it could be any. Many API calls that take strings or characters as parameters have two versions, an ANSI version, and a UNICODE (or wide character) version. Although you use TextOut, in reality you're using either TextOutA or TextOutW, depending on whether you're compiling with _UNICODE and UNICODE defined. If you examine some of the Windows header files, you'll see definitions for both A and W functions, and then a macro which defines the base name (without A or W) as one or the other. If you've unintentionally screwed up a parameter list to CWnd::SetWindowText, for example, the compiler will often complain about 'SetWindowTextA' or 'SetWindowTextW', rather than SetWindowText, because it's getting the definition of what the word 'SetWindowText' should be from a windows header. Any time you see a reference to a function that ends with W or A, try looking in MSDN for the name without that trailing letter. MEANWHILE, back to your original question; There is a BIG flaw in your design. In the case of an in-proc ATL DLL, the global would be addressable, but that sure isn't how it's supposed to be done. Although the method can only return an HRESULT, you can pass pointers to things in, and have the method assign values indirectly (equivalent to VB's ByRef, rather than ByVal). An example would be: IDL Definition: HRESULT GetMyName( [out, retval] BSTR* pName ); HRESULT CMyObj::GetMyName( BSTR* pName) { if (pName == NULL) { return E_POINTER; // Bad address passed in... } *pName = SysAllocString(L"Steve Spencer"); return S_OK; } Client code: BSTR t = NULL; // Empty BSTR if (SUCCEEDED(pObj->GetMyName( &t ))) { // woohoo! We got a result... } else { // Handle your error gracefully... } This works because a BSTR is a pointer; you pass in the address of the pointer, and the server (your ATL DLL) fills in the value for the pointer (hence '*pName' instead of 'pName'). You also have to mark the parameter as [out] so that the marshalling code knows how to transfer data. It's marked as [retval] so that VB programmers can use your object and treat that interface method as returning a string. (BSTR means 'BASIC String') Hope this helps S<
-
My interface member is a BSTR Sum.
{ // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; }
It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it.:wtf:I have found the best way!!! CComBSTR some(CString("some")); CString some1= some; CComBSTR and CString are exellent together!!! ================================ My Home is here!