Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. 16 layers of ifs, Who dare challenge this?

16 layers of ifs, Who dare challenge this?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
29 Posts 20 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mav northwind

    Let me guess - there's a coding rule to use only one return statement per method?

    Regards, mav -- Black holes are the places where God divided by 0...

    J Offline
    J Offline
    jayart
    wrote on last edited by
    #7

    I somehow do not appreciate the "single return" coding rule.

    J 1 Reply Last reply
    0
    • J jayart

      I somehow do not appreciate the "single return" coding rule.

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #8

      I generally follow the single return style but if it is this complex I would have broken the function into smaller parts.

      John

      P 1 Reply Last reply
      0
      • J John M Drescher

        I generally follow the single return style but if it is this complex I would have broken the function into smaller parts.

        John

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #9

        Yes, exactly.

        1 Reply Last reply
        0
        • M mav northwind

          Let me guess - there's a coding rule to use only one return statement per method?

          Regards, mav -- Black holes are the places where God divided by 0...

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #10

          Even so, it's easy enough to do something along the lines of:

          success = Operation()

          if (success == TRUE)
          {
          ...
          }

          if (success == TRUE)
          {
          ...
          }

          etc or

          do {
          success = Operation();
          if (!success) break;

          success = Operation2();
          if (!success) break;

          ...
          } while(false)

          cheers, Chris Maunder

          CodeProject.com : C++ MVP

          L P G C 4 Replies Last reply
          0
          • C Chris Maunder

            Even so, it's easy enough to do something along the lines of:

            success = Operation()

            if (success == TRUE)
            {
            ...
            }

            if (success == TRUE)
            {
            ...
            }

            etc or

            do {
            success = Operation();
            if (!success) break;

            success = Operation2();
            if (!success) break;

            ...
            } while(false)

            cheers, Chris Maunder

            CodeProject.com : C++ MVP

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #11

            Hi, the former is what I do, the latter is a bit ugly, it basically is a never looping loop construct, maybe it belongs in the horror section :~

            Luc Pattyn [Forum Guidelines] [My Articles]


            Good riddance W


            P C 2 Replies Last reply
            0
            • L Luc Pattyn

              Hi, the former is what I do, the latter is a bit ugly, it basically is a never looping loop construct, maybe it belongs in the horror section :~

              Luc Pattyn [Forum Guidelines] [My Articles]


              Good riddance W


              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #12

              Luc Pattyn wrote:

              belongs in the horror section

              Yes, as mentioned the last time it was brought up.

              1 Reply Last reply
              0
              • C Chris Maunder

                Even so, it's easy enough to do something along the lines of:

                success = Operation()

                if (success == TRUE)
                {
                ...
                }

                if (success == TRUE)
                {
                ...
                }

                etc or

                do {
                success = Operation();
                if (!success) break;

                success = Operation2();
                if (!success) break;

                ...
                } while(false)

                cheers, Chris Maunder

                CodeProject.com : C++ MVP

                P Offline
                P Offline
                Phil J Pearson
                wrote on last edited by
                #13

                Sorry Chris, but that second option is just a <hushed_tones>goto</hushed_tones> that avoids using the letters 'g' or 't'. I know you can do better than that!

                Phil


                The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                C S 2 Replies Last reply
                0
                • P Phil J Pearson

                  Sorry Chris, but that second option is just a <hushed_tones>goto</hushed_tones> that avoids using the letters 'g' or 't'. I know you can do better than that!

                  Phil


                  The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                  C Offline
                  C Offline
                  Chris Maunder
                  wrote on last edited by
                  #14

                  :D I said is was pretty or would not cause gagging.

                  cheers, Chris Maunder

                  CodeProject.com : C++ MVP

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, the former is what I do, the latter is a bit ugly, it basically is a never looping loop construct, maybe it belongs in the horror section :~

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Good riddance W


                    C Offline
                    C Offline
                    Chris Maunder
                    wrote on last edited by
                    #15

                    I agree. The first time I saw the latter in use I had a double take and went 'hang on...' in a very suspicious tone. No, not recommended, but arguably better than 16 levels of bleah.

                    cheers, Chris Maunder

                    CodeProject.com : C++ MVP

                    1 Reply Last reply
                    0
                    • P Phil J Pearson

                      Sorry Chris, but that second option is just a <hushed_tones>goto</hushed_tones> that avoids using the letters 'g' or 't'. I know you can do better than that!

                      Phil


                      The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                      S Offline
                      S Offline
                      supercat9
                      wrote on last edited by
                      #16

                      Sorry Chris, but that second option is just a goto that avoids using the letters 'g' or 't'. The reason GOTO has gotten a bad rap is that it has historically been used without any concept of structured control-flow. Programs are generally easiest to understand if they can be subdivided into nested blocks, such that there are few jumps across block boundaries, and all inter-block jumps are of a few specific forms (e.g. jumping to the start or end of an enclosing block). Consider:

                      if (condition) goto TRUE_CASE;
                      FALSE_CASE:
                      do_false_stuff();
                      goto END_IF;
                      TRUE_FASE:
                      do_true_stuff();
                      END_IF:

                      Not quite as nice as using the C block constructs, but not particularly nasty. On the other hand, prior to the invention of structured programming, such code would often have been written as:

                      if (condition) goto TRUE_CASE;
                      do_false_stuff;
                      END_IF:

                      .. somewhere else in the code ..
                      TRUE_CASE:
                      do_true_stuff();
                      goto END_IF;

                      The code for the true case would often be placed rather arbitrarily. In assembly code written for some machines, it might be placed before the start of the routine which used it, so as to allow an efficient short-displacement branch. Trying to follow code whose physical arrangement bears no relation to its logical flow is, of course, difficult. The problem, though, isn't the use of GOTO per se but rather the use of control flow that doesn't follow any logical structure. (nb: I do sometimes write assembly code which is more like the latter than the former, particularly in cases where the 'if' case occurs far less frequently than the 'else' case, and the performance impact of adding an extra branch to the 'else' case would be significant and unacceptable. I don't like such code, but sometimes it is necessary).

                      1 Reply Last reply
                      0
                      • K kingsimba0511

                        I hope you have a 22 inch above screen.

                        bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon)
                        {
                        LPCTSTR lpszModPictureFilePath = lpszPictureFilePath;

                        IImagingFactory\*    pImgFactory = NULL;
                        IImage\*             pImage = NULL;
                        
                        
                        bool                fIsClsFounded    = false;
                        GUID                guidImageEncoderCls;
                        HRESULT             hr = S\_OK;
                        
                        hr = CoCreateInstance(CLSID\_ImagingFactory, NULL, CLSCTX\_INPROC\_SERVER, IID\_IImagingFactory, (void   \*\*)&pImgFactory);
                        
                        if (SUCCEEDED(hr))
                        {
                        	IStream\*        pFileStream = CreateStreamByFileName(lpszPictureFilePath);
                        	IImageDecoder\*   pImageDecoder = 0; 
                        
                        	hr = pImgFactory->CreateImageDecoder(pFileStream, DecoderInitFlagNone, &pImageDecoder);
                        	if (SUCCEEDED(hr))
                        	{
                        		ImageInfo imageInfo;
                        
                        		hr = pImageDecoder->GetImageInfo(&imageInfo);
                        		if (SUCCEEDED(hr))
                        		{
                        			UINT nEncodersCount = 0;
                        			ImageCodecInfo\* pEncoders = NULL;
                        
                        			hr = pImgFactory->GetInstalledEncoders(&nEncodersCount, &pEncoders);
                        			if (SUCCEEDED(hr))
                        			{
                        				for (UINT i = 0; i < nEncodersCount; i++)
                        				{
                        					if (pEncoders\[i\].FormatID == imageInfo.RawDataFormat)
                        					{
                        						guidImageEncoderCls = pEncoders\[i\].Clsid;
                        						fIsClsFounded = true;
                        						break;
                        					}//if
                        				}//for
                        			}//if
                        
                        
                        			// encoder founded now goes to properties
                        			if (fIsClsFounded)
                        			{
                        				PropertyItem pi;
                        
                        				// add latitude
                        				{
                        					// add longitude
                        					pi.id = PropertyTagSoftwareUsed;
                        					pi.type = PropertyTagTypeASCII;
                        					pi.length = sizeof(char) \* 30;
                        					pi.value = lat\_lon;
                        
                        					hr = pImageDecoder->SetPropertyItem(pi);
                        					if (SUCCEEDED(hr))
                        					{
                        						IImageEncoder\* pImageEncoder = NULL;
                        
                        						hr = pImgFactory->CreateImageEncoderToFile(
                        							&guidImageEncoderCls,
                        							lpszModPictureFilePath,
                        							&pImageEncoder);
                        
                        						if (SUCCEEDED(hr))
                        						{
                        							IImageSink\* pImageSink = NULL;
                        
                        							hr = pImageEncoder->GetEncodeSink(&pImageSink);
                        							if (SUCCEEDED(hr))
                        							{
                        								UINT uiPropertiesCount = 0;
                        
                        								hr = pImageDecoder->GetPropertyCount(&uiPropertiesCount);
                        								if (SUCCEEDED(hr))
                        								{
                        									UINT totalBufferSize = 0;
                        									UINT numProperties = 0;
                        
                        									hr = pImageDecoder->GetPropertySize(&totalBufferSize, &numProperties);
                        									if (SUCCEEDED(hr))
                        									{
                        										PropertyItem\* pis = (PropertyItem\*)malloc(totalBufferSize);
                        
                        										hr = pImageDecode
                        
                        M Offline
                        M Offline
                        Mohammad Dayyan
                        wrote on last edited by
                        #17

                        kingsimba0511 wrote:

                        I hope you have a 22 inch above screen.

                        I don't have it :(

                        P 1 Reply Last reply
                        0
                        • M Mohammad Dayyan

                          kingsimba0511 wrote:

                          I hope you have a 22 inch above screen.

                          I don't have it :(

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #18

                          And it fits my 20" monitor just fine. Even with the 8-SPACE indenting and large font.

                          M 1 Reply Last reply
                          0
                          • K kingsimba0511

                            I hope you have a 22 inch above screen.

                            bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon)
                            {
                            LPCTSTR lpszModPictureFilePath = lpszPictureFilePath;

                            IImagingFactory\*    pImgFactory = NULL;
                            IImage\*             pImage = NULL;
                            
                            
                            bool                fIsClsFounded    = false;
                            GUID                guidImageEncoderCls;
                            HRESULT             hr = S\_OK;
                            
                            hr = CoCreateInstance(CLSID\_ImagingFactory, NULL, CLSCTX\_INPROC\_SERVER, IID\_IImagingFactory, (void   \*\*)&pImgFactory);
                            
                            if (SUCCEEDED(hr))
                            {
                            	IStream\*        pFileStream = CreateStreamByFileName(lpszPictureFilePath);
                            	IImageDecoder\*   pImageDecoder = 0; 
                            
                            	hr = pImgFactory->CreateImageDecoder(pFileStream, DecoderInitFlagNone, &pImageDecoder);
                            	if (SUCCEEDED(hr))
                            	{
                            		ImageInfo imageInfo;
                            
                            		hr = pImageDecoder->GetImageInfo(&imageInfo);
                            		if (SUCCEEDED(hr))
                            		{
                            			UINT nEncodersCount = 0;
                            			ImageCodecInfo\* pEncoders = NULL;
                            
                            			hr = pImgFactory->GetInstalledEncoders(&nEncodersCount, &pEncoders);
                            			if (SUCCEEDED(hr))
                            			{
                            				for (UINT i = 0; i < nEncodersCount; i++)
                            				{
                            					if (pEncoders\[i\].FormatID == imageInfo.RawDataFormat)
                            					{
                            						guidImageEncoderCls = pEncoders\[i\].Clsid;
                            						fIsClsFounded = true;
                            						break;
                            					}//if
                            				}//for
                            			}//if
                            
                            
                            			// encoder founded now goes to properties
                            			if (fIsClsFounded)
                            			{
                            				PropertyItem pi;
                            
                            				// add latitude
                            				{
                            					// add longitude
                            					pi.id = PropertyTagSoftwareUsed;
                            					pi.type = PropertyTagTypeASCII;
                            					pi.length = sizeof(char) \* 30;
                            					pi.value = lat\_lon;
                            
                            					hr = pImageDecoder->SetPropertyItem(pi);
                            					if (SUCCEEDED(hr))
                            					{
                            						IImageEncoder\* pImageEncoder = NULL;
                            
                            						hr = pImgFactory->CreateImageEncoderToFile(
                            							&guidImageEncoderCls,
                            							lpszModPictureFilePath,
                            							&pImageEncoder);
                            
                            						if (SUCCEEDED(hr))
                            						{
                            							IImageSink\* pImageSink = NULL;
                            
                            							hr = pImageEncoder->GetEncodeSink(&pImageSink);
                            							if (SUCCEEDED(hr))
                            							{
                            								UINT uiPropertiesCount = 0;
                            
                            								hr = pImageDecoder->GetPropertyCount(&uiPropertiesCount);
                            								if (SUCCEEDED(hr))
                            								{
                            									UINT totalBufferSize = 0;
                            									UINT numProperties = 0;
                            
                            									hr = pImageDecoder->GetPropertySize(&totalBufferSize, &numProperties);
                            									if (SUCCEEDED(hr))
                            									{
                            										PropertyItem\* pis = (PropertyItem\*)malloc(totalBufferSize);
                            
                            										hr = pImageDecode
                            
                            D Offline
                            D Offline
                            Dan Neely
                            wrote on last edited by
                            #19

                            kingsimba0511 wrote:

                            I hope you have a 22 inch above screen.

                            It's not the diagonal, it's the resolution. That fits comfortably on my 18" 1600x1200 CRT. I suspect it would fit on my 1400px wide laptop LCD as well.

                            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                            P 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              And it fits my 20" monitor just fine. Even with the 8-SPACE indenting and large font.

                              M Offline
                              M Offline
                              Mohammad Dayyan
                              wrote on last edited by
                              #20

                              I have 17" monitor :-\

                              1 Reply Last reply
                              0
                              • D Dan Neely

                                kingsimba0511 wrote:

                                I hope you have a 22 inch above screen.

                                It's not the diagonal, it's the resolution. That fits comfortably on my 18" 1600x1200 CRT. I suspect it would fit on my 1400px wide laptop LCD as well.

                                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #21

                                And the font, I use 8-point.

                                D 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  And the font, I use 8-point.

                                  D Offline
                                  D Offline
                                  Dan Neely
                                  wrote on last edited by
                                  #22

                                  I use browser default. I've never seen a font only scaling that didn't fubar page layouts at least somewhat. Opera's zoom probably comes closest but there're some video plugins it doesn't scale.

                                  Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    Even so, it's easy enough to do something along the lines of:

                                    success = Operation()

                                    if (success == TRUE)
                                    {
                                    ...
                                    }

                                    if (success == TRUE)
                                    {
                                    ...
                                    }

                                    etc or

                                    do {
                                    success = Operation();
                                    if (!success) break;

                                    success = Operation2();
                                    if (!success) break;

                                    ...
                                    } while(false)

                                    cheers, Chris Maunder

                                    CodeProject.com : C++ MVP

                                    G Offline
                                    G Offline
                                    GibbleCH
                                    wrote on last edited by
                                    #23

                                    Or if it's just functions being called in sequence success = success && Operation1(); success = success && Operation2(); success = success && Operation3(); or more obfuscated... success = success && Operation1() && Operation2() && Operation3();

                                    S 1 Reply Last reply
                                    0
                                    • G GibbleCH

                                      Or if it's just functions being called in sequence success = success && Operation1(); success = success && Operation2(); success = success && Operation3(); or more obfuscated... success = success && Operation1() && Operation2() && Operation3();

                                      S Offline
                                      S Offline
                                      supercat9
                                      wrote on last edited by
                                      #24

                                      If there were nothing other than functions called in sequence, then one could use:

                                      {
                                      if (operation1())
                                      return -1;
                                      else if (operation2())
                                      return -2;
                                      else if (operation3())
                                      return -3;
                                      return 0; /* Success! */
                                      }

                                      which is I think nicer than using the flag. The place the flag is helpful is when there are things going on other than the simple operations, e.g.

                                      if (!error)
                                      {
                                      setup_for_operation2();
                                      error = operation2();
                                      }

                                      I'm not a particular fan of using the && operator; if one wants to put each operation on one line, one could code it as

                                      if (!error) error = operation3();

                                      which is clearer than the && version, is more versatile when zero is error case (the error flag will hold the particular error code returned, instead of having to hold zero or one), and may yield more efficient code if 0 is error and 1 is success (a statement like ok = ok && operation3(); is likely to perform a redundant write to ok when it's equal to zero.

                                      1 Reply Last reply
                                      0
                                      • K kingsimba0511

                                        I hope you have a 22 inch above screen.

                                        bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon)
                                        {
                                        LPCTSTR lpszModPictureFilePath = lpszPictureFilePath;

                                        IImagingFactory\*    pImgFactory = NULL;
                                        IImage\*             pImage = NULL;
                                        
                                        
                                        bool                fIsClsFounded    = false;
                                        GUID                guidImageEncoderCls;
                                        HRESULT             hr = S\_OK;
                                        
                                        hr = CoCreateInstance(CLSID\_ImagingFactory, NULL, CLSCTX\_INPROC\_SERVER, IID\_IImagingFactory, (void   \*\*)&pImgFactory);
                                        
                                        if (SUCCEEDED(hr))
                                        {
                                        	IStream\*        pFileStream = CreateStreamByFileName(lpszPictureFilePath);
                                        	IImageDecoder\*   pImageDecoder = 0; 
                                        
                                        	hr = pImgFactory->CreateImageDecoder(pFileStream, DecoderInitFlagNone, &pImageDecoder);
                                        	if (SUCCEEDED(hr))
                                        	{
                                        		ImageInfo imageInfo;
                                        
                                        		hr = pImageDecoder->GetImageInfo(&imageInfo);
                                        		if (SUCCEEDED(hr))
                                        		{
                                        			UINT nEncodersCount = 0;
                                        			ImageCodecInfo\* pEncoders = NULL;
                                        
                                        			hr = pImgFactory->GetInstalledEncoders(&nEncodersCount, &pEncoders);
                                        			if (SUCCEEDED(hr))
                                        			{
                                        				for (UINT i = 0; i < nEncodersCount; i++)
                                        				{
                                        					if (pEncoders\[i\].FormatID == imageInfo.RawDataFormat)
                                        					{
                                        						guidImageEncoderCls = pEncoders\[i\].Clsid;
                                        						fIsClsFounded = true;
                                        						break;
                                        					}//if
                                        				}//for
                                        			}//if
                                        
                                        
                                        			// encoder founded now goes to properties
                                        			if (fIsClsFounded)
                                        			{
                                        				PropertyItem pi;
                                        
                                        				// add latitude
                                        				{
                                        					// add longitude
                                        					pi.id = PropertyTagSoftwareUsed;
                                        					pi.type = PropertyTagTypeASCII;
                                        					pi.length = sizeof(char) \* 30;
                                        					pi.value = lat\_lon;
                                        
                                        					hr = pImageDecoder->SetPropertyItem(pi);
                                        					if (SUCCEEDED(hr))
                                        					{
                                        						IImageEncoder\* pImageEncoder = NULL;
                                        
                                        						hr = pImgFactory->CreateImageEncoderToFile(
                                        							&guidImageEncoderCls,
                                        							lpszModPictureFilePath,
                                        							&pImageEncoder);
                                        
                                        						if (SUCCEEDED(hr))
                                        						{
                                        							IImageSink\* pImageSink = NULL;
                                        
                                        							hr = pImageEncoder->GetEncodeSink(&pImageSink);
                                        							if (SUCCEEDED(hr))
                                        							{
                                        								UINT uiPropertiesCount = 0;
                                        
                                        								hr = pImageDecoder->GetPropertyCount(&uiPropertiesCount);
                                        								if (SUCCEEDED(hr))
                                        								{
                                        									UINT totalBufferSize = 0;
                                        									UINT numProperties = 0;
                                        
                                        									hr = pImageDecoder->GetPropertySize(&totalBufferSize, &numProperties);
                                        									if (SUCCEEDED(hr))
                                        									{
                                        										PropertyItem\* pis = (PropertyItem\*)malloc(totalBufferSize);
                                        
                                        										hr = pImageDecode
                                        
                                        S Offline
                                        S Offline
                                        sucram
                                        wrote on last edited by
                                        #25

                                        This developer might not be as stupid as we think. Just think how impressed a business user ( with no concept of programming) must be when this code is shown to him/her. A business person will think that a developer that can write code that looks like this (extremely complex in the business users eyes) must be a genius and a great asset to the company. What better job security can you get?

                                        If at first you don't succeed, failure may be your style. (Quentin Crisp) Recession is when a neighbor loses his job. Depression is when you lose yours. (Ronald Reagan)

                                        1 Reply Last reply
                                        0
                                        • K kingsimba0511

                                          I hope you have a 22 inch above screen.

                                          bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon)
                                          {
                                          LPCTSTR lpszModPictureFilePath = lpszPictureFilePath;

                                          IImagingFactory\*    pImgFactory = NULL;
                                          IImage\*             pImage = NULL;
                                          
                                          
                                          bool                fIsClsFounded    = false;
                                          GUID                guidImageEncoderCls;
                                          HRESULT             hr = S\_OK;
                                          
                                          hr = CoCreateInstance(CLSID\_ImagingFactory, NULL, CLSCTX\_INPROC\_SERVER, IID\_IImagingFactory, (void   \*\*)&pImgFactory);
                                          
                                          if (SUCCEEDED(hr))
                                          {
                                          	IStream\*        pFileStream = CreateStreamByFileName(lpszPictureFilePath);
                                          	IImageDecoder\*   pImageDecoder = 0; 
                                          
                                          	hr = pImgFactory->CreateImageDecoder(pFileStream, DecoderInitFlagNone, &pImageDecoder);
                                          	if (SUCCEEDED(hr))
                                          	{
                                          		ImageInfo imageInfo;
                                          
                                          		hr = pImageDecoder->GetImageInfo(&imageInfo);
                                          		if (SUCCEEDED(hr))
                                          		{
                                          			UINT nEncodersCount = 0;
                                          			ImageCodecInfo\* pEncoders = NULL;
                                          
                                          			hr = pImgFactory->GetInstalledEncoders(&nEncodersCount, &pEncoders);
                                          			if (SUCCEEDED(hr))
                                          			{
                                          				for (UINT i = 0; i < nEncodersCount; i++)
                                          				{
                                          					if (pEncoders\[i\].FormatID == imageInfo.RawDataFormat)
                                          					{
                                          						guidImageEncoderCls = pEncoders\[i\].Clsid;
                                          						fIsClsFounded = true;
                                          						break;
                                          					}//if
                                          				}//for
                                          			}//if
                                          
                                          
                                          			// encoder founded now goes to properties
                                          			if (fIsClsFounded)
                                          			{
                                          				PropertyItem pi;
                                          
                                          				// add latitude
                                          				{
                                          					// add longitude
                                          					pi.id = PropertyTagSoftwareUsed;
                                          					pi.type = PropertyTagTypeASCII;
                                          					pi.length = sizeof(char) \* 30;
                                          					pi.value = lat\_lon;
                                          
                                          					hr = pImageDecoder->SetPropertyItem(pi);
                                          					if (SUCCEEDED(hr))
                                          					{
                                          						IImageEncoder\* pImageEncoder = NULL;
                                          
                                          						hr = pImgFactory->CreateImageEncoderToFile(
                                          							&guidImageEncoderCls,
                                          							lpszModPictureFilePath,
                                          							&pImageEncoder);
                                          
                                          						if (SUCCEEDED(hr))
                                          						{
                                          							IImageSink\* pImageSink = NULL;
                                          
                                          							hr = pImageEncoder->GetEncodeSink(&pImageSink);
                                          							if (SUCCEEDED(hr))
                                          							{
                                          								UINT uiPropertiesCount = 0;
                                          
                                          								hr = pImageDecoder->GetPropertyCount(&uiPropertiesCount);
                                          								if (SUCCEEDED(hr))
                                          								{
                                          									UINT totalBufferSize = 0;
                                          									UINT numProperties = 0;
                                          
                                          									hr = pImageDecoder->GetPropertySize(&totalBufferSize, &numProperties);
                                          									if (SUCCEEDED(hr))
                                          									{
                                          										PropertyItem\* pis = (PropertyItem\*)malloc(totalBufferSize);
                                          
                                          										hr = pImageDecode
                                          
                                          G Offline
                                          G Offline
                                          Geoff Field
                                          wrote on last edited by
                                          #26

                                          And the comments on the terminating braces are useless, too.

                                          Professional Geek, Amateur Stage-Levelling Gauge

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups