|
You can get the compiler version with _MSC_VER. Look into the online help for the possible values.
However from your example I guess that you really want to use _MFC_VER which gives you the MFC version (>= 0x0700 for MFC 7 or higher).
Oliver
|
|
|
|
|
Thank you very much, Oliver. I will use the online-help to figure out the rest.
Best regards
tabor25
|
|
|
|
|
Hi,
can anyone help me with this prob ??? I am at a total lost
I have several pointers (using them as matrix) and i have always allocate mem to them using the "new" operator. However i encounter a strange problem with one of them (temp). Whenever my program trys to access the pointer 'temp' up to a location, it would generate an "First-chance exception: 0xC00000005: Access violation" error.
an eg of the code is like this:
double * temp
temp = new double (5000);
for (i = 0; i < 5000; i ++)
{
temp[i] = x*y;
}
I use breakpoints and see that the index of temp from 1 to 2577 is valid. However when i > 2578 all the values are invalid ("CXX0030: Error: expression cannot be evaluated") and hence causing my program to hit the ""First-chance exception: 0xC00000005: Access violation" error. This seems so strange to me and i am at a lost of what to do......
Can anyone tell me why is it so ?? and how can i solve this problem??
Thank you very much for your kind attention !!
|
|
|
|
|
Must be:
temp = new double [ 5000] ;
rechi
|
|
|
|
|
Hi rechi,
Really thanx a lot ... I guess i made a silly typo without realizing !! You save my day
bk
|
|
|
|
|
Hello everybody,
My task is to interrupt a job (click on a button) that takes a lot of time for execution (a kind of endless loop). This code is in a DLL.
I tried different methods without success.
If the code is executed in the same thread, I can solve this problem with the ::PeekMessage() function.
Is the DLL executed in a different thread?
Can you help me?
Thanks,
Gelu
|
|
|
|
|
In principle, DLL code is executed in the same thread as the EXE that invokes it, unless the DLL launches a secoondary thread on purpose.
Anyway, I'm curious about how you plan to terminate the llop using PeekMessage . Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Obviously, when I work in a executable my code seems like this:
fct()
{
.... init loop ...
MSG msg;
while(!(::PeekMessage(&msg, GetDlgItem(IDC_STOP)->m_hWnd, 0, 0, PM_NOREMOVE))
{
...... do a step ...
}
}
where IDC_STOP is a button.
If I put the same code in a DLL
fct()
{
.... init loop ...
MSG msg;
while(!(::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
...... do a step ...
}
}
The GUI freezes and I have to use the task manager to kill the task
Thanks,
Gelu
|
|
|
|
|
Hi,
First create a new thread for your endless loop function. Then the first line of the thread execute the following
[code]
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE)
[/code]
This will force the OS to create a non windowed message loop. Inside your loop you can the use PeekMessage or GetMessage to receive messages for that thread. Obviously the hWnd member of the MSG struct will contain NULL because is has no window.
To post a message to the thread message loop use PostThreadMessage. This will fail if you haven't created the message loop at the start of the thread
Hope this helps
Ceri
|
|
|
|
|
Hi Ceri,
My experience on creating threads in Windows system is very limited. Can you recommend me some code?
Thanks,
Gelu
|
|
|
|
|
Try this
[code]
#include "stdafx.h"
#define CUSTOMSTOPMSG WM_USER + 1
DWORD WINAPI ThreadProc(LPVOID lpParameter);
void StartThread();
void StopThread();
//the thread ID. Must give this ID to PostThreadMessage
DWORD dwThreadID = 0;
//this function is the thread function - contains the infine loop
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
MSG msg;
int iRetVal = 1;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); //forces creation of non windowed message loop
while(!(PeekMessage(&msg, NULL, CUSTOMSTOPMSG, CUSTOMSTOPMSG, PM_REMOVE)))
{
//....do processing here
};
//.... do clean up here
return(iRetVal);
}
//execute this function from your standard thread
void StartThread()
{
HANDLE hThread;
//you can use this to pass a parameter to your thread
//(usualy a pointer to a struct or some other kind of user data)
LPVOID pParam = NULL;
hThread = CreateThread(NULL,0,ThreadProc,pParam,0,&dwThreadID);
}
void StopThread()
{
//obviously wParam and lParam in the PostThreadMessage could be some value also
if(dwThreadID)
PostThreadMessage(dwThreadID,CUSTOMSTOPMSG,0,0);
}
[/code]
Call StartThread when you want to initialize the loop and StopThred when you want to stop (I guess you would use your button for this)
Let me know how you get on
|
|
|
|
|
Many thanks Ceri. It works perfectly.
Gelu
|
|
|
|
|
|
I'd like to create a control (a ComboBox) and position it at the bottom of a window. Thus I need to know the height of this control before I create it.
If I just measure it on this PC and code it as a const, then it will look ugly if someone has a bigger font or s.th else is changed.
Is there any way to get the standard size of such a control without creating it first ? (s.th. like GetSystemMetrics for controls)
|
|
|
|
|
I couldn't find any function equivalent to GetSystemMetrics for combo boxes, but I would try this technique:
1. Create a temporary combo box without the WS_VISIBLE flag, so that it's invisible.
2. Retrieve its height. GetWindowRect should do it.
3. Destroy it.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
Works just like it should
thank you.
|
|
|
|
|
Hi all,
I stumbled upon an interesting character in a csv file created by Excel. the character's decimal representation is -96 and hex is FFFFFFA0. Does anybone know from which character set this one jumped out?
Thanks in advance.
Alberto Gattegno
Software Engineer
http://www.itgil.com
|
|
|
|
|
Could it be á, i.e 0xA0 or 0xFF - 0xA0, 0c5F '_'
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Hi
I've always read that with every "new" there shld be a "delete" and likewise with "malloc" and "free", otherwise it'll lead to memory leak.However when the application is terminated, will this resources be freed?
Once, i've created an object with "new" in a loop and was unable to delete the object outside the loop.Anyone knows why?
thks!
|
|
|
|
|
raner wrote:
However when the application is terminated, will this resources be freed?
Yes. In debug mode, the IDE shows nasty comments about the leaks, but thats it.
So, if your app starts, runs a second, leaking a few KB of memory and terminates, no harm is done.
But if you imagine MS-Word would leak one byte per keystroke, you see how this would lead to trouble.
Basically, dont leak at all! It is not that hard to acomplish if you are careful:
Drop char* in favor of std::string or CString, drop dynamic C-arrays in vavor of std::vector etc.
Those pointers that you need are initialised at creation, checked against NULL before use and set to NULL after the delete.
raner wrote:
Once, i've created an object with "new" in a loop and was unable to delete the object outside the loop.Anyone knows why?
You threw away the pointer to this object, eg. overwriting it in the next loop iteration?
Remember: My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
jhwurmbach wrote:
Drop char* in favor of std::string or CString, drop dynamic C-arrays in vavor of std::vector etc.
By std::vector, are u referring to STL?..Sorry i'm not very familiar with VC yet.
For the use of "new" in the loop, yes, i reassigned the pointer to consecutive elements in an array at each iteration.Do i not need to delete the pointer then?
thks alot!
|
|
|
|
|
Yes std:: is the namespace where the STL resides.
Read the tutorials here at CP, and you will understand how it works, and soon be a follower of the GREAT STL *manic laugh*
As to the loop, you said you could not delete memory you new ed in a loop.
If you have overwritten the pointer to this memory (being your only access) in the next iteration, you can not delete it: A delete on your pointer deletes only the last new ed memory.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
ok..i see the point now.
But can i confirm that the following statements should be fine?
int* pi = 0;
for(int i = 0; i < 100;++i)
{
pi = new int;
//I'll store pointer pi of each iterationin some kind of array, so it can be retrieved later
}
delete pi;
|
|
|
|
|
raner wrote:
But can i confirm that the following statements should be fine?
[..example deleted..]
No! You have 100 'new int ' instructions (in the loop), but only one delete (after the loop). You are leaking 99 int s.
This one works:
#include < iostream >
#define num 100
int main(int argc, char* argv[])
{
typedef int* intPtr;
intPtr* pI = new intPtr[num];
for(int i = 0; i < num; ++i)
{
pI[i] = new int;
*pI[i] = i*i;
}
for( i = 0; i < num; ++i)
std::cout << "i: " << i << " i quadrat: " << *pI[i] << std::endl;
for(i = 0; i < num; ++i)
{
delete pI[i];
}
delete[] pI;
return 0;
}
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
i think i get it...thks alot!
|
|
|
|