|
If the thread doesn't do UI I'd definitely use a worker thread. Then use PostMessage() to communicate with the main app thread. If you can add a flag param to the common code functions that do the message pump that says whether to pump or not you can set this to false for your thread. Alternatively use this:
BOOL
InAppThread()
{
return ( AfxGetApp() eq AfxGetThread() );
}
and then:
if ( InAppThread() )
do message pump ..
Also look at http://www.codeproject.com/threads/threadlibrary.asp[^] which is very nice and also simple.
Threads are way better and cleaner for CPU intensive tasks than trying to do this in message pumps. Of course you have to consider sychronization and potential deadlock issues as well. Welcome to the world of multithreading.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
That little code snippet will be perfect for getting around those message loops for now, but I'll be pushing for doing this all in threads, and the link you provided looks like it may be about perfect for that.
Thanks!
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
I'm glad I was able to be of help. There is an article here at CP by Newcomer about Worker Threads which you should read. Make sure you don't use SendMessage from thread, instead always use PostMessage(). All to do with deadlocks.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I have a little question. What happens exactly in these several case:
case 1:
int* pVar = new int;<br />
void* pPointer = pVar;<br />
delete pPointer;
case 2:
char* szString = new char[Value];<br />
void* pPointer = szString;<br />
delete pPointer;
case 3: (the most interesting)
CMyClass* pClass = new CMyClass;<br />
void* pPointer = pClass;<br />
delete pPointer;
Of course, the question is how will the compiler handle the destruction of the different objects ?? In the third case, does he 'know' that it will need to call the destructor of CMyClass ?
|
|
|
|
|
The rule is simple. Calling delete on a void pointer frees the memory pointed to by the pointer (regardless of what type it is), but never calls any destructors.
Note that the actual object type pointed to makes no difference. The runtime library keeps track of the size and base address of each memory block allocated, and uses these to free the memory properly. It doesn't care what the memory contents is or what type of object it points to.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ok, thanks. It's clear now .
So this is safe to use such a technique with basic types (not arrays) but not safe with classes...
|
|
|
|
|
cedric moonen wrote:
So this is safe to use such a technique with basic types (not arrays) but not safe with classes...
Well, I certainly wouldn't call it 'safe'. It violates the rules of type-safe programming and is IMO a very, very bad design. If you have any other way of doing things, do it.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
how can I get current language which the window user is using? Can I also query the list of languages that are selected in IE (e.g. english first, next german if first not availble)?
Thanks
|
|
|
|
|
Chech out GetKeyboardLayout Function
How to detect when this change happen use WM_INPUTLANGCHANGE message
Ivan Cachicatari
www.latindevelopers.com
|
|
|
|
|
Would any of the following help:
GetLocaleInfo()
GetACP()
GetUserDefaultLangID()
GetUserDefaultUILanguage()
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks, I will have a look at these.
Anonymous
|
|
|
|
|
I have downloaded a example for VMR9,when compiling the project,error shows:
error LNK2001: unresolved external symbol _IID_IVMRWindowlessControl
it means this project should include some .lib,what is it?
thanks a lot
|
|
|
|
|
How can I push out my app to the rest of the user in the LAN? So they can run my app.
|
|
|
|
|
hi, in correspodace to my graduation project i need a progarm that converts monochrome bitmaps to a 2-D array ... i would be glad if u could help me .
your's faithfully
|
|
|
|
|
Hi,
Normally bitmaps are stored in 1D arrays.
For exemple you have 640x480 bitmap, the way to get to a pixel would be like this:
<br />
char bitmap[640 * 480];<br />
<br />
bitmap[x+(480*y)] = value;<br />
If you want to convert the exemple above to a 2D array, you can do the following:
<br />
char bitmap[640*480];<br />
char bitmap2D[640][480];<br />
<br />
for( int y = 0; x < 480; y++ )<br />
for( int x = 0; x < 640; x++ )<br />
bitmap2D[y][x] = bitmap[x + 480 * y];<br />
Hope this helps..
|
|
|
|
|
I have a written a header file in the same directory as the .net project. compile time it says cannot find the header file, 'no such file or directory'. I has been added to the headers directory in the project. What have I not done, or whats wrong. Please help.
|
|
|
|
|
Go to the line where you include your header file an check the spelling of the file / class and the problem should be solved
Pascal
|
|
|
|
|
And your question is?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I thought I had this problem solved, but I seem to have hit a problem with a 4 bit field on a byte boundary.
Can anyone suggest a solution to an extra byte being added to the structute. I need everything packed tight.
#pragma pack(1)<br />
<br />
typedef struct{<br />
char tc1_w01_month_1_s_ : 4;<br />
char tc1_w01_month_10_s_ : 4;<br />
char tc1_w01_day_1_s_ : 4;<br />
char tc1_w01_day_10_s_ : 4;
char tc1_w02_reserved1 : 1;<br />
char tc1_w02_reserved2 : 1;<br />
char tc1_w02_minute_1_s_ : 4;<br />
char tc1_w02_minute_10_s_ : 4; <big>
char tc1_w02_hour_1_s_ : 4;<br />
char tc1_w02_hour_10_s_ : 2;<br />
char tc1_w03_second_0_01_s_ : 4;<br />
char tc1_w03_second_0_1_s_ : 4;<br />
char tc1_w03_second_1_s_ : 4;<br />
char tc1_w03_second_10_s_ : 4;<br />
}TEST_10_tc1;<br />
<br />
#pragma pack()
|
|
|
|
|
Use int rather than char for the first 32 bits (all except the last 4 fields), and short rather than char for the rest.
It's a good idea to use the largest possible data type size when using bitfields (ie. favour ints /longs ). If you need to prevent padding at the end, then by all means use the smaller data types (ie. short /char ).
Also, be careful about using signed values in bitfields. Generally, it's a good idea to use unsigned values (eg. unsigned int ) because then you can guarantee how the compiler will treat it. If the values are signed, then you have to know whether the compiler sign-extends or zero-extends the value when you're using it in an expression.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
i am using ADO Connection Strings from this page to connect to an access database. unfortunalty they just contain parameters for userID and user password
e.g.:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};"
"Dbq=C:\\VC Projects\\ADO\\Samples\\AdoTest\\dbTestSecurity.mdb;"
"SystemDB=C:\\Program Files\\Microsoft Office\\Office\\SYSTEM.mdw;"
"Uid=Carlos Antollini;Pwd=carlos");
the problem is that the database which i want to connect to is protected with a database password .
is there an other attitional connection string which has the database password as parameter?
thx Bernhard
|
|
|
|
|
By default, user id of an access database is "Admin", hence to open a password protected database, use:
"UID=Admin; PWD=your-password"
Arsalan Malik
|
|
|
|
|
hmmm if i try like this:
CString strConnection = _T("Driver={Microsoft Access Driver (*.mdb)} Dbq=c:\\exchange-b\\ApplicationDatabase.mdb; Uid=Admin; Pwd=myPass;");
m_DB.SetConnectionString(strConnection);
the programm still cant open (m_DB.Open()) the database. are you sure there is no difference between database base password and user password?
if i set a database password and a user password and then i try to open the database from the win explorer, ms access asks me for both passwords ...
so i think i need a connection string which contains the databasepassword
|
|
|
|
|
You'll have to include the database password like so: "Jet OLEDB:Database Password=MyDbPassword;"
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
thanks! that is what i was looking for
|
|
|
|