Re: LPCSTR from String

From: Bijoy (Bijoy_at_discussions.microsoft.com)
Date: 02/15/05


Date: Tue, 15 Feb 2005 01:13:03 -0800

I thinnk this has more importance as a managed/unmanaged issue. I don't know
much about LPCSTR, but belive this can hold pointer to both ANSI and UNICODE
string. Up from NT5 windows uses unicode, can some one explane on these
context

"William DePalo [MVP VC++]" wrote:

> "Joe Thompson" <JoeThompson@discussions.microsoft.com> wrote in message
> news:D16ADA9B-8920-468D-8109-FD37ABF7ABF2@microsoft.com...
> > I am using VS 2003 writing a managed C++ windows app.
> > I am calling PlaySound. The first parameter is a LPCSTR. I have a String
> > *str representing a filename. I like using the String class because the
> > file
> > name needs to be built on the fly.
> > How do I get from String * I have to the LPCSTR it wants?
>
> I'm not sure if your question has to do with ANSI/UNICODE or
> managed/unmanaged issues.
>
> To set the stage:
>
> PlaySound is actually a macro that equates to PlaySoundA in ANSI builds and
> PlaySoundW in UNICODE builds.
>
> An LPCSTR is a pointer to an ANSI string.
>
> ..Net strings are composed of UNICODE characters.
>
> That said, this works by pinning the string (prevent it from being moved by
> the GC), getting a pointer to the first character of the string, and passing
> off the pointer to a native function:
>
> #include <vcclr.h>
>
> System::String *str = new System::String("C:\\windows\\media\\windows xp
> startup.wav");
> wchar_t __pin *p = PtrToStringChars(str);
>
> PlaySoundW(p, 0, SND_FILENAME | SND_SYNC);
>
> Regards,
> Will
>
>
>
>



Relevant Pages

  • Re: Error 52 Bad file name or number on file read
    ... Sorry Nick but if you're ending up with a mixture of ANSI and Unicode data ... Private Type FILETIME ... Public Function StripNulls(sText As String) As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Did Borland doing well in Q4? Listen to the Earning CC
    ... AS an ANSI application you will need to change all "String" ... declarations to "ANSIString" (and Char to ANSIChar and PChar to ... Only THEN can you start thinking about how Unicode is best ... Even the specifically "ANSI" FS routines do not use ...
    (borland.public.delphi.non-technical)
  • Re: using structs like BROWSEINFO and OPENFILENAME (string members
    ... your discussion of unicode ... vs ansi reminded me to recheck my typelib and found a couple of errors. ... > is declared as string, the other is declared as long. ...
    (microsoft.public.vb.winapi)
  • Re: api call for tchar*
    ... > String passes an ANSI version while a ByRef passes a Unicode version. ... The row of characters is preceded by a Long ...
    (microsoft.public.vb.winapi)
  • Re: length checking...
    ... ANSI string. ... Win9x is dead, so all apps are becoming NT-only, which means - no reasons ... Unicode is much simpler then ANSI, and I would recommend Unicode for beginners ...
    (microsoft.public.development.device.drivers)

Quantcast