Click here to Skip to main content
15,913,669 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Insert ActiveX wizard trouble Pin
Anonymous11-Feb-04 10:47
Anonymous11-Feb-04 10:47 
GeneralTextOut a BSTR Pin
SiddharthAtw10-Feb-04 19:14
SiddharthAtw10-Feb-04 19:14 
GeneralRe: TextOut a BSTR Pin
Steve S10-Feb-04 23:19
Steve S10-Feb-04 23:19 
GeneralRe: TextOut a BSTR Pin
SiddharthAtw11-Feb-04 1:17
SiddharthAtw11-Feb-04 1:17 
GeneralRe: TextOut a BSTR Pin
Steve S11-Feb-04 6:12
Steve S11-Feb-04 6:12 
GeneralRe: TextOut a BSTR Pin
Anonymous11-Feb-04 10:42
Anonymous11-Feb-04 10:42 
GeneralRe: TextOut a BSTR Pin
SiddharthAtw11-Feb-04 17:39
SiddharthAtw11-Feb-04 17:39 
GeneralRe: TextOut a BSTR Pin
Steve S11-Feb-04 22:32
Steve S11-Feb-04 22:32 
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

Steve S
GeneralRe: TextOut a BSTR Pin
Brigsoft12-Feb-04 8:35
Brigsoft12-Feb-04 8:35 
GeneralGeting Main brower window corridnates Pin
macattack10-Feb-04 10:29
macattack10-Feb-04 10:29 
GeneralCWindow* to CWnd* Pin
Member 4085619-Feb-04 23:53
Member 4085619-Feb-04 23:53 
GeneralRe: CWindow* to CWnd* Pin
_Magnus_10-Feb-04 1:36
_Magnus_10-Feb-04 1:36 
GeneralRe: CWindow* to CWnd* Pin
Jörgen Sigvardsson11-Feb-04 8:50
Jörgen Sigvardsson11-Feb-04 8:50 
GeneralRestricting a BHO Pin
macattack9-Feb-04 12:39
macattack9-Feb-04 12:39 
GeneralRe: Restricting a BHO Pin
Jason De Arte10-Feb-04 7:04
Jason De Arte10-Feb-04 7:04 
GeneralRe: Restricting a BHO Pin
macattack10-Feb-04 7:18
macattack10-Feb-04 7:18 
QuestionHow to add a help file into a wtl dialog? Pin
freehawk8-Feb-04 19:27
freehawk8-Feb-04 19:27 
GeneralError in wizard Pin
SiddharthAtw8-Feb-04 18:16
SiddharthAtw8-Feb-04 18:16 
GeneralRe: Error in wizard Pin
Simon.W9-Feb-04 1:12
Simon.W9-Feb-04 1:12 
QuestionIdentical methods/properties in separate interfaces ? Pin
Alwin756-Feb-04 0:16
Alwin756-Feb-04 0:16 
AnswerRe: Identical methods/properties in separate interfaces ? Pin
_Magnus_6-Feb-04 2:43
_Magnus_6-Feb-04 2:43 
AnswerRe: Identical methods/properties in separate interfaces ? Pin
Jörgen Sigvardsson7-Feb-04 23:01
Jörgen Sigvardsson7-Feb-04 23:01 
QuestionHow can i get properties of com object dynamically Pin
Inam5-Feb-04 19:46
Inam5-Feb-04 19:46 
AnswerRe: How can i get properties of com object dynamically Pin
Jörgen Sigvardsson5-Feb-04 21:37
Jörgen Sigvardsson5-Feb-04 21:37 
GeneralAbout CString Pin
freehawk5-Feb-04 18:48
freehawk5-Feb-04 18:48 

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.