|
|
Thanks a lot! I am continuing work based on your article.
Regards,
William
|
|
|
|
|
Hello,
I have Microsoft Excel 2003 and want to open in VC++ through CreateDispatch() method of _Application .
_Application app;
app.CreateDispatch("Excel.Application");
With the above I get an error.
What is the parameter that I should use in CreateDispatch() or what are the files that I should check in my directory which are necessary to run _Application.
Pritha
|
|
|
|
|
Hi Pritha,
You should preceed your code with "CoInitialize (NULL);". Next to this, it is better in my experience, to check is Excel is already running and use the running instance of excel if it is. Only start a new instance if no excel is running. I use the following routine:
BOOL OpenExcel (LPCTSTR szFilename)
{
_Application Excel;
BOOL bExcel = FALSE;
CLSID clsid ;
LPDISPATCH lpDispatch ;
LPUNKNOWN lpUnk ;
HRESULT hr;
COleException * Error = new COleException;
CoInitialize (NULL); // We must be initialized first!
//------------------------------------------------------------------------------------
// Check if Excel is already running
//
if (CLSIDFromProgID(OLESTR("Excel.Application"), &clsid) == NOERROR)
{
if (GetActiveObject (clsid, NULL, &lpUnk) == S_OK)
{
hr = lpUnk->QueryInterface(IID_IDispatch, (LPVOID*)&lpDispatch) ;
lpUnk->Release() ;
if (hr == NOERROR) // Yep, excel is already there
{
Excel.AttachDispatch (lpDispatch, TRUE) ;
bExcel = TRUE;
}
}
}
if (!bExcel) // Excel was not yet running
{
bCreated = TRUE; // we now created an instance of Excel ourselves
bExcel = TRUE; // start from a positive assumption
try
{
if(!Excel.CreateDispatch("Excel.Application",Error)) // Create the instance
throw Error; // throw an error on failure
}
catch (COleDispatchException * Error) // Oops... could not create...
{
CString strMessage;
strMessage = "Could not launch Microsoft Excel\r\n";
if (!Error->m_strSource.IsEmpty())
{
strMessage += Error->m_strSource;
strMessage += " - ";
}
if (!Error->m_strDescription.IsEmpty())
strMessage += Error->m_strDescription;
else
strMessage += "unknown error";
MessageBox (HWND_DESKTOP, (LPCTSTR)strMessage, NULL, MB_OK|MB_ICONERROR);
bCreated = FALSE; // no Excel created afterall
bExcel = FALSE; // and no Excel running....
}
}
Error->Delete (); // we do not need the Error exception
return bExcel;
}
|
|
|
|
|
Hello,
Your code above was useful.I wanted to find out how many rows should be read from the sheet.For that I have used the following but it doesn't work.
LPDISPATCH lpDisp;
lpDisp = sheet.GetUsedRange();
range.AttachDispatch(lpDisp);
range.Select();
range.GetRows();
long lTotalRows = range.GetCount();
Any ideas
Thanks
Prithaa
|
|
|
|
|
Hello Prithaa,
I am not sure, but I think the following should work (did not test it though)
Range Rng;
Range Rws;
Rng = Sheet.GetUsedRange ();
Rws = Rng.GetRows ();
long lTotalRows = Rws.GetCount ();
Rws.ReleaseDispatch ();
Rng.ReleaseDispatch ();
There is no need to use a separate LPDISPATCH and then connect it to a Range variable; you can do this directly as above.
Regards,
William
|
|
|
|
|
Hello everyone,
I think printf %d works fine with signed, unsigned and negative integer values, and the same as %ld for long. Is that correct? If not, do we need to special conversion?
thanks in advance,
George
|
|
|
|
|
Hi George,
Yep, you are right. Although I must say that in today's implementation there is no difference between int and long (they both are 4 bytes)
William
|
|
|
|
|
Thanks William!
regards,
George
|
|
|
|
|
I tried with
long int li = 0xFFFFFFFFL;
unsigned long int uli = 0xFFFFFFFFL;
printf( "%ld %ld\n", li, uli );
short int si = 0xFFFF;
unsigned short int usi = 0xFFFF;
printf( "%d %d\n", si, usi );
And the result was
-1 -1
-1 65535
- NS -
|
|
|
|
|
Thanks NS17!
I am clear.
regards,
George
|
|
|
|
|
Hi All,
I have an application which updates itself when new version is available . But thises updates are having a problem if the app is run by a user having non admin rights , as the service alters the files in %program Files% folder , registry settings while updating . if the user is a non admin then these processes fail and thus the update fails . Is there any way by which i can find if the logged in user is a administrator or not ? so that i dont allow updates for a non admin user ???
Thanks in Advance
Vijayeta
|
|
|
|
|
vijayeta wrote: Is there any way by which i can find if the logged in user is a administrator or not ?
IsUserAnAdmin()
|
|
|
|
|
IsUserAnAdmin() where is this method ?? , as i am using MFC
|
|
|
|
|
it is declared in ShlObj.h and is located in the dll shell32.dll. You need to install platfor sdk to class this function. Optionally you can dynamically load the dll and call it with the help of LoadLibrary and GetProcAddress().
|
|
|
|
|
|
Naveen.R wrote: You need to install platfor sdk to class this function
Depends on the version of Visual Studio - the function was added for W2k. It is included in the VS2005 headers.
Judy
|
|
|
|
|
netusergetlocalgroups
Prasann
who else
|
|
|
|
|
chk this link.
http://www.codeproject.com/win32/accessctrl2.asp#Groups
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
|
Hi all , i used the IsUserAnAdmin() func and it worked on windows XP , but it fails on Vista , on Vista even foa an Admin it is returning False , can anybody help me out in this matter ??
Vijayeta
|
|
|
|
|
Hi! I m trying to view a MS Word *.Doc File in HTML view in VC++,by using Navigate2() function of CHtml view class. But the problem is that when the File viewed on HTML view all controls work,means i can right click on it,save this file by using F12 key ,open its help by pressing F1 key and all the other control. I just want to stop(disable) the working of these control. If i do EnableWindow(FALSE),it not only stop the working bt also stop the scrolling. I just want to stop the working of *.doc controls.
Raj
-- modified at 6:33 Wednesday 24th October, 2007
|
|
|
|
|
Hi All,
Can somebody tell me the reason ,Why wizards generate enum IDD for dialogs?
Thanks,
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|
|
NiceNaiduCan somebody tell me the reason ,Why wizards generate enum IDD for dialogs?
The IDD enum of a dialog class contains the ID of dialog in the resource.
enum { IDD = IDD_MYDLG_DIALOG };
This IDD is passed in the constructor of your dialog to CDialog constructor.
CMyDlg::CMyDlg(CWnd* pParent )<br />
: CDialog(CMyDlg::IDD, pParent)<br />
{<br />
}
You can simply get the ID of the dialog with a statement like CMyDlg::IDD
So when creating a dialog, we can use like
CMydlg dlg;<br />
dlg.Create( CMydlg::IDD, 0 )
Instead of
CMydlg dlg;<br />
Dlg.Create( IDD_MYDLG_DIALOG, 0 )
When MFC was initially developed a statement like the below one was not supported.
Class CMyDlg: public CDialog<br />
{<br />
....<br />
<br />
public:<br />
static const DWORD IDD = IDD_MYDLG_DIALOG;<br />
}
Also the trick of keeping an enum doesnt increase the memory size of object
|
|
|
|
|
Thanks Nave..
Don't get surprised, if someone says " You are my Role Model.".
You are doing good job.
Keep going.
Appu.
Appu..
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
|
|
|
|