Re: LPCSTR from String
From: Bijoy (Bijoy_at_discussions.microsoft.com)
Date: 02/15/05
- Next message: Steve McLellan: "Re: unboxing : Please tell me the difference"
- Previous message: Antti Keskinen: "Re: need a way"
- In reply to: William DePalo [MVP VC++]: "Re: LPCSTR from String"
- Next in thread: Jochen Kalmbach: "Re: LPCSTR from String"
- Reply: Jochen Kalmbach: "Re: LPCSTR from String"
- Messages sorted by: [ date ] [ thread ]
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
>
>
>
>
- Next message: Steve McLellan: "Re: unboxing : Please tell me the difference"
- Previous message: Antti Keskinen: "Re: need a way"
- In reply to: William DePalo [MVP VC++]: "Re: LPCSTR from String"
- Next in thread: Jochen Kalmbach: "Re: LPCSTR from String"
- Reply: Jochen Kalmbach: "Re: LPCSTR from String"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|