LPTSTR初始化 [英] LPTSTR initialization

查看:115
本文介绍了LPTSTR初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何初始化LPTSTR变量?


我正在尝试调用微软功能


LONG QueryStringValue(

LPCTSTR pszValueName,

LPTSTR pszValue,

ULONG * pnChars

)throw(); pszValue应该得到值得我想要,但我需要在我将它传递给QueryStringValue之前初始化它,我如何初始化

它?函数(CRegKey的成员)被描述为

这里: http://msdn.microsoft.com/library/de...y/en-us/vclib/

html / _atl_cregkey.asp



---- ==通过Newsfeed.Com发布 - 无限制 - 未经审查 - 安全Usenet新闻== ----
http://www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组

--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---

how do i initialize an LPTSTR variable?

i''m trying to call a microsoft function

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG* pnChars
) throw( );pszValue is supposed to get the value i want but i need to
initialize it before i pass it to QueryStringValue, how do i initialize
it?the function (member of CRegKey) is described
here:http://msdn.microsoft.com/library/de...y/en-us/vclib/
html/_atl_cregkey.asp


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

推荐答案



" alex" <人************* @ verizon.net>在消息中写道

news:40 ********** @ 127.0.0.1 ...

"alex" <al*************@verizon.net> wrote in message
news:40**********@127.0.0.1...
我如何初始化一个LPTSTR变量?

我试图调用微软功能

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG * pnChars )throw(); pszValue应该得到我想要的值,但我需要在将它传递给QueryStringValue之前初始化它,我如何初始化
它?函数(CRegKey的成员)是描述

这里: http://msdn.microsoft.com/library/de...y/en-us/vclib/ html / _atl_cregkey.asp
how do i initialize an LPTSTR variable?

i''m trying to call a microsoft function

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG* pnChars
) throw( );pszValue is supposed to get the value i want but i need to
initialize it before i pass it to QueryStringValue, how do i initialize
it?the function (member of CRegKey) is described
here:http://msdn.microsoft.com/library/de...y/en-us/vclib/ html/_atl_cregkey.asp




你需要分配一些内存,你应该指定你在nChars中分配多少内存。


Eg假设您决定分配1000个字符


LPTSTR pszValue = new TCHAR [1000];

nChars = 1000;

xxxx。 QueryStringFunction(" yyyyy",pszValue,& nChars);

//用pszValue做一些事情

delete [] pszValue; //释放分配的内存


john



You need to allocate some memory, you should specify how much memory you
allocate in nChars.

E.g. suppose you decide to allocate 1000 characters

LPTSTR pszValue = new TCHAR[1000];
nChars = 1000;
xxxx.QueryStringFunction("yyyyy", pszValue, &nChars);
// do something with pszValue
delete[] pszValue; // free the allocated memory

john


" alex" <人************* @ verizon.net>在消息中写道

news:40 ********** @ 127.0.0.1 ...
"alex" <al*************@verizon.net> wrote in message
news:40**********@127.0.0.1...
我如何初始化一个LPTSTR变量?

我试图调用微软功能

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG * pnChars )throw(); pszValue应该得到我想要的值,但我需要在将它传递给QueryStringValue之前初始化它,我如何初始化
它?函数(CRegKey的成员)是描述
这里: http://msdn.microsoft.com/library/de...y/en-us/vclib/
html / _atl_cregkey.asp
how do i initialize an LPTSTR variable?

i''m trying to call a microsoft function

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG* pnChars
) throw( );pszValue is supposed to get the value i want but i need to
initialize it before i pass it to QueryStringValue, how do i initialize
it?the function (member of CRegKey) is described
here:http://msdn.microsoft.com/library/de...y/en-us/vclib/
html/_atl_cregkey.asp




这个新闻组仅关于标准C ++,所以微软的API是关于主题的
。但是我认为这个问题本身就足够了C ++与这里回答的问题。


你需要意识到的是LPTSTR是什么。这是一个typedef。一个LPTSTR

实际上是一个TCHAR *,这取决于UNICODE是否定义了映射到

char *或wchar_t *。


您需要将您的LPTSTR初始化为足够的大小,以便您希望返回的字符串为
。你可以通过两种方式在堆栈上或堆上执行此操作(

new):

在堆栈中:

TCHAR szValue [ 50];

ULONG nChars = 50;

key.QueryStringValue(" SomeValue",szValue,& nChars);


在堆上:

LPTSTR szValue = new TCHAR [50];

ULONG nChars = 50;

key.QueryStringValue(" SomeValue",szValue,& nChars);

//用szValue做一些事情

delete [] szValue; //不要忘记这个!


-

不可原谅



This newsgroup is about standard C++ only, so Microsoft''s APIs are
off-topic. However I think the question itself is enough C++ related to be
answered here.

What you need to realize is what an LPTSTR is. It''s a typedef. An LPTSTR
actually is a TCHAR*, which depending on whether UNICODE is defined maps to
either char* or wchar_t*.

You need to initialize your LPTSTR to sufficient size for the string you
want to return. You do this in two ways, on the stack or on the heap (with
new):
On the stack:
TCHAR szValue[50];
ULONG nChars = 50;
key.QueryStringValue("SomeValue", szValue, &nChars);

On the heap:
LPTSTR szValue = new TCHAR[50];
ULONG nChars = 50;
key.QueryStringValue("SomeValue", szValue, &nChars);
// do something with szValue
delete[] szValue; // DO NOT FORGET THIS!

--
Unforgiven


alex发表:
alex posted:
我如何初始化一个LPTSTR变量?

我试图调用一个微软功能

LONG QueryStringValue (
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG * pnChars
)throw(); pszValue应该得到我想要的值,但我需要初始化它在我将它传递给QueryStringValue之前,我如何初始化
它?函数(CRegKey的成员)在这里描述: http://msdn.microsoft.com/library/de...brary/en-us/vc
lib / html / _atl_cregkey.asp
how do i initialize an LPTSTR variable?

i''m trying to call a microsoft function

LONG QueryStringValue(
LPCTSTR pszValueName,
LPTSTR pszValue,
ULONG* pnChars
) throw( );pszValue is supposed to get the value i want but i need to
initialize it before i pass it to QueryStringValue, how do i initialize
it?the function (member of CRegKey) is described
here:http://msdn.microsoft.com/library/de...brary/en-us/vc
lib/ html/_atl_cregkey.asp



typedef const char * LPCTSTR;


typedef char * LPTSTR;


typedef unsigned long ULONG;

char value_name [] =" BlahBlah";


char value [] =" BlahBlah" ;;


unsigned long poo = 0;


QueryStringValue(value_name,value,& ; poo);


甚至:


QueryStringValue(Hello,Goodbye,& poo);

这个函数将改变第二个和第三个参数,因为它们不是
声明为const。

为什么Microsoft给出内在类型的新名称?


因为你得到的信息和你得到的头文件是

打算编程语言是非特定的。如果他们使用char *,那么

用一种叫做Blerg的语言写一些东西就不知道发生了什么。

所以他们已经想到了每台电脑都会使用的新名字

编程语言。

-JKop


typedef const char* LPCTSTR;

typedef char* LPTSTR;

typedef unsigned long ULONG;
char value_name[] = "BlahBlah";

char value[] = "BlahBlah";

unsigned long poo = 0;

QueryStringValue(value_name,value,&poo);

Or even:

QueryStringValue("Hello","Goodbye",&poo);
This function will alter the second and third arguments, as they''re not
declared const.
Why does Microsoft give the intrinsic types new names?

Because the information that you''ve got and the header files you''ve got are
intended to be programming language NON-specific. If they used "char*", then
some-one writing in a language called Blerg wouldn''t know what''s going on.
So they''ve thought up of new names to be used with every computer
programming language.
-JKop


这篇关于LPTSTR初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆