Click here to Skip to main content
15,887,326 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt24-Mar-15 0:17
professionalJochen Arndt24-Mar-15 0:17 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023725-Mar-15 4:25
Member 935023725-Mar-15 4:25 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt25-Mar-15 4:46
professionalJochen Arndt25-Mar-15 4:46 
GeneralMessage Closed Pin
25-Mar-15 6:47
Member 935023725-Mar-15 6:47 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt25-Mar-15 6:56
professionalJochen Arndt25-Mar-15 6:56 
QuestionBIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus16-Mar-15 11:24
Tacitonitus16-Mar-15 11:24 
AnswerRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C16-Mar-15 13:00
Frankie-C16-Mar-15 13:00 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus16-Mar-15 15:36
Tacitonitus16-Mar-15 15:36 
Apologies. I made a mistake in transcribing the original code.

Which actually has nothing to do with why this code still doesn't work - just to be clear.

In the original code, the NID->szTip, NID->szInfoTitle, and NID->szInfo structure members are not initialized by strcpy(). I changed it to a bunch of strcpy() calls to "simplify" the code (to make it easier to read)..

They are initialized in the original code by a function call whose return value sets an auto bool called, "Opning". When I substituted out that function call for those strcpy() calls (for simplicity), I also (erroneously) took out the "bool Opning =" part.

My bad.

To make a long story short, the following is a far more correct "transcription" of the existing code:
C++
#define TRAY_ICON_ID  0xABC  // <== ..our System Tray Icon Id
#define BALL_ICON_ID  0xDEF  // <== ..our Balloon Tip Icon Id

#define MSG_FROM_TRAY  (WM_APP + 0xDAD)   // <== ..the "callback message" ID..

static NOTIFYICONDATA *NID;

static void Init_NID( HWND hDlg )
{
    if ( NID = new NOTIFYICONDATA )
    {
         memset( NID, 0, sizeof( NOTIFYICONDATA ) );

         if ( LoadIconMetric( AppInst,
                              (PCWSTR)MAKEINTRESOURCE( IDR_TrayIcon ),
                              LIM_SMALL, &NID->hIcon ) == S_OK )
         {
              if ( LoadIconMetric( AppInst,
                                   (PCWSTR)MAKEINTRESOURCE( IDR_BallIcon ),
                                   LIM_SMALL, &NID->hBalloonIcon ) == S_OK )
              {
                   bool Opning;

                   if ( Opning = LoadStrings( NID->szTip,
                                              NID->szInfo,
                                              NID->szInfoTitle ) )
                   {
                        NID->uTimeout = 5000;
                        NID->uID = TRAY_ICON_ID;
                        NID->dwInfoFlags = NIIF_USER;
                        NID->uCallbackMessage = MSG_FROM_TRAY;
                        NID->cbSize = sizeof( NOTIFYICONDATA );
                        NID->dwState = 0;
                        NID->dwStateMask = NIS_HIDDEN | NIS_SHAREDICON;

                        return;   // <== i.e. RETURN to caller w/ NID != NULL..
                   }

                   DestroyIcon( NID->hBalloonIcon );
              }

              DestroyIcon( NID->hIcon );
         }

         delete NID;
         NID = NULL;
    }
}

Again, sorry for that oversight.

However, as is readily apparent from the above code, it is incorrect to say that the "memory is released when sub exits". The memory is only released if the function fails to initialize the entire structure.

Thing is though, even if the function does fail (which BTW, I've never seen it do, and I've debugged this a lot), then the NID variable would get set to NULL, which would prevent the Shell_NotifyIcon() function from ever getting called (because the function that calls it checks the NID before it does anything else).

And to forestall the inevitable question, yes, I am sure that my "LoadString()" function is not overwriting any other structure members (with strings too big)..

Anyway, the structure always initializes fine, so I don't think that's the problem.

I am curious though, about what you meant when you said that it "works for me"? Are you compiling in 64-bit?
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C16-Mar-15 22:39
Frankie-C16-Mar-15 22:39 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus17-Mar-15 3:34
Tacitonitus17-Mar-15 3:34 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 4:11
Frankie-C17-Mar-15 4:11 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Tacitonitus17-Mar-15 7:21
Tacitonitus17-Mar-15 7:21 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 7:29
Frankie-C17-Mar-15 7:29 
GeneralRe: BIG trouble with 64-bit Shell_NotifyIcon() - can anyone help? Pin
Frankie-C17-Mar-15 22:48
Frankie-C17-Mar-15 22:48 
QuestionVC++ DLL throws error when call it from C#[EntryPointNotFound] Pin
Member 988367216-Mar-15 1:38
Member 988367216-Mar-15 1:38 
AnswerRe: VC++ DLL throws error when call it from C#[EntryPointNotFound] Pin
Richard Andrew x6416-Mar-15 5:48
professionalRichard Andrew x6416-Mar-15 5:48 
QuestionIAccessible - get word under mouse pointer in IE Pin
Fourblack15-Mar-15 22:01
Fourblack15-Mar-15 22:01 
QuestionC++ to C problem Pin
alexx00614-Mar-15 10:03
alexx00614-Mar-15 10:03 
AnswerRe: C++ to C problem Pin
Richard Andrew x6414-Mar-15 13:15
professionalRichard Andrew x6414-Mar-15 13:15 
AnswerRe: C++ to C problem Pin
Frankie-C15-Mar-15 5:49
Frankie-C15-Mar-15 5:49 
GeneralRe: C++ to C problem Pin
David Crow16-Mar-15 2:54
David Crow16-Mar-15 2:54 
QuestionUI widget Pin
Member 1152499814-Mar-15 7:01
Member 1152499814-Mar-15 7:01 
AnswerRe: UI widget Pin
Albert Holguin15-Mar-15 17:19
professionalAlbert Holguin15-Mar-15 17:19 
QuestionUI widget Pin
Member 1152499814-Mar-15 6:52
Member 1152499814-Mar-15 6:52 
QuestionFeatures and rich documentation of MFC vs Small Executable of WTL Pin
Member 1120327711-Mar-15 4:21
Member 1120327711-Mar-15 4:21 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.