简体   繁体   中英

Reading a 32 bit integer from BYTE array. VC++

I have created a BYTE array containing a image pixel data. Image is grayscale and each pixel intensity is a 32bit integer. 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). So my question is how can I read a 32 bit (or also 16 bit) integer from a BYTE array. (working in VC++/MFC).

Thank you.

Use memcpy to get the data from your array of BYTE to an array of int32_t (or 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.

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 .

Ben Voigt

With all due respect, I totally disagree with the statement that DLLMain is not mandatory. The link you provided has misleading information.

Every executable module (exe or DLL) HAS TO HAVE AN ENTRY POINT . Otherwise system would not be able to start any program.

Therefore defining and implementing an entry point is a MUST.

UNK

If you create Win32 or MFC extension dll, wizard inserts entry point in both projects. MFC uses DllMain and Win32 uses _tmain that is defined as wmain for Unicode or main for ANSI. Both are only a placeholders for names and the can be changed (but why bother).

You must have created MFC regular DLL . This type of dll also has an entry point but it is not exposed in any source file created by the wizard. It is called __DllMainCRTStartup and resides in crtdll.c.

For MFC regular DLL, use app's InitInstance to initialize your dll.

By the way: any MFC application also has WinMain that is not exposed in any code generated by the wizard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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