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.
  • K Offline
    K Offline
    kingsimba0511
    wrote on last edited by
    #1

    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 D M M D 9 Replies 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
      Malli_S
      wrote on last edited by
      #2

      :omg: wasn't he aware of

      return false

      statement? Might wanna to stick with "single entry-single exit" type of function coding..... :-\

      [Delegates]      [Virtual Desktop]      [Tray Me !]
      -Malli...! :rose:****

      G 1 Reply Last reply
      0
      • M Malli_S

        :omg: wasn't he aware of

        return false

        statement? Might wanna to stick with "single entry-single exit" type of function coding..... :-\

        [Delegates]      [Virtual Desktop]      [Tray Me !]
        -Malli...! :rose:****

        G Offline
        G Offline
        gri
        wrote on last edited by
        #3

        "return false" alone might not help, a CComPtr (was that the name? never did mfc..) would also be useful ;)

        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
          Dalek Dave
          wrote on last edited by
          #4

          Easier to do specific cases surely?

          ------------------------------------ "The greatest tragedy in mankind's entire history may be the hijacking of morality by religion" Arthur C Clarke

          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
            mav northwind
            wrote on last edited by
            #5

            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 C 2 Replies Last reply
            0
            • G gri

              "return false" alone might not help, a CComPtr (was that the name? never did mfc..) would also be useful ;)

              M Offline
              M Offline
              Malli_S
              wrote on last edited by
              #6

              I commented just by seeing return type of the function. Did't dare to look into 16 layers at all... :^) As per prototype bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon) my comment meant the function would return false in case of failure (rather increasing the layers). :~

              [Delegates]      [Virtual Desktop]      [Tray Me !]
              -Malli...! :rose:****

              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...

                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
                                          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