|
Why do you try to get a pointer to your own class?
Try this code:
GetWindowRect(&rc);
rc.right -= 100;
ScreenToClient(&rc);
MoveWindow(&rc);
|
|
|
|
|
Hi
I have some questions regarding C++ basic types:
1. Is DWORD the same as unsigned long?
2. What's the difference between BOOL in VC++ and bool in C++? It seems that they're functionally identical, so why the redundancy?
Thanks!
|
|
|
|
|
DWORD I'm not shure. (I think it's 32bit data which can be interpreted as something else then a integer)
BOOL: 0,1 or 2,3,4,... (TRUE is defined as 1 and FALSE as 0)
bool: true or false, this cannot be a number, but is a boolean, a BOOL can be an integer value.
hope it helps.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
typedef unsigned long ULONG
typedef ULONG DWORD
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Indrawati wrote:
2. What's the difference between BOOL in VC++ and bool in C++? It seems that they're functionally identical, so why the redundancy?
VC++ creates a layer between native types and data types used in the VC++, BOOL is same as bool in windows, may be it will be different in the future release of VC++ or depending on the platform.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Mr.Prakash wrote:
BOOL is same as bool in windows
How so? One is 4 bytes while the other is 1 byte.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
bool is a C++ native type for boolean values whereas BOOL is merely a typedef for int
since C/ C++ treat int values as boolean. The benefit could be in performance etc. for e.g. if
you try to assign int to a bool you get this warning:
Compiler Warning (level 3) C4800
'type' : forcing value to bool 'true' or 'false' (performance warning)
DWORD etc are portable datatypes defined in Windows SDK. You can find a part of
the list in MSDN Library help.
BOOL A Boolean value.
BSTR A 32-bit character pointer.
BYTE An 8-bit integer that is not signed.
COLORREF A 32-bit value used as a color value.
DWORD A 32-bit unsigned integer or the address of a segment and its associated offset.
LONG A 32-bit signed integer.
LPARAM A 32-bit value passed as a parameter to a window procedure or callback function.
LPCSTR A 32-bit pointer to a constant character string.
LPSTR A 32-bit pointer to a character string.
LPCTSTR A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.
LPTSTR A 32-bit pointer to a character string that is portable for Unicode and DBCS.
LPVOID A 32-bit pointer to an unspecified type.
LRESULT A 32-bit value returned from a window procedure or callback function.
UINT A 16-bit unsigned integer on Windows versions 3.0 and 3.1; a 32-bit unsigned integer on Win32.
WNDPROC A 32-bit pointer to a window procedure.
WORD A 16-bit unsigned integer.
WPARAM A value passed as a parameter to a window procedure or callback function: 16 bits on Windows versions 3.0 and 3.1; 32 bits on Win32.
Due Regards
Mahendra
|
|
|
|
|
Indrawati wrote:
2. What's the difference between BOOL in VC++ and bool in C++? It seems that they're functionally identical, so why the redundancy?
A tidbit from MSDN:
In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 5.0 and later, sizeof(bool) yields 1.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi all
I recently got a 3.4GHz P4 with HyperThreading (HT). I am getting weird things happening with my threads in my Visual Studio 6 C++ app. I have found that my mutexes are often ignored. This means that the data that the mutexes are protecting becomes invalid causing a GPF.
Example files:
class CBob
{
...
void Func();
CStringList m_listFiles;
CMutex m_mutex;
...
};
void CBob::DisplayFiles()
{
CSingleLock sLock(&m_mutex);
if (sLock.Lock(9000))
{
for (POSITION pos = m_listFiles.GetStartPosition(); pos; )
{
CString strFile = m_listFiles.GetNext(pos);
TRACE(strFile + "\n");
}
sLock.Unlock();
}
else
{
ASSERT(FALSE); //Mutex timeout
}
}
This only happens when I am running in Debug mode with HT enabled. Release mode does not crash even with HT enabled.
Has anyone got any ideas about why enabling hyperthreading causes the mutex to be ignored?
Cheers
Tha d3m0n
|
|
|
|
|
If there are multiple instances of CBob then the mutex must be declared static so the same instance is used by all instances of CBob. Are there multiple instances of CBob?
Also you should be able to use a critical section instead of a mutex, but that is an aside.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
There is only ever one instance of CBob.
I have looked everywhere I can think of for someone with a similar query but I haven't had any luck.
Do you think CriticalSection would be any more robust than CMutex?
|
|
|
|
|
[d3m0n] wrote:
There is only ever one instance of CBob.
I have looked everywhere I can think of for someone with a similar query but I haven't had any luck.
Do you think CriticalSection would be any more robust than CMutex?
How do you know the mutex is causing this problem? If there is only ever one instance of CBob then I suspect something else wrong.
A Mutex and CS should give the same results, however a CS is faster. Mutex's are typically used where you need to protect something across multiple processes, which you aren't doing from what I see.
I am aware of multi-threading problems which show up on multiple cpu pc's that don't show on single cpu machines.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
"How do you know the mutex is causing this problem?"
I know this because the program crashes in the for loop which iterates through every file in the list. If at that point I look at the value of the list, it is full of garbage.
As the only place which modifies the list is on a separate thread, which is also protected by the same mutex, I cannot figure out why the HT-enabled version is allowing the list to be changed whilst it is being looped through.
|
|
|
|
|
I want to try to use the vectorization to improve the performances of my programs, but I don't have too much information about how to use the libraries. Do you know what are the libraries (if there is any) I need to include to be able to use the types like 'vector int' or whatever? If there is not do I have to use intrinsics or there is another way?
thanks
Pierre
|
|
|
|
|
You should:
#include <vector>
and initialization of a vector of ints look like this:
std::vector<int> vInt;
or
std::vector<int> vInt(numElements, initialValue);
For other data types, just replace <int> with <name_of_data_type>
|
|
|
|
|
Note if you want to improve performance consider this.
If you are removing entries within the vector frequently then this is a "slow" process. It calls copy constructors for all entries above the deleted item as it shuffles them down.
Consider using list instead in these cases.
i.e.
#include <list><br />
<br />
typedef std::list<int> TIntList;<br />
<br />
TIntList m_MyIntList;
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
How can I call a function, given its name as a string?
|
|
|
|
|
In a map push the pointer to your function and its name as a string
and when you need to call the function just query for its pointer and pass the correct parameters.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I have created my project ... with VC++ + DirectShow. + MS Access..
I need to build installer for my application that can i give to my users .. to intall the application on their PC..
How can i do it ,, any Software ,, etc..
i thikn there r some scrpts with which we do ir ..
But i not have experince on these .. how can i easily build my installer
thanx
|
|
|
|
|
Try out Microsoft Visual Studio Installer
It is easy to use
and really cool.
|
|
|
|
|
Hello,
Can anyone please tell me, why "c" doesn't support nested functions
|
|
|
|
|
Do you mean the bizarre Pascal construct where you can have a function inside a function?
That is:
void func1() {
void func2(){
}
}
If that is the case, the answer is simply "because it doesn't". And a good thing it is too, support nightmare and everything It is completely unnecessary, tools converting Pascal code to C do this by creating a struct of the local variables in func1, making func2 a separate function and having the struct as an inparam to func2, if you need to convert code.
|
|
|
|
|
As has already been mentioned, there is no need. What is it that you are doing that you think requires such a construct?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
i am doing project on vc++ MFC DIALOG, where in i will be repeatedly calling the same dialog box morethan 100 times, but the problem is, that the dialog box is getting crashed(terminating or ending) after some 50 times..
what can be the problem?
|
|
|
|
|
jklhjk wrote:
what can be the problem?
Probably that you have a bug in your program. As you don't describe anything about what the dialog does, it's difficult to be more specific
Have you tried running it in debug mode, you ought to get some more info on the reason this way?
|
|
|
|