在 c++ 中声明 const BYTE *

发布于 2024-09-14 06:52:22 字数 478 浏览 1 评论 0原文

我目前正在尝试拨打 函数调用。这是声明:

const void* WINAPI CertCreateContext(
  __in      DWORD dwContextType,
  __in      DWORD dwEncodingType,
  __in      const BYTE *pbEncoded,
  __in      DWORD cbEncoded,
  __in      DWORD dwFlags,
  __in_opt  PCERT_CREATE_CONTEXT_PARA pCreatePara
);

如您所见,第三个输入参数调用 const BYTE * ,它表示您尝试创建的编码证书。如何在c++中定义这样的变量?

I am currently trying to make a call to this function call. Here's the declaration:

const void* WINAPI CertCreateContext(
  __in      DWORD dwContextType,
  __in      DWORD dwEncodingType,
  __in      const BYTE *pbEncoded,
  __in      DWORD cbEncoded,
  __in      DWORD dwFlags,
  __in_opt  PCERT_CREATE_CONTEXT_PARA pCreatePara
);

As you can see, the third input param calls for a const BYTE * which represents the encoded certificate you are trying to create. How do I define such a variable in c++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

善良天后 2024-09-21 06:52:22

你不需要。函数参数是一个指向const BYTE的指针,这意味着函数不会改变它指向的字节。一个简单的例子:

void f( const BYTE * p ) {
    // stuff
}

BYTE b = 42;
BYTE a[] = { 1, 2, 3 };

f( & b );
f( a );

您当然需要 #include 声明 BYTE 类型的标头。

You don't need to. The function parameter is a pointer to a const BYTE, which means the function will not change the byte it points to. A simple example:

void f( const BYTE * p ) {
    // stuff
}

BYTE b = 42;
BYTE a[] = { 1, 2, 3 };

f( & b );
f( a );

You will of course need to #include the header that declares the type BYTE.

治碍 2024-09-21 06:52:22

您只需要声明一个BYTE*,编译器就会自动将非const转换为const

You only need to declare a BYTE*, the compiler will automatically cast's non-consts to consts.

玻璃人 2024-09-21 06:52:22

根据文档

pbEncoded 是一个指向缓冲区的指针,该缓冲区包含要复制的现有编码上下文内容。

According to the documentation:

pbEncoded is a pointer to a buffer that contains the existing encoded context content to be copied.

伴我心暖 2024-09-21 06:52:22

传入一个指向 BYTE 的常规指针。其中的const表示所指向的对象不会在函数内部被修改。

Pass in a regular pointer to BYTE. The const there indicates that the pointed-to object will not be modified inside the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文