|
How can I write Outlook addin which support all versions of Outlook?
|
|
|
|
|
|
i can lock a thread, but how about single function?
int Func(int par)
just want to lock it so other function do not call it until it finish, is that possible?
|
|
|
|
|
What do you mean by "lock a function"? By definition you can only lock it if it is running in a separate thread.
Veni, vidi, abiit domum
|
|
|
|
|
|
If you want something inside the function protected from parallel/recursive calls, you can do that by placing a criitical section and a class member variable inside it. If don't want the function to be called at all, you could make it private and add a public function as the only one that calls it. It could look something like that:
void somePublicFunc()
{
EnterCriticalSection(); try
{
if (!alreadyRunning) {
alreadyRunning = true;
privateFunction();
alreadyRunning = false;
}
}
catch (...)
{
alreadyRunning = false; LeaveCriticalSection(); throw; }
LeaveCriticalSection();
}
So privateFunction() will only be called once at a time no matter from which thread (provided you don't add another member function that calls it or introduce any friend classes).
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Not bad but in C++ you should use RAII for this, use the destructor of an auto (stack) object as your finally block.
class CAutoLock
{
public:
CAutoLock(CRITICAL_SECTION& cs)
: m_CS(cs)
{
EnterCriticalSection(&cs);
}
~CAutoLock()
{
LeaveCriticalSection(&m_CS);
}
private:
CRITICAL_SECTION& m_CS;
};
void func()
{
CAutoLock auto_lock(cs);
{
CAutoLock auto_lock2(cs2);
}
}
|
|
|
|
|
Parameter names are commented out in the method signature, as in:
void OnUpdate(CView* , LPARAM , CObject* )
I know that optional parameters would be given as:
void OnUpdate(CView* pSender = 0, LPARAM lHint = 0, CObject* pHint = 0)
So what does the first one mean?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It means that you're not using them. You can still read the parameter names in the comments, but the compiler won't issue any warnings about unreferenced parameters.
|
|
|
|
|
Oh! Thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi all,
I released an article over the weekend (Don't mess up your #defines[^]).
I received a negetive feedback from a guy from germany:
Quote: For one, this article promotes 80's #define's as if they're still a valuable solution (hint: a global const variable can do the same and is always the better option).
Also the later suggestion is not only obvious (use member variables, duh!), but actually needlessly complicates things: you can name structs just like classes without typedef's, and if you really need a global structure for these things, use templates! How can code with #define's and typedef's be called "Optimized for C++11", when it looks more like C72?
Now I am wondering: Is the article that bad? Is he mentioning valid points ( I got him with the "use templates", but I am still not sure whether I can trust him or not - After all, his profile says "Web developer").
Since I want to provide quality articles to the community I'd also want a feedback on what I could improve with the article to make it more valuable and up-to-date.
Thanks for any help
- PP
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
I've just taken a quick look at your article but I agree with the guy. To me it seems that you are a C programmer who is quite new in C++. Defines should be avoided whenever possible. In a lot of cases defines can be replaced with template/inline functions. In some other cases long macros can be replaced to a combination of a short macro + template/inline functions/classes. Macros don't respect name spaces and they arent type safe. Still, some small stupid problems can be solved practically only with macros (for example automatically logging out filename/linenumber/functionname can be done only with a logger macro). But even when you are using a macro its better to keep the body of the macro short by immediately calling a function or intantiating/using a class. Using typedef on structs in C++ is awkward and using header guards is also deprecated in my opinion, in a large project you got a very strange error message with a duplicate (for example copy-pasted) header guard and today all major compilers support "#pragma once".
|
|
|
|
|
This is really not the place for this type of message. Your article showed up in the latest Newsletter, so those who are interested will go and look at it.
Veni, vidi, abiit domum
|
|
|
|
|
I had not come across the word psychopomp before, until you started posting in the forums recently. And last night I saw it a second time while reading a short story; strange coincidence.
Veni, vidi, abiit domum
|
|
|
|
|
Yes and no. Considering how often he changes his name, something like that had to happen sooner or later.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
I came across it not long ago[^], it was the solution for the CCC.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
He's definitely right in that the style of code you provided is not in any way a good example of nodern, object-oriented code. Defining a struct that contains nothing but two constants is not a sensible design. Definitely not from an object-oriented view, and not even in for modular, old style C programming. For the former you'd define a boundary object singleton with methods that you could call rather than exposing the actual constants, for the latter there's no good reason not to simply use a number of individual constants - but you could also just define a function to validate the boundary range and thus hide the use of the constants inside the function implementation!
I've listed these suggestions and a few more in the other thread. (didn't even use templates - not that there wouldn't be good solutions with templates too, but there really is no need to overcomplicate things!)
Also, if you want to make a point, choose an example that is bad for non-obvious reasons. Your use of #define as a bad example totally fails to bring across the need for a const struct initialization. And to be honest, I still don't see the need in the first place, since - as outlined above - grouping the const values inside a struct was a mistake to start with.
On a sidenote, you are contradicting yourself in this article: Your reason for not using #define is that you have to recompile every time the value changes - but the same is true for every variant you bring up in the article! The only way to avoid having to recompile the code is store the values outside the code and read them at some point (which however would prevent the use of const variables...)
|
|
|
|
|
I personally feel that KISS approach is the best way.
The C language #define is THE basic way to implement MN - magic numbers.
Such MN need to be readily identifiable and should stand out.
I have an issue with things like "C++11" or whatever newfangled compiler MS comes up with where MN are covered by layers of convoluted code.
So what if MN can be implemented umpteen different ways.
Mine #define(s)are up front in StdAfx.h file. And if I need them , I do search for "define" and get the all in one swoop. Try that with global variables.
I really feel that your article is getting attention from "if it is new it must be cool" coders.
Don't worry, be happy...
Cheers Vaclav
|
|
|
|
|
'blast_vib_proc.exe': Loaded 'D:\DATA\fragmentation_model\Debug\blast_vib_proc.exe', Symbols loaded.
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msimg32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\comdlg32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\winspool.drv', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oledlg.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_72d273598668a06b\GdiPlus.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\AMInit32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
First-chance exception at 0x00743387 in blast_vib_proc.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x77cf15de in blast_vib_proc.exe: 0xC00000FD: Stack overflow.
|
|
|
|
|
Why have you posted this, all it does is confirm that your program causes a stack overflow error? You need to show the code where the error occurs, we cannot be expected to guess what your program is doing.
Veni, vidi, abiit domum
|
|
|
|
|
Go trough your program using your debugger - The debugging stops as soon as the stackoverflow happens.
In case your program stops before entering the debug mode you might want to look into this one:
http://stackoverflow.com/questions/6267837/stack-overflow-error-in-c-before-any-step[^]
If neither one helps you I kindly ask you to post the source code of your main and the classes which are initialized at first - We can't read your mind, nor your HDD.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
As soon as start program, not operate on any array yet, got error message:
Unhandled exception at 0x77c315de in blast_frag.exe: 0xC00000FD: Stack overflow.
Please help why ?
Thanks
|
|
|
|
|
mrby123 wrote: Please help why ? Because you have a bug in your code.
Veni, vidi, abiit domum
|
|
|
|
|
True.
Veni, vidi, vici.
|
|
|
|
|
Typical sources for stack overflows are declaring large objects on the stack and recursive function calls:
void some_func()
{
int large_array[500000];
CSomeLargeObject Obj;
some_func();
some_other_func();
}
Large objects on the stack should be avoided. Use dynamic memory allocation instead (new or malloc() ).
So check your code for the above conditions. To detect recursive calls, use the debugger and check the functions that are called for recursions.
|
|
|
|
|