Click here to Skip to main content

Manish K. Agarwal - Professional Profile

Summary

13,409
Author
219
Authority
90
Debator
41
Editor
7
Enquirer
285
Organiser
1,030
Participant
Working with Pitney Bowes, Noida (India). Using C/C++, VC++, MFC, STL, C#, Java etc. on various platform like Windows, Unix, Macintosh etc. from last 12 years to convert various type of requirements into running software components. My core expertise is multithreaded desktop product development on Windows.
Member since Friday, May 18, 2001 (11 years, 11 months)

Contributions

Articles 4 (Legend)
Tech Blogs 0
Messages 155 (Lurker)
Q&A Questions 2
Q&A Answers 0
Tips/Tricks 6
Comments 12

Links

Reputation

For more information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege, and the given member types also gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilverAdmin
Store personal files in your account areaplatinumplatinumSitebuilder, Subeditor, Supporter, Editor, Staff
Have live hyperlinks in your biographybronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Edit a Question in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Edit an Answer in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Delete a Question in Q&AYesSubeditor, Protector, Editor, Admin
Delete an Answer in Q&AYesSubeditor, Protector, Editor, Admin
Report an Articlesilversilversilversilver
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubeditor, Mentor, Protector, Editor, Staff, Admin
Edit other members' articlesSubeditor, Protector, Editor, Admin
Create an article without requiring moderationplatinumSubeditor, Mentor, Protector, Editor, Staff, Admin
Report a forum messagesilversilverbronzeProtector, Editor, Admin
Create a new tagsilversilversilversilverAdmin
Modify a tagsilversilversilversilverAdmin

Actions with a green tick can be performed by this member.


 
You must Sign In to use this message board.
Search this forum  
Generallocale setting Pin
Wednesday, November 3, 2010 8:53 PM by Manish K. Agarwal
We can use _tsetlocale to set the locale used by CRT functions like wcstod to convert string to double etc.
 
Call to _tsetlocale
 
_tsetlocale(LC_NUMERIC, _T("German_Germany.1252"));
 
Current OS Locale string can be retrieved using following function:
 
CString GetLocaleStr()
{
	CString localeStrBuf;
	TCHAR strBuf[128];
	memset(strBuf, 0, sizeof(strBuf));
	
	// Load the English name of the locale
	GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, strBuf, 127);
	localeStrBuf = strBuf;
 
	memset(strBuf, 0, sizeof(strBuf));
 
        // Load the English name for the country/region
	GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGCOUNTRY, strBuf, 127);
	if (*strBuf)
	{
		localeStrBuf += _T("_");
		localeStrBuf += strBuf;
	}
 
	memset(strBuf, 0, sizeof(strBuf));
 
        // Load the code page
	if ((GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, strBuf, 127)
		|| GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE, strBuf, 127))
		&& *strBuf)
        {
		localeStrBuf += _T(".");
		localeStrBuf += strBuf;
	}
 
	return localeStrBuf;
}
 
Also we can change the locale to environment locale as following:
 
   TCHAR* lcl = _tcsdup(::_tsetlocale(LC_NUMERIC, NULL)); //Save the current locale
   ::_tsetlocale(LC_NUMERIC, _T(""));  //Set the locale to the environment locale

   // your code

   ::_tsetlocale(LC_NUMERIC, lcl); //restore the original locale
   free(lcl);
Manish Agarwal
manish.k.agarwal @ gmail DOT com

 
GeneralWildcard pattern matching Pin
Thursday, July 8, 2010 10:05 PM by Manish K. Agarwal
Algo for wildcard base search.
 
BOOL CheckPattern(LPTSTR pattern, LPTSTR str)
{
   LPTSTR pStrCurPos = NULL;
   LPTSTR pPatCurPos = NULL;
   LPTSTR pStrMatchPos =  NULL;
   LPTSTR pPatMatchPos = NULL;
   BOOL fIsAsterisk  = FALSE;
 

   pStrMatchPos = pStrCurPos = str;
   pPatMatchPos = pPatCurPos = pattern;
 

 
   while (*pStrCurPos != '\0')
   {
      if (*pPatCurPos == _T('*'))
      {
         fIsAsterisk = TRUE;
 
         
         // Set matched string to cur position
         pStrMatchPos = pStrCurPos;
 
         // Move to the next position in the pattern
         pPatMatchPos = ++pPatCurPos;
 
         if (*pPatMatchPos == '\0')
         {
            return TRUE;
         }
 
         continue;
      }
      else if (*pPatCurPos == _T('?'))
      {
        // do nothing just move to next char
      }
      else if (*pStrCurPos != *pPatCurPos)
      {
         if (fIsAsterisk == FALSE)
         {
             // Not processing wildcard
            return FALSE;
         }
 
         // Move to next position in String
         pStrCurPos = ++pStrMatchPos;
 
         // Reset pattern in matched position
         pPatCurPos = pPatMatchPos;
 
         continue;
      }
 
      // Move current position forward
      ++pStrCurPos;
      ++pPatCurPos;
   } // while

 
   if (*pPatCurPos == _T('*'))
      ++pPatCurPos;
 
   return (*pPatCurPos == _T('\0'));
}
Manish Agarwal
manish.k.agarwal @ gmail DOT com

 
GeneralRemote Debugging: Quick Steps Pin
Friday, June 19, 2009 1:07 AM by Manish K. Agarwal
Here are some simple steps for remote debugging of a 32 bit WinForm application:
 
Remote Machine:
1. Copy “x86” folder from “C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger” on remote machine.
 
2. Right click on “.\x86\msvsmon.exe” and click on “Run as…” and specify the user name for the system where Visual Studio is running.
 
3. Share your executable folder and place pdb files or you can specify the location pdb files by right click on your module during debugging in modules windows.
 
VS2008 Machine:
 
1. In Visual Studio, choose Project Properties and select Debug tab.
 
2. In the “Start Action” setting, select “Start External Program” and specify the executable on the remote computer (e.g. “\\manishdesktop\Application\MyApp.exe”.)
 
3. Under “Start Options” in the working directory box, type the directory where the executable is located. (e.g. \\manishdesktop\Application)
 
4. Select “Use Remote Machine” and specify the remote machine name. You can specify any command line arguments to pass to the application.
 
5. Start debugging from Debug Menu.
 
Manish Agarwal
manish.k.agarwal @ gmail DOT com

GeneralRe: Remote Debugging: Quick Steps PinmemberTejaSingh8 Jul '09 - 20:05 
 
GeneralAnother C++ Singleton pattern implementation Pin
Tuesday, April 7, 2009 7:21 PM by Manish K. Agarwal
Generally I have seen that for singleton implementation, we declare a static pointer mSingletonP and static method GetInstance(). Inside GetInstance(), we check if mSingletonP is NULL, allocate it using new and return the pointer otherwise if it is already allocated simply return the pointer. Typically we implement like this:
 
class MySingleton
{
public:
	static MySingleton *GetInstance(){
		if (mMySingletonP == NULL) {
			mMySingletonP = new MySingleton;
		}
 
		return mMySingletonP;
	}
 
private:
	MySingleton(){
	}
 
	MySingleton(const MySingleton & ){
	}
 
	MySingleton & operator=(const MySingleton & ) {
		// Wrong but we just want a private implementation
		// We simply want no one call this.
		return *((MySingleton *)NULL);
	}
 
	~MySingleton(){
	}
 
	static MySingleton *mMySingletonP;
 
};
Further if we want that at the end destructor must invoke, we use atexit(), C Run Time library function and register some function which will take care of delete mMySingltonP.
 
Recently I have a seen a nice implementation of Singleton. This implementation is good if want to invoke destructor without using atexit. This is not thread safe and this is based on a static keyword. Implementation is as below:
 
class Singleton
{
public:
	static Singleton &GetInstance(){
		static Singleton instance;
 
		return instance;
	}
 
private:
	Singleton(){
	}
 
	Singleton(const Singleton & ){
	}
 
	Singleton & operator=(const Singleton & ) {
		// We simply want no one call this.
		return *this;
	}
 
	~Singleton(){
	}
 
};

Above is the best implementation for non thread safe singleton and below is the best implementation for thread safe singleton.
 
For thread safe implementation of GetInstance() we use double NULL checking and locking in our traditional singleton implementation i.e.
 
static MySingleton *GetInstance() {
 
     if (mMySingletonP == NULL) {
           // Aquire a lock here
           if (mMySingletonP == NULL) {
                mMySingletonP = new MySingleton;
           }
           // relase lock here
     }
 
     return mMySingletonP;
}
Please share your views on the same.
 
Usage:
int _tmain(int argc, _TCHAR* argv[])
{
	int nTmp1 = 10;
	Singleton &firstRef = Singleton::GetInstance();
 
	Singleton &otherRef = Singleton::GetInstance();
 
	return 0;
}

 
Manish Agarwal
manish.k.agarwal @ gmail DOT com

 
Generalsprintf_s on UNIX / Mac Pin
Thursday, November 20, 2008 11:42 PM by Manish K. Agarwal
Microsoft CRT has new good security enhancements. I specially miss the sprintf_s on UNIX/ Mac
 
I have to write my own version of sprintf_s for Apple Macintosh something like this-
 
int sprintf_s1(char* buffer, size_t bufferSize, const char *formattingString, ...)
{
  int size = -1;
 
  if (bufferSize < 1 || buffer == NULL) {
	  return size;
  }
  va_list argptr;
 
  va_start(argptr, formattingString);
 
  //FILE *nul = fopen("nul", "w");
  
  // calculate the size of output by nul device.
  size = vfprintf(stderr, formattingString, argptr);
  //fclose(nul);

  if (size > bufferSize) {
    return -1;
  }
 
  size = vsprintf(buffer, formattingString, argptr);
  // ensure null termination.
  buffer[(size > 0) ? (size-1) : 0] = '\0';
 
  va_end(argptr);
 
   return size;
}
 
Any better way to calculate the size of output apart from using stderr or nul device
 
Manish Agarwal
manish.k.agarwal @ gmail DOT com
 
GeneralActivation Codes Pin
Thursday, November 24, 2005 6:55 PM by Manish K. Agarwal
Activation codes used to stop unauthorized software copy. One way to generate activation codes, gather some unique information (like CPU id, hard disk id, network card id etc.) from the system and write somewhere in the disk or use ImageAddCertificate() API on Windows to put this information in your executable itself.
 
Read your activation code by reading activation data through ImageGetCertificateData() and validate it. But what to do if due to some reason user change his network card or CPU etc.
 
If we need to install the software again ? No, generally all professional software take care of this situation.
 
I think, one idea could be gather such 4 - 5 unique IDs and make a rule that if any of 2 ids are same, continue execution otherwise show error unauthorized copy Cool | :cool: .
 
There could some more better ways to deal this. Starting this thread to discuss more about activation codes generation.
 

Manish Agarwal
manish.k.agarwal @ gmail DOT com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130513.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid