|
static means different things when applied to a member function versus a member variable. static on a method means that the method does not receive a this pointer. There's no concept of "instances" for methods - the compiler generates the code for the method, and threads run that code whenever you call the method.
So you can have many threads calling the same method with no problems. (Of course, you have to protect any data from simultaneous access if necessary, but that's another topic altogether.)
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0.1! | RightClick-Encrypt
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
Hi Mike, and thanks for your answer, what i ment by "instances" of methods was actually a "copy" of it on memory during program execution, NE way, i know now that each thread has its own space, and there for receives its own "copy" of the function.
Thanks!
|
|
|
|
|
|
I think your confusing class instances with threads. You are correct, when you define a class function as static, there is only one copy of the function(per thread). But a thread has it's own stack. So each thread executes it's own copy of the static function. So any local variables inside the static function are multi-thread safe. But any global/static variables are not thread safe. They are shared by all threads threads.
|
|
|
|
|
Ahh! i dint know threads had its own stack, i tought they all ran in the same stack, now i understand, each thread has its own copy of the function, so there isnt "just one" copy of it.
Thanks!
|
|
|
|
|
I have an SDI app that uses an ini file to store settings. The user has the option to manually edit the ini file from my program, which is done through notepad. What I want to do is suspend execution of my program until notepad exits. I read up on createprocess() and shellexecute() along with waitforsingleobject()but couldnt figure out how to do it.
Any help would be great!
Thanks,
Daniel
|
|
|
|
|
here is some code I use to open an UDL file
and wait for the UDL Editor to exit.
BUT! Your main thread is blocked and so
the repaint is blocked!!!
<br />
SHELLEXECUTEINFO inf;<br />
memset(&inf,0,sizeof(SHELLEXECUTEINFO));<br />
inf.cbSize = sizeof(SHELLEXECUTEINFO);<br />
inf.fMask=SEE_MASK_NOCLOSEPROCESS;<br />
<br />
inf.lpVerb=_T("open");<br />
inf.lpFile=sUdlFile;<br />
<br />
if(ShellExecuteEx(&inf)) {<br />
WaitForSingleObject(inf.hProcess,-1);<br />
CloseHandle(inf.hProcess);<br />
}<br />
|
|
|
|
|
|
Original bit field: http://noisydisco.free.fr/original.jpg
Stretched bitmap: http://noisydisco.free.fr/stretched.jpg
The target bitmap init code :
BITMAPINFOHEADER bmiHeader;
ZeroMemory( &bmiHeader, sizeof(BITMAPINFOHEADER) );
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = _dwBitmapSize.X;
bmiHeader.biHeight = _dwBitmapSize.Y;
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 32;
bmiHeader.biCompression = BI_RGB;
_hDC = CreateCompatibleDC( NULL );
_hBitmap = CreateDIBSection( _hDC, (BITMAPINFO*) &bmiHeader,
DIB_RGB_COLORS, (void**) &_pBitmapBits, NULL, 0 );
_hOldBitmap = (HBITMAP) SelectObject( _hDC, _hBitmap );
And the stretch:
StretchDIBits( _hDC,
0, 0, _dwBitmapSize.X, _dwBitmapSize.Y,
0, 0, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight,
pSource, pbmi, DIB_RGB_COLORS, SRCCOPY );
Everything seems straight forward but I can't make this work.
Where is the problem ?
Thanks for your help
|
|
|
|
|
I think you should use SetStretchBltMode(HDC hDC, int nStretchMode).
Set the mode to HALFTONE before you use StretchDIBits and look if the stretched bitmap looks better. Take a look at the MSDN library for SetStretchBltMode. I think there are some limitations if you use HALFTONE mode!
|
|
|
|
|
Hello,
I would like to handle accelerators like Ctrl+Alt+R in my dialog based app, but can't find any good source for example on doing that. If somebody have noticed somewhere an article or code snippet on doing that, please let me know,
Thanks in advance!
|
|
|
|
|
this site helped me out a lot, hope it will do the same with you
http://www4.ncsu.edu:8030/~jgbishop/codetips/dialog/accelerator_keys.html
Eugi Games
|
|
|
|
|
Thanks !
|
|
|
|
|
I’m writing a kind of spy program. It’s for a good purpose – to protect kids by letting their parents know when they are up to no good. I can monitor system wide keystrokes and mouse clicks, and I can get the text from Edit/Combo boxes of other apps with no problem, but I cannot get the text that has been entered into Edit/Combo boxes on web pages in IE. It seems that these are not normal child windows. Any ideas?
|
|
|
|
|
A good education is better than a controlling spying program.
Don't you agree ?
Marcello
|
|
|
|
|
Ok, so this is starting to get really annoying. Everytime I write some code and I want to go back to it after I turn my pc off I get this error. I tried using the answer to question 2.7 in the debuging questions article and that did not work....I am really confused why this is happening and I have no idea how to fix it. It is really starting to slow me down
Can anyone help me with this?? I have gotten these errors with every MFC program I am writing! Here are the files I'm using.
main.cpp
radio.h
radio.cpp
Here is the errors.
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Radio::~Radio(void)" (??1Radio@@QAE@XZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Radio::Display(int)" (?Display@Radio@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Radio::Radio(void)" (??0Radio@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
main.exe - 4 error(s), 0 warning(s)
Please help??????
Thanks everyone!!!!!
|
|
|
|
|
Try including radio.h and radio.cpp before main.cpp - this error usually occurs when the linker cannot resolve the definitions for the Radio class.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - Writing Word addins
Office addin
|
|
|
|
|
Maybe I am not getting this right because I am new to this, but what do you mean? I have main.cpp which looks like this:
#include <iostream.h>
#include <afxwin.h>
#include "Radio.h"
int main()
{
Radio x; //x is the object called. It is of class type Radio
int Number = 7;
x.Display(Number);
return 0;
}
Radio.cpp is the definitions of Radio.h. Main.cpp is the main program....I dont understand what you mean??
|
|
|
|
|
#include "Radio.cpp" or add the cpp file to the project and rebuild.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - Writing Word addins
Office addin
|
|
|
|
|
Ok, that works! But I have another quick question. I have not had to do this before when compiling C++ projects and I also do not have to do it when I create the project from scratch (I only got this problem when I continued working on a project after I turned my PC off). In both my C++ book and my MFC book they only include the hearder.h file. How come in the books they do not include the header.cpp file? Is this something I am going to have to do with all MFC and C++ projects in the future?
Thank you for your help Kula, this has really been helpful!
|
|
|
|
|
#include "radio.h" into radio.cpp and then #include "radio.h" into main.cpp
That should work!
|
|
|
|
|
I have that and it didnt work
|
|
|
|
|
I'm not sure what compiler you're using, however I use Visual C++ 6.0. When I create a new Win32/Console application and define a new class I simply insert the header file for the class into main.cpp and everything compiles and links just fine. From what I gather of your original post, it sounds like a compiler configuration issue. You might want to consult Microsoft's Knowledge Base just to find out if this is a known issue and if so, how to fix the problem.
I hope this helps.
|
|
|
|
|
I had to readd the files to my workspace for some odd reason. Thanks for all of your help!
|
|
|
|
|
Can anyone point me in the right direction? I have been building a audio app for a couple of months based on DirectMusic, and I have had problems looping .wavs. I'm loading them into a segment, (after the usual initialisation) setting the length, and specifying looping points, but on play back the segments play the entire file and loop from start to finish.
I suspect I am missing out a setup step, but the documentation is pants, and I can't seem to find any tutorials that deal with this. Any help would be greatly appreciated.
|
|
|
|