|
I think the guy was asking about using exceptions in general, not wrapping all up in try/catch blocks. Please note that he refers to (quote) "the "try{ throw }catch()" sentence". If he's reading this maybe he can make it clear what was his original intent.
I am a vocal advocate of try/catch as an alternative to goto, your example number two is very similar to stuff I have posted many times.
Good to know we're on the same side.
By the way, a BOOL is an int, bool should be used instead.
Got me (ouch!)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Not sure what you mean. My VC++ code contains many try/throw/catch statements. I often use then in file handling and DAO database I/O.
|
|
|
|
|
I think what he means is (incase you were asking)
Exception handling was included in C++ because C style error checking is almost tedious and would cause confusion to the reader. If you checked the ret value on each function call that would compile into bulky slower code.
if(printf("hey") < NULL)
AfxMessageBox("Error");
Exception handling requires extra type info, which I think is where the slower execution stuff comes in, the crapola is figured out at run time instead of at compile. So I agree with him there, yes it's slower, but I also thought it was the prefered method of error checking. It's the new way.
Besides if you can avoid testing the return on each function certainly this would out-weigh exception handling?
Have a day!!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
G'Day All
I am writing an NT service that uses some MAPI stuff. According to MSDN (and experimentation) it seems that must run without a desktop. Which is fine and indeed I have that part working. However I would like to add some functionality to this service such that it needs to interact with the desktop - specifically I would like it to manipulate the system tray.
Now I believe that system tray manipulation needs a handle to a window but my problem is because the MAPI stuff requires no desktop I don't know how I can grab one. I had tried to enumerate child windows until I found the one I wanted but of course because there is no desktop that call returns no windows.
So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar....
Much thanks for your thoughts,
Richard Ellis.
|
|
|
|
|
Use GetDesktopWindow(). If it returns NULL, it means the desktop is not up yet. Once you have the desktop up, you can do all the tray adding stuff.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Call RegisterWindowMessage(_T("TaskbarCreated")) . That message is broadcast by the shell when the taskbard is created. Use that to tell when you can add your tray icon. (Requires shell 4.71+, however)
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Richard Ellis wrote:
So I was wondering whether anyone had a good idea as to how best to get around this? Is it possible to have the service start another exe/process/thread to do the manipulation which would have access to the desktop but not place a button on the task bar....
Usually when there is need for GUI presence in any non-gui service/driver, the safest solution is just another service which starts after the non-gui one (set dependency in the registry) and use IPC (LPC, pipes, etc.)
cheers
Andreas
|
|
|
|
|
Thankyou very much Gentlemen for your replies.
That was enough to get me searching for a few things I had not thought of. I ended up coming across an article in MSDN that showed me how to create a process from with a NT Service. It seems to work well. FYI my code is below
STARTUPINFO si;
PROCESS_INFORMATION ProcessInformation;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpTitle = NULL;
si.lpDesktop = "WinSta0\\Default";
si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
if (CreateProcess(NULL, "some exe name", NULL, NULL, FALSE, 0, NULL, NULL, &si, &ProcessInformation))
{
LogText(" process created");
CloseHandle(ProcessInformation.hProcess);
CloseHandle(ProcessInformation.hThread);
} else {
LogText("CreateProcess failed. Error %d\n", GetLastError());
}
Richard Ellis.
|
|
|
|
|
when one MDI view(1) is closed, what happens to another MDI View(2), what message the MDI View(2) will recevie?
one is the other who absorbs the thoughts of others
|
|
|
|
|
WM_MDIACTIVATE is sent for both of the windows. The parameters will indicate which window is losing focus and which window is gaining focus.
|
|
|
|
|
any other chinese programmer in USA ?
|
|
|
|
|
No there isn't...sorry
US Gov't only allows one chinese programmer per country, except China of course
Just teasing...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
rose:
i am chinese in P.R.China(Tang Dynasty) :
one is the other who absorbs the thoughts of others
|
|
|
|
|
if there is two mdi child windows, one is closed, which message need to be handled to show the caret on the other mdi window? even i don't know how to
process the OnActivateView method.
one is the other who absorbs the thoughts of others
|
|
|
|
|
Hi,
I've got an app with a CListView member in it, and I'nm trying to figure out how to get it to go into "report mode", with say 2 or 3 columns.
I get the underlying list control with GetListCtrl. Then I tried Setting the style, but this seems to have no effect. Am I doing something wrong here?
pListView = (CListView*)m_wndChildSplitter.GetPane(0,1);
CListCtrl& right = pListView->GetListCtrl();
// Turn on the report bit
DWORD dwExStyle = right.GetExtendedStyle();
dwExStyle |= LVS_REPORT;
right.SetExtendedStyle(dwExStyle);
right.InsertColumn(0, "COL1");
right.InsertColumn(1, "COL2");
right.InsertItem(0, "Right", 0);
Thanks
|
|
|
|
|
LVS_REPORT is not an extended style, it's a... not-extended style! You might want to try:
right.ModifyStyle(LVS_LIST | LVS_ICON | LVS_SMALLICON, LVS_REPORT, 0);
Haven't tried it, but hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Thanks!
|
|
|
|
|
You can do it a bit shorter:
right.ModifyStyle(LVS_TYPEMASK, LVS_REPORT, 0);
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
S 000-00-0001 C 20
B 000-00-0001 C 20
B 000-00-0002 CD 10
B 000-00-0002 JDSU 50
S 000-00-0002 CD 5
B 000-00-0010 TXN 30
B 000-00-0010 TYC 20
B 000-00-0009 WCOM 20
S 000-00-0009 WCOM 10
now i need to read the first letter of this input and test what is!
and based on that i need to take certain actions
here is what i have done but i'm not sure it is the right way
doesn't look like it's working!
Thanks
|
|
|
|
|
char ch;
do
{ cin>> ch;
switch (ch)
{
case 'C':
{
cin>>tempST>>tempIV;
tempStock->setStockTicker(tempST);
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
(*tempStock) = tempStocks->getStock(mid);
tempStock->setcurStockPrice(tempIV);
if (strcmp(tempStock->getStockTicker(),inputLine ) < 0)
low = mid + 1;
else if (strcmp(tempStock->getStockTicker(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
}break;
case 'B':
{
count = 0;
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempAccount;
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
Investor tempInvestor = (*tempInvestors).getInvestor(mid);
tempAccount = tempInvestor.getAccountBalance();
if (strcmp(tempInvestor.getSocialSecurity(),inputLine ) < 0)
low = mid + 1;
else if (strcmp(tempInvestor.getSocialSecurity(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
char tempTicker[30];
strcpy(tempTicker,inputLine);
int lo =0, mi, hi=14;
int tempStockPrice;
while (lo <= hi)
{
mi = (lo + hi)/2;
*tempStock = (*tempStocks).getStock(mi);
tempStockPrice = (*tempStock).getCurStockPrice();
if (strcmp((*tempStock).getStockTicker(),inputLine ) < 0)
lo = mi + 1;
else if (strcmp((*tempStock).getStockTicker(),inputLine ) > 0)
hi = mi - 1;
else
mi = mi;
}
while((c = cin.get()) != '\n ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempNumShares = atoi (inputLine);
if ( tempAccount >= (tempStockPrice * tempNumShares))
{
(*tempTickerShare).setNumOfShares(tempNumShares);
(*tempTickerShare).setTickerSymbol(tempTicker);
(*tempInvestor).addTickerShare(tempTickerShare);
}
}break;
case 'S':
{
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int low =0, mid, high=14;
while (low <= high)
{
mid = (low + high)/2;
Investor tempInvestor = (*tempInvestors).getInvestor(mid);
if (strcmp((tempInvestor).getSocialSecurity(),inputLine ) < 0)
low = mid + 1;
else if (strcmp((tempInvestor).getSocialSecurity(),inputLine ) > 0)
high= mid - 1;
else
mid = mid;
}
while((c = cin.get()) != ' ')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
char tempTicker[30];
strcpy(tempTicker,inputLine);
int lo =0, mi, hi=14;
while (lo <= hi)
{
mi = (lo + hi)/2;
tempTickerShare = (*tempInvestor).getTickerShare(mi);
strcpy (tempTicker , (*tempTickerShare).getTickerSymbol());
if (strcmp(tempTicker,inputLine ) < 0)
lo = mi + 1;
else if (strcmp(tempTicker,inputLine ) > 0)
hi = mi - 1;
else
mi = mi;
}
while((c = cin.get()) != '\n')
{
inputLine[count] = c;
count++;
}
inputLine[count] = '\0';
count = 0;
int tempNumShares = atoi (inputLine);
if (tempNumShares <= (*tempTickerShare).getNumOfShares())
{
tempNumShares = (*tempTickerShare).getNumOfShares() - tempNumShares;
(*tempTickerShare).setNumOfShares(tempNumShares);
}
else
cout<< "Sorry don't have enough shares to sell"<<endl;
="" }break;
="" }
="" }
="" while="" (!cin.eof());
<\pre="">
|
|
|
|
|
Do you use the debugger to find out where the function fails?
With VC6 edit and continue functionality, it should be easy enough for you to step through the code and find out where the code is failing.
If you need help debugging let me know.
|
|
|
|
|
no i really don't know how to use the debugger!
this is my first time programming in C++ and I am using visual C++
and DEV-C++ to compile and run my program.
well if you want to tell me how you debug i'm ready to learn>
appreciate your help
|
|
|
|
|
Use F9 to set what's called a break point - you'll see a black dot appear by the line of code. Hit F5 to start debugging - the code will run to a breakpoint, and then stop. You can hit F10 to exectue a line of code at a time, and you also get a variable watch window, into which you can type variable names to see how their values change as each line is executed.
Make sure you're in debug mode You set that by clicking on Build | Set Active Configuration.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I would just like to add a little more detail to what Christian G (CG). said.
I assume that you are running your programs right now by clicking the icon with the !. This simply runs the app. like CG said, run your application by hitting the F5 key instead. You could also go to the Build menu, and select Start Debug. There are a lot of other useful commands on this menu.
When you know that you have a trouble area in your program, go to the line of code where you think that the problem is starting and hit the F9 key. Like CG said, this will set a breakpoint. A the program will halt its execution when it reaches this point.
At this point you can move your cursor over any variable to see what values they hold. There are a number of windows that you will want to open from the debug menu in order to get important information from the debugger.
The watch window will allow you to type in any of the variables that are in the current scope, or function, and you can see the values that they hold. If you have a class or a struct this is a really nice window because you can view all of the data member values of the object.
You can change the value of a variable in the right hand side of the watch window. This is very useful if you want to change the or set the value of a variable while debugging, with out writing code, or if you want to see how this new value will affect code execution.
The variables window will show all of the variables that are currently being used on the current line. Just like the watch window, you can change the value of the variables in the right hand side of the window.
You probably will not have to worry about the registers window for right now unless you learn more about x86 assembly. However the EAX register is the register where return values are always sent. So if you call an API function, but do not store the return value with a variable in your program, you can check this register.
The memory window is good for checking the memory at a particular address. So if you have a pointer and you want to see what memory it points to, type in the variable name in the address section, and dereference it ex. *lpString .
The call stack window is helpful to see what function calls have led upto the current function. You can also click on one of the previous lines in the call stack window to set the current debug context to one of those other functions. This will allow you to check variable values in a different function call that is on the stack. Some times you can uncover problems that happened in a previous function that caused problems later on.
Just like the registers window, you will not have to worry about the disassembly window until you learn more about x86 assembly.
A few more tips:
You can step to the next line of code with F10.
You can skip over a function call with F11.
If you want to stop execution of a program that is currently being debugged, hold Shift + F5.
You can set the current execution point by setting the caret to the line that you want to execute from and right click to get the context menu and select "Set Next Execution Point". This is very useful when you execute a statement with a wrong value and then you want to change the value in the watch window and re-execute a piece of code. Or if you want to skip over an entire section of code.
The most important thing of all, say you have a breakpoint set. The execution of your program has halted at that breakpoint, and you step through your program with F10. You finally find the problem, you can directly edit you code, make the one line fix or what ever the simple problem may be, hit F10, and Dev Studio will has if you want to edit and continue. If you choose yes, it will recompile your code, and you can continue executing the program from the same point without restarting the program. This works in most cases, but the compiler cannot recover after all of the changes that you make. SO you will want to limit this feature to small changes in your program.
I know there is alot of information here, and it may take you some time to get comfortable with all of the things that I have explained here, however these are the bare essentials to debugging in Dev Studio, and I stringly suggest you learn and use every one of these features. It will help you find problems quicker and you will learn your code faster as well.
I know there are a few other things that I left out so if anyone thinks that I left out anything important please add to this.
|
|
|
|
|
just wanted to say thank you before i go to sleep
|
|
|
|
|