简体   繁体   English

从BYTE数组中读取32位整数。 VC ++

[英]Reading a 32 bit integer from BYTE array. VC++

I have created a BYTE array containing a image pixel data. 我创建了一个包含图像像素数据的BYTE数组。 Image is grayscale and each pixel intensity is a 32bit integer. 图像是灰度级,每个像素强度是32位整数。 Now I want to read the each pixel intensity( 32 bit int) and then do some operations on each pixel intensity and store back the modified pixel intensity (again in 32bit int). 现在我想读取每个像素强度(32位int),然后对每个像素强度进行一些操作并存储修改后的像素强度(再次以32位int)。 So my question is how can I read a 32 bit (or also 16 bit) integer from a BYTE array. 所以我的问题是如何从BYTE数组中读取32位(或16位)整数。 (working in VC++/MFC). (在VC ++ / MFC中工作)。

Thank you. 谢谢。

Use memcpy to get the data from your array of BYTE to an array of int32_t (or uint32_t ). 使用memcpyBYTE数组中的数据转换为int32_t (或uint32_t )数组。

If you don't need portability, your architecture probably allows casting the address of the first BYTE to a int32_t* and using it in-place. 如果您不需要可移植性,那么您的体系结构可能允许将第一个BYTE的地址转换为int32_t*并在原地使用它。

If all your data always comes from a file, and nothing needs to work on the individual bytes, you could just read it directly into an array of int32_t . 如果你的所有数据总是来自一个文件,并且没有什么需要处理单个字节,你可以直接将它读入int32_t数组。

Ben Voigt 本沃格特

With all due respect, I totally disagree with the statement that DLLMain is not mandatory. 尽管如此,我完全不同意DLLMain不是强制性的说法。 The link you provided has misleading information. 您提供的链接具有误导性信息。

Every executable module (exe or DLL) HAS TO HAVE AN ENTRY POINT . 每个可执行模块(exe或DLL)都有入口点 Otherwise system would not be able to start any program. 否则系统将无法启动任何程序。

Therefore defining and implementing an entry point is a MUST. 因此,定义和实现入口点是必须的。

UNK UNK

If you create Win32 or MFC extension dll, wizard inserts entry point in both projects. 如果您创建Win32或MFC扩展DLL,向导将在两个项目中插入入口点。 MFC uses DllMain and Win32 uses _tmain that is defined as wmain for Unicode or main for ANSI. MFC使用DllMain和Win32使用_tmain,其定义为Unicode的wmain或ANSI的main。 Both are only a placeholders for names and the can be changed (but why bother). 两者都只是名称的占位符,可以更改(但为什么要这么麻烦)。

You must have created MFC regular DLL . 您必须已创建MFC常规DLL This type of dll also has an entry point but it is not exposed in any source file created by the wizard. 这种类型的dll也有一个入口点,但它不会在向导创建的任何源文件中公开。 It is called __DllMainCRTStartup and resides in crtdll.c. 它被称为__DllMainCRTStartup并驻留在crtdll.c中。

For MFC regular DLL, use app's InitInstance to initialize your dll. 对于MFC常规DLL,使用应用程序的InitInstance来初始化您的DLL。

By the way: any MFC application also has WinMain that is not exposed in any code generated by the wizard. 顺便说一句:任何MFC应用程序也有WinMain,它不会在向导生成的任何代码中公开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM