|
What do you really mean?
You know there's a function, namely LoadLibrary[^] to (explicitely) load a dynamic library.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The question isn't very clear, I'm afraid.
If you use "pure C++" to mean only standards-compliant language elements/libraries, the answer is that you can't. To start with, DLL files are specific for the Windows platform, so any solution would not work on Unix/Linux/MacOS etc.
If you are concerned that the Windows function to load a DLL (LoadLibrary , as already noted) is a C function, and therefore should not for some reason be used in "pure C++", don't worry - a large reason for making C++ backwards compatible with C was that many operating systems offer their native APIs as C functions, and calling them is a perfectly valid use of C++.
|
|
|
|
|
Here is an exception-free way :
class CSafeDllHolder {
HMODULE m_hModule;
public:
CSafeDllHolder(LPCTSTR lpszLib) : m_hModule(::LoadLibrary(lpszLib)) {}
~CSafeDllHolder() { if (m_hModule) ::FreeLibrary(m_hModule); }
HMODULE GetHandle() const { return m_hModule; }
};
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Hello,
Can you please explain me what is mfc100u.lib and its got to do with VS2010?
Thanks.
|
|
|
|
|
1. Drag-select "mfc100u.lib" in your last post
2. Right-click, select "Search Google for mfc100u.lib"
3. click 2nd search result.
It took less time than reading your question. Presumably I can read your question quicker than you can type it?!
|
|
|
|
|
Hi,
I need to add worksheets(like sheet2,sheet3,...) with the below exising code. Now sheet1 is coming by default and able to write the contents.
Existing Code:
--------------
COleException objEx; // exception object
Application objExcel; // excel application object
// local var
COleVariant vRet;
// row index
long nRow = 1;
// range object
Range objRange;
// create the excel object
objExcel.CreateDispatch( "Excel.Application", &objEx );
// show the application
objExcel.SetVisible( COleVariant(short(FALSE)) );
// get the workbooks object
vRet = objExcel.Workbooks2();
// set the workbooks object
Workbooks objWorkbooks( V_DISPATCH( (LPVARIANT)vRet ) );
// adding the new workbook
vRet = objWorkbooks.Add( COleVariant( (long)xlWorksheet ) );
// set the workbook object
Workbook objWorkbook( V_DISPATCH( (LPVARIANT)vRet ) );
// adding the worksheet
vRet = objWorkbook.Worksheets( COleVariant( (long)1 ) );
// set the worksheet object
Worksheet objWorksheet( V_DISPATCH( (LPVARIANT)vRet ) );
How to add more sheets with the above code? Please help.
I am using below header files;
#include "XL5EN32.H"
#include "excel9.h"
#include "ExcelObject.h"
Thanks,
Pala
|
|
|
|
|
Did you try this[^] class ?
|
|
|
|
|
I have the follow code :
#if _MSC_VER > 1200
BOOL CMainFrame::ShowNotifyBaloon(LPCTSTR lpszBalloonTitle, LPCTSTR lpszBalloonMsg, DWORD dwIcon, UINT nTimeOut)
{
ASSERT (dwIcon == NIIF_WARNING || dwIcon == NIIF_ERROR || dwIcon == NIIF_INFO || dwIcon == NIIF_NONE);
NOTIFYICONDATA nid = {sizeof(NOTIFYICONDATA)};
nid.uID = 0;
nid.hWnd = m_hWnd;
nid.dwInfoFlags = dwIcon;
nid.uFlags |= NIF_INFO;
nid.uTimeout = nTimeOut;
nid.uCallbackMessage = WMU_TRAYNOTIFYICON;
::strcpy(nid.szInfoTitle,lpszBalloonTitle);
::strcpy(nid.szInfo,lpszBalloonMsg);
return ::Shell_NotifyIcon(NIM_MODIFY,&nid);
}
#endif // _MSC_VER > 1200
ShowNotifyBaloon(_T("Info"),_T("Test message"),NIIF_INFO,5);
and the ShowNotifyBaloon method is calling because I verify that through a TRACE macro, but still, I don't see any baloon in system tray ( I have to mention that application is minimized in system tray ).
What I'm doing wrong ?
modified on Saturday, September 3, 2011 10:12 AM
|
|
|
|
|
I see that you're not setting the size member of the structure:
nid.cbSize = sizeof( NOTIFYICONDATA );
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you for feedback, I will try what you said, but right now I haven't newer environment then VC6 ... Thank you.
|
|
|
|
|
Technically, he is with the initializer
NOTIFYICONDATA nid = {sizeof(NOTIFYICONDATA)}; but it only works because the .cbSize element is offset 0. This is bad programming practice. Doublly so since he responded to your suggestion with "I will try what you said", meaning that he didn't know he was initializing it, probably somebody else's code he's trying.
Best practices would the to explicitly initialize the structure like this
NOTIFYICONDATA tnid;
memset(&tnid, 0, sizeof(tnid));
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = GetSafeHwnd();
etc...
|
|
|
|
|
Chuck O'Toole wrote: Technically, he is with the initializer
Wow, learn something every day. I didn't realize that's what that code does.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Did you also ever create the notify icon by calling Shell_NotifyIcon with NIM_ADD.
See this MSDN page[^] for a technical description of the function.
|
|
|
|
|
Yes, of course, I have already icon in system tray. I just want to setup NIM_MODIFY parameter to show up a baloon notification.
|
|
|
|
|
Does the code work if you make the proposed modification of explicitly setting cbSize, along with the following: nid.uFlags = NIF_INFO; rather than |= which can (and I think in this case does) lead to errors?
|
|
|
|
|
This code works for me. You're probably missing some flag in your code.
void CMainFrame::PopupTrayBalloon(CString title, CString msg)
{
NOTIFYICONDATA tnid;
OSVERSIONINFO ver;
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&ver)) return;
if ((ver.dwPlatformId == VER_PLATFORM_WIN32_NT) && (
((ver.dwMajorVersion == 5) && (ver.dwMinorVersion > 0)) ||
((ver.dwMajorVersion == 6) && (ver.dwMinorVersion >= 0)) ))
{
memset(&tnid, 0, sizeof(tnid));
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = GetSafeHwnd();
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO;
tnid.dwInfoFlags = NIIF_INFO;
tnid.uTimeout = 10000;
lstrcpyn(tnid.szInfoTitle, title, sizeof(tnid.szInfoTitle));
lstrcpyn(tnid.szInfo, msg, sizeof(tnid.szInfo));
tnid.hIcon = LoadIcon(GetMainInstance(), MAKEINTRESOURCE(IDR_MAINFRAME));
tnid.uCallbackMessage = MY_ICONNOTIFICATION;
Shell_NotifyIcon(NIM_MODIFY, ((NOTIFYICONDATA *)&tnid));
}
}
|
|
|
|
|
Thank you very much ! I will try this code.
|
|
|
|
|
Does the supplied code work? Please also check out my other post, as it might help you in the future (for instance, when testing on 64 bits).
|
|
|
|
|
Why are you using GetVersion in this way? If this code now attempts to run under a future OS it will fail, without any need. For instance, if Windows 8 (or later) gets a major version of 7 then this code will artificially stop running. You should really use better version checks of Windows, as this can lead to real problems in the future.
A little further note on compatibility, rather than using lstrcpyn use StringCchCopy as advised by MSDN. Also, sizeof(tnid.szInfoTitle) returns the amount of char's, meaning it's twice as big as it should be under Unicode, which effectively removes the security layer add by using this particular function over a simple _tcscpy.
Ok, I'm sounding like a real nagger here. I don't mean to, I just want to avoid hard-to-solve bugs in the future.
|
|
|
|
|
The code was offered as a way of showing all the fields that need to be filled in to achieve a working solution, cut / paste at your own peril.
I can't predict what a future OS might look like, nor can you. However, I do know that some old OS'es do not support the balloon so I do not attempt it there, the results are unpredictable.
Thanks for your comments
|
|
|
|
|
Finnaly I get the notify baloon with follow code :
BOOL CMainFrame::ShowNotifyBaloon(LPCTSTR lpszBalloonTitle, LPCTSTR lpszBalloonMsg, DWORD dwIcon, UINT nTimeOut)
{
ASSERT (dwIcon == NIIF_WARNING || dwIcon == NIIF_ERROR || dwIcon == NIIF_INFO || dwIcon == NIIF_NONE);
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.uID = 0;
nid.dwInfoFlags = dwIcon;
nid.hWnd = GetSafeHwnd();
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO;
nid.uTimeout = nTimeOut;
nid.uCallbackMessage = WMU_TRAYNOTIFYICON;
::strcpy(nid.szInfoTitle,lpszBalloonTitle);
::strcpy(nid.szInfo,lpszBalloonMsg);
return ::Shell_NotifyIcon(NIM_MODIFY,&nid);
}
but still has a problem : when baloon show up, the systemtray icon dissapear !? Why ? I compile code with VC6 + SDK, and I try it on Win7.
|
|
|
|
|
I realize you had to make changes to my code but I don't think the .dwInfoFlags field is where you stick the dwIcon. And you don't fill in the .hIcon field in the structure so I'm not surprised that the icon disappears. Go back and check the code I posted
|
|
|
|
|
Lookup the definition of the flag NFI_ICON, it says:
NIF_ICON (0x00000002)
0x00000002. The hIcon member is valid.
but you didn't fill in the .hIcon field (well, memset() zeroed it).
Either give it an Icon handle in .hIcon or remove the NFI_ICON flag.
|
|
|
|
|
You are right, and it is good to avoid calling the function on OSes that are too old to support it. But we can reasonably assume that the code will work on future OSes, as has most always been the case with Windows (high level of backwards compatibility, via extended (FuncXyzEx) functions), so I was suggesting only setting a minimum.
When changing the compatibility setting for an executable to an older version of windows, the GetVersion API changes along to display the 'emulated' setting. The reason is does this is to 'fix' code that does version checks 'the wrong way' (restricting it from above. Such as applications for XP that stop working on Windows 7 because they only checked if major version was 5).
While searching for an article I once saw, I found this: VerifyVersionInfo Function[^] which does what we want for us.
|
|
|
|
|
Finally goes fine ... here is the code :
BOOL CMainFrame::ShowNotifyBaloon(LPCTSTR lpszBalloonTitle, LPCTSTR lpszBalloonMsg, DWORD dwIcon, UINT nTimeOut)
{
ASSERT(dwIcon == NIIF_WARNING || dwIcon == NIIF_ERROR || dwIcon == NIIF_INFO || dwIcon == NIIF_NONE);
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.uID = 0;
nid.dwInfoFlags = dwIcon;
nid.hWnd = GetSafeHwnd();
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO;
nid.uTimeout = nTimeOut;
nid.hIcon = theApp.LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME));
nid.uCallbackMessage = WMU_TRAYNOTIFYICON;
::strcpy(nid.szInfoTitle,lpszBalloonTitle);
::strcpy(nid.szInfo,lpszBalloonMsg);
return ::Shell_NotifyIcon(NIM_MODIFY,&nid);
}
Thank you very much, for your kindness and patience !
|
|
|
|