How to: Load Unmanaged Resources into a Byte Array
来源:互联网 发布:linux网卡设置命令 编辑:程序博客网 时间:2024/05/17 09:12
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
This topic discusses several ways to load unmanaged resources into a System.Byte array.
If you know the size of your unmanaged resource, you can preallocate a CLR array and then load the resource into the array using a pointer to the array block of the CLR array.
// load_unmanaged_resources_into_Byte_array.cpp// compile with: /clrusing namespace System;void unmanaged_func( unsigned char * p ) { for ( int i = 0; i < 10; i++ ) p[ i ] = i;}public ref class A {public: void func() { array<Byte> ^b = gcnew array<Byte>(10); pin_ptr<Byte> p = &b[ 0 ]; Byte * np = p; unmanaged_func( np ); // pass pointer to the block of CLR array. for ( int i = 0; i < 10; i++ ) Console::Write( b[ i ] ); Console::WriteLine(); }};int main() { A^ g = gcnew A; g->func();}
0123456789
This sample shows how to copy data from an unmanaged memory block to a managed array.
// load_unmanaged_resources_into_Byte_array_2.cpp// compile with: /clrusing namespace System;using namespace System::Runtime::InteropServices;#include <string.h>int main() { char buf[] = "Native String"; int len = strlen(buf); array<Byte> ^byteArray = gcnew array<Byte>(len + 2); // convert any native pointer to IntPtr by doing C-Style cast Marshal::Copy( (IntPtr)buf, byteArray, 0, len );}
- How to: Load Unmanaged Resources into a Byte Array
- How to group anagrams in a string into an array
- How to display a byte array as hex values
- Reading a File into a Byte Array
- How to convert Java String into byte[]?
- convert an int into a byte array
- How To Load CLOB Data from a File into a CLOB column using PL/SQL
- How to get byte array from imageview
- How to sort an array of hashes into hashes with multiple values for a key?
- How to copy values of an array into another array
- Ruby, how to shuffle one array into another
- How can I refactor converting this array into a Hash
- How to turn a negative outlook into a positive one
- How to convert a list of tensors into a tensor
- JNDI Resources HOW-TO
- Convert a byte array to a Hex string
- convert a byte array to a hexadecimal string
- How to load large files safely into InnoDB with LOAD DATA INFILE
- 如何成为一个编程高手
- poj2553--Tarjan
- .NET 中 操作excel 系列--copy功能.
- 用highcharts动态获取值,以及x轴值可以改变
- C/C++折半查找函数bsearch
- How to: Load Unmanaged Resources into a Byte Array
- GPGGA数据解析
- js保持div悬浮,不随页面向下滚动而被覆盖
- linux 系统博客
- 【DP】 hdu3237 Help Bubu
- Psiphon 3
- 数据库的部分成操作
- 锁定屏幕输入框
- signatures段使DWR能确定集合中存放的数据类型