BYTE数组大小 [英] BYTE array size

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

问题描述

我有一个BYTE数组 -

BYTE const * pbBinary


我想知道该字节数组中有多少字节


但如果我这样做 - sizeof(* pbBinary); - 然后我得到1

但如果我这样做 - sizeof(pbBinary); - 然后我得到4


我相信阵列有几百个字节


我怎么能这样做?


======================


BYTE const * pbBinary =& bytes [0 ];

int size = sizeof(pbBinary);

解决方案

" Chunekit Pong" < wo ******** @ yahoo.com在留言新闻中写道:f5 ****************************** ** @ 4ax.com ...


>我有一个BYTE数组 -

BYTE const * pbBinary



你没有BYTE数组,你有一个指向BYTE的指针。

(什么是BYTE?)



我想知道该字节数组中有多少字节


但是如果我这样做 - sizeof(* pbBinary); - 然后我得到1

但如果我这样做 - sizeof(pbBinary); - 然后我得到4


我相信阵列有几百个字节


我怎么能这样做?



没有其他信息你不能。


11月20日上午8:27 * am, Chunekit Pong< worlman ... @ yahoo.comwrote:


我有一个BYTE数组* -

BYTE const * pbBinary


我想知道该字节数组中有多少字节


但如果我这样做 - * sizeof(* pbBinary); * - 然后我得到1

但如果我这样做 - sizeof(pbBinary); - 然后我得到4


我相信阵列有几百个字节



pbBinary只是一个指针..它不存储关于
的信息
它指向的字节/元素数量

如果你关心数组的大小,请使用std :: vector< 。

m。


On Thu,2008年11月20日08:46:12 +0100,Fred Zwarts < F. ****** @ KVI.nl>

写道:


>" Chunekit Pong" < wo ******** @ yahoo.com在留言新闻中写道:f5 ****************************** ** @ 4ax.com ...


>>我有一个BYTE数组 -
BYTE const * pbBinary

你没有BYTE阵列,你有指向BYTE的指针。
(什么是BYTE?)


> ;>
我想知道该字节数组中有多少字节

但如果我这样做 - sizeof(* pbBinary); - 然后我得到1
但如果我这样做 - sizeof(pbBinary); - 然后我得到了4

我相信阵列有几百个字节

我怎么能这样做?


没有其他信息你不能。



整个代码是这样的 - 目的是转换二进制文件

到Base64字符串

=================

typedef unsigned char BYTE ;

std :: ifstream file1(" c:/test2.png; quot;);


//从test2.png读入BYTE数组

std :: vector< BYTEbytes(

(std :: istreambuf_iterator< char>(file1))

,(std :: istreambuf_iterator< char> ())

);

if(bytes.empty())

; //没有读取字节


BYTE const * pbBinary =& bytes [0];

int size = sizeof(pbBinary);


unsigned long ulEncLen = 0;

char * pEncOut = NULL;


BOOL fRet = :: CryptBinaryToString(pbBinary,尺寸,

CRYPT_STRING_BASE64,pEncOut,& ulEncLen);

====================
BOOL WINAPI CryptBinaryToString(

__in const BYTE * pbBinary,

__在DWORD dwFlags,
__out_opt LPTSTR pszString,

__inout DWORD * pcchString

);


I have a BYTE array -
BYTE const* pbBinary

I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?

======================

BYTE const* pbBinary = &bytes[0];
int size = sizeof( pbBinary);

解决方案

"Chunekit Pong" <wo********@yahoo.comwrote in message news:f5********************************@4ax.com...

>I have a BYTE array -
BYTE const* pbBinary

You don''t have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)


I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?

Without other information you can''t.


On Nov 20, 8:27*am, Chunekit Pong <worlman...@yahoo.comwrote:

I have a BYTE array *-
BYTE const* pbBinary

I would like to know how many bytes in that byte array

but if I do - *sizeof(* pbBinary); *- then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

pbBinary is just a pointer.. it does not store the information about
number of bytes/elements it points to
if you care about the size of an "array", use std::vector<instead.
m.


On Thu, 20 Nov 2008 08:46:12 +0100, "Fred Zwarts" <F.******@KVI.nl>
wrote:

>"Chunekit Pong" <wo********@yahoo.comwrote in message news:f5********************************@4ax.com...

>>I have a BYTE array -
BYTE const* pbBinary


You don''t have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)

>>
I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?


Without other information you can''t.

The whole code is like this - the purpose is to convert binary file
into a Base64 string
=================
typedef unsigned char BYTE;
std::ifstream file1("c:/test2.png");

// read from test2.png into BYTE array
std::vector<BYTEbytes(
(std::istreambuf_iterator<char>(file1))
, (std::istreambuf_iterator<char>())
);
if(bytes.empty())
; // no bytes have been read

BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary);

unsigned long ulEncLen = 0;
char *pEncOut = NULL;

BOOL fRet = ::CryptBinaryToString( pbBinary, size,
CRYPT_STRING_BASE64, pEncOut, &ulEncLen );
====================
BOOL WINAPI CryptBinaryToString(
__in const BYTE *pbBinary,
__in DWORD cbBinary,
__in DWORD dwFlags,
__out_opt LPTSTR pszString,
__inout DWORD *pcchString
);


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

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