🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.ole
4 messages
4 total messages Started by Ananda Subramaniam Wed, 17 Jan 1996 20:43
Problems VC++4.0 & StringFromCLSID function
#10
Author: Ananda Subramaniam
Date: Wed, 17 Jan 1996 20:43
32 lines
1696 bytes
Hi,

I have an OLE sample that I wrote and compiled in VC++ 2.0 without any problems.
However, when I tried to compile in VC++ 4.0, I had trouble with the
StringFromCLSID function. 

I get a message "cannot convert 2nd parameter char ** to unsigned short**"

The Prototype for StringFromCLSID is:
StringFromCLSID(REFCLSID, LPOLESTR *);

I am passing as my second parameter a LPSTR *, which shouldn't be a problem
because grepping through the several include files provided by MS there is a
typedef as follows

typedef LPSTR LPOLESTR;

The compiler seems to think that LPOLESTR is of type unsigned short.
To further confirm this, I changed the type of my string to LPOLESTR and the 
compiler went past StringFromCLSID function but complained on the next line
where I had AfxMessageBox(mystr).  The compiler said "non of the 2 overloads can
covert parameter one from type unsigned short * "

After this, I went and modified the header file that has the prototype for
StringFromCLSID (objbase.h) and modified the prototype from LPOLESTR to LPSTR
and the app compiled and sort of worked.  

I am running out of ideas, plus it does not help being the only C++ programmer
in the office.   Any help will be appreciated.

Ananda
email: ananda@mars.superlink.net
Re: Problems VC++4.0 & StringFromCLSID function
#11
Author: Jeroen Nikkels
Date: Thu, 18 Jan 1996 07:45
37 lines
1868 bytes
In article <4djn2d$mps@earth.superlink.net>, ananda@mars.superlink.net (Ananda Subramaniam) writes:
|> Hi,
|> 
|> I have an OLE sample that I wrote and compiled in VC++ 2.0 without any problems.
|> However, when I tried to compile in VC++ 4.0, I had trouble with the
|> StringFromCLSID function. 
|> 
|> I get a message "cannot convert 2nd parameter char ** to unsigned short**"
|> 
|> The Prototype for StringFromCLSID is:
|> StringFromCLSID(REFCLSID, LPOLESTR *);
|> 
|> I am passing as my second parameter a LPSTR *, which shouldn't be a problem
|> because grepping through the several include files provided by MS there is a
|> typedef as follows
|> 
|> typedef LPSTR LPOLESTR;

In the file wtypes.h there are also typedefs for
   typedef WCHAR OLECHAR
   typedef const OLECHAR *LPOLESTR;

All OLE functions use unicoded string arguments. Probably your VC++ 2.0
settings included the define OLE2ANSI to use ansi strings.

You should use the function MultiByteToWideChar(...) to convert an ansi
string to a unicode string.

This should help you out !

greetings,
-- 
# Jeroen Nikkels                          Baan Development B.V.     #
# Technology Development                  Baron van Nagellstraat 89 #
# Phone: +31 (0)342 428808                P.O. Box 143              #
# Fax  : +31 (0)342 428787                3770 AC Barneveld         #
# Email: jeroenn@baan.nl                  The Netherlands           #
Re: Problems VC++4.0 & StringFromCLSID function
#12
Author: Tom Armstrong
Date: Thu, 18 Jan 1996 16:28
37 lines
1759 bytes
In article <4djn2d$mps@earth.superlink.net>,
   ananda@mars.superlink.net (Ananda Subramaniam) wrote:
>Hi,
>
>I have an OLE sample that I wrote and compiled in VC++ 2.0 without any 
problems.
>However, when I tried to compile in VC++ 4.0, I had trouble with the
>StringFromCLSID function. 
>
>I get a message "cannot convert 2nd parameter char ** to unsigned short**"
>
>....
>The compiler seems to think that LPOLESTR is of type unsigned short.
>To further confirm this, I changed the type of my string to LPOLESTR and the 
>compiler went past StringFromCLSID function but complained on the next line
>where I had AfxMessageBox(mystr).  The compiler said "non of the 2 overloads 
can
>covert parameter one from type unsigned short * "
>
>...

>I am running out of ideas, plus it does not help being the only C++ 
programmer
>in the office.   Any help will be appreciated.

>Ananda
>email: ananda@mars.superlink.net

Ananda,

One major change between VC++ 2.0 and VC++ 4.0 is the support for Unicode. All 
OLE functions require Unicode strings. That's why it wants and "unsigned 
short**". 2.x provided this translation for you, but 4.0 does not. Check out 
Tech Note 59. And if you need source examples, check out my FAQ under "General 
Questions"/"Converting from 2.0 to 4.0" at http://www.sky.net/~toma.

TwA
Re: Problems VC++4.0 & StringFromCLSID function
#13
Author: John D. Prokopek
Date: Sat, 20 Jan 1996 17:54
64 lines
2889 bytes
Ananda Subramaniam wrote:
> 
> Hi,
> 
> I have an OLE sample that I wrote and compiled in VC++ 2.0 without any problems.
> However, when I tried to compile in VC++ 4.0, I had trouble with the
> StringFromCLSID function.
> 
> I get a message "cannot convert 2nd parameter char ** to unsigned short**"
> 
> The Prototype for StringFromCLSID is:
> StringFromCLSID(REFCLSID, LPOLESTR *);
> 
> I am passing as my second parameter a LPSTR *, which shouldn't be a problem
> because grepping through the several include files provided by MS there is a
> typedef as follows
> 
> typedef LPSTR LPOLESTR;
> 
> The compiler seems to think that LPOLESTR is of type unsigned short.
> To further confirm this, I changed the type of my string to LPOLESTR and the
> compiler went past StringFromCLSID function but complained on the next line
> where I had AfxMessageBox(mystr).  The compiler said "non of the 2 overloads can
> covert parameter one from type unsigned short * "
> 
> After this, I went and modified the header file that has the prototype for
> StringFromCLSID (objbase.h) and modified the prototype from LPOLESTR to LPSTR
> and the app compiled and sort of worked.
> 
> I am running out of ideas, plus it does not help being the only C++ programmer
> in the office.   Any help will be appreciated.
> 
> Ananda
> email: ananda@mars.superlink.net

This little problem bugged me too.
There is an easy way to convert- 
If you include afxpriv.h there are conversion macros that will allocate 
memory perform the necessary conversion and return the proper pointer.

here is a little sample from my junk...

#include "afxpriv.h"

void CBaseObjectApp::RegisterServer(void)
{
    OLECHAR     szID[128];
    TCHAR       szCLSID[128];
    TCHAR       szModule[512];
    USES_CONVERSION;			<< this initializes some vars

    StringFromGUID2(CLSID_ChatSrv, (LPOLESTR)szID, 128); << LPOLESTR is 
what is expected
    lstrcpy(szCLSID, TEXT("CLSID\\"));
    lstrcat(szCLSID, OLE2CT(szID)); 	<< OLE2CT performs a conversion
					<< and returns the correct 
					<< pointer
					<< check it out
I still need to compile with MBCS and have had no luck compileing with
_UNICODE defined but that is another headache.
Microsoft - "Do it our way until we tell you otherwise"

later 
johnp
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads