I would like to show graphics at a fixed 30 fps. The only solution I have is: while (true) { while (not ready) { check the performance timer() } draw() } The problem is that this method pegs the cpu. I would like to use one of these: - SetTimer and handle WM_TIMER - use WaitForSingleObject with a WaitableTimer possibly but they have too low a resolution. Can anyone see another solution? Thanks, Alex Griffing
Alex Griffing
Posts
-
waiting for a small amount of time -
Linking Input to an email outputI'm getting very frustrated with trying to send email from my computer programmatically. From what I've been able to find out, there are two choices: - use MAPI: problem: It pops up dialog boxes requiring user input when it is unable to send messages or when various errors happen. Therefore it is not useful to me since I want to run the program on a computer that isn't being looked at by a human. - use SMTP: problem: You need a computer that you can connect to on port 25 and say HELO\r\nMail From: a@b.c\r\nRCPT To: x@y.z\r\ndata\r\nfirstline\r\nlastline\r\n.\r\nQUIT\r\n or whatever. In any case I don't have a computer that I can send this through so I can't do this either. But check out the code below for an example of doing MAPI. You have to put a line of code each of mapi init and uninit and include mapi.h. The functions i call at the end here just display the appropriate error message according to a switch statement using strings taken from the msdn docs. hope it helps. /* CMfcserverDlg::Mail(CString subject, CString text) { LPMAPISENDMAIL lpfnMAPISendMail = (LPMAPISENDMAIL) GetProcAddress (m_mapiModule,"MAPISendMail"); LPMAPILOGON lpfnMAPILogon = (LPMAPILOGON) GetProcAddress (m_mapiModule,"MAPILogon"); LPMAPILOGOFF lpfnMAPILogoff = (LPMAPILOGOFF) GetProcAddress (m_mapiModule,"MAPILogoff"); LHANDLE lhSession = 0; char subject[] = "this is the subject"; char message_text[] = "automated\r\nhello\r\nthis is the message text\r\nblah\r\nblah\r\nblah\r\ngoodbye"; char str_originator_name[] = "alexander the originator"; char str_recip_name[] = "alexander the recipient"; char str_originator_address[] = "snowman@north.pole"; char str_recip_address[] = "SMTP:agriffing@hotmail.com"; MapiRecipDesc originator; originator.ulReserved = 0; originator.ulRecipClass = MAPI_ORIG; originator.lpszName = str_originator_name; originator.lpszAddress = str_originator_address; originator.ulEIDSize = 0; originator.lpEntryID = 0; MapiRecipDesc recip; recip.ulReserved = 0; recip.ulRecipClass = MAPI_TO; recip.lpszName = str_recip_name; recip.lpszAddress = str_recip_address; recip.ulEIDSize = 0; recip.lpEntryID = 0; MapiMessage msg; msg.ulReserved = 0; msg.lpszSubject = subject; msg.lpszNoteText = message_text; msg.lpszDateReceived = 0; msg.lpszConversationID = 0; msg.flFlags = 0; msg.lpOriginator = &originator; msg.nRecipCount = 1; msg.lpRecips = &recip; msg.nFileCount = 0; msg.lpFiles = 0; ULONG ret; ret = lpfnMAPILogon(0, 0, 0, 0, 0, &lhS
-
sending email from vc++How can I send email from a program? I would like to not have to go through an SMTP server. On a related note, but off topic for this forum, I set up an SMTP server on my computer but when I tried to email my hotmail account through it, it said that it was 'unable to relay' for that email address. On the 'relay restrictions' page of the internet information services settings I have the 'Allow all computers which successfully authenticate to relay' check box checked. Thank you for suggestions, -Alex Griffing
-
Connect() timeoutWhen I do CSocket sock; sock.Connect(place_that_doesn't_exist); Connect waits like half a minute before returning. I could do some kind of multithreading or overlapped IO completion ports (neither of which I have any experience with) but it would work for me just to have it return after a second or two if it can't connect. I was thinking along the lines of something like sock.SetTimeout(500_milliseconds); or setsockopt(sock.m_socket, SO_TIMEOUT, 500_milliseconds); Any suggestions? Thanks! - Alex Griffing
-
I don't want message boxes to beepI could unplug my speaker or give information in another way, but it's so easy to say AfxMessageBox("foo"); Is there a setting on the computer or a programmatic way to stop the annoying beeping (without deplugging the computer speaker :))? Thanks!
-
sending emailIs there a way to send email (with attachments too) without calling an smtp server? Is there an article for this or an API call or code somewhere? I'll bet this a pretty frequently asked question but I can't find any answers. Thank you! Alex Griffing
-
newbie stl compiler error questionYeah the forum ate my code. The type was, let's try to do this explicitly, typedef std::list<Socket *> SOCKLIST; but I fixed the problem, so it's OK. Thanks for the feedback!
-
newbie stl compiler error questionOk sorry. the < should be a !=
-
newbie stl compiler error questionHi everyone! I'm trying to learn stl, resisting the temptation to reinvent the wheel repeatedly, but I'm running into an initial problem. typedef std::list SOCKLIST; function(SOCKLIST sockets_) { SOCKLIST::iterator it; for (it=sockets_.begin(); it &,const class std::list<_Ty,_A> &)' : could not deduce template argument for 'const class std::list<_Ty,_A> &' from 'class std::list
-
Video streaming bluesHi all! I have a bunch of problems that fall under the general category of video streaming, and since this technology is rapidly advancing I'm hoping that other people are dealing with this too. I have: Analog camera -> osprey card -> Real Producer I would like: Analog camera -> osprey card -> my little program -> Real Producer I'm afraid it might not be in the cards, but I've only done VFW stuff so maybe it can be done using DirectShow? One problem is that I need to monitor the video stream (locally) but since the encoder is connected to the capture device I'm working around the problem by constantly peeking at the DC of the display window (X|) Is there a better way? Another problem is that I need a _live_ display (to get a reasonably tight feedback loop, as in video conferencing) but the >10 second delay that makes the Real stream so smooth and low bitrate makes the latency too high. Again, I'm working around this by capturing the DC of the Real Producer display, shrinking it, compressing it to a jpeg, then sending it over the net to a receiving program. Very inefficient, but the point is to get improved latency which it does. But it still makes me gag. By the way, the receiving program I'm using is a windows exe, but I'd like it to display on the web instead (users won't download stuff). I assume that the way to do this would be using java or an ATL control - neither of which I know now, but if this is the way to do it then I will learn. Any suggestions? To vent another video complaint, my stinky little Real Producer voyeur program saves recent frames in a circular buffer and makes a video file from it upon request. However, it's a pain to use the driver's 'compression dialog' to set the compression parameters manually. I'm working around it by saving the result of the compression structure in a file. As an aside, is it possible to change the video format and source in a more programmatically flexible way than clicking on a radio button in the driver's dialog box? I think I remember DirectShow being able to do this though. What's the legal status of the divx codec? Personal use? In-house use? Commercial use? Another video question - There are lots of codecs for transforming (a bunch of raw frames) -> (a video file) but I'm looking for a way to replace sending a 'stream' of jpeg frames (generated on the fly) over the network. Any pointers? Also I just noticed that versions of windows more recent than 95 have built-in JPEG support! My question is how compatible is
-
changing the cursorThanks, I just finally found that. I guess DefWindowProc was the culprit that kept changing the cursor back!
-
changing the cursorHi! I'm trying to set the mouse to a custom cursor while it's in the client window. I made a cursor with myhcur = CreateCursor(...) I tried SetCursor(myhcur), but it got immediately changed back to the normal arrow cursor. So then I tried changing the system cursor from arrow to my custom cursor, which I did with SetSystemCursor(myhcur, 32512). I used 32512 instead of OCR_NORMAL because the compiler thought it was an undefined symbol even when I'd included winuser.h. So now I have my own custom cursor instead of the arrow and everything works great. The problem is that I can't switch back. I've tried each of hnormal = (HCURSOR) LoadImage(0, (char *) 32512/*OCR_NORMAL*/, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE); and hnormal = LoadCursor(0, IDC_ARROW); But when I try to set these back when my program ends, SetSystemCursor(hnormal, 32512) returns no error but doesn't change the cursor back. :)...:confused:...:((...:mad:
-
where is the mouse?I would like my program to know at all times: - Is the mouse in the client area? - If so then where is it? And I want to do this without polling GetCursorPos. A windows message like WM_MOUSEHASJUSTLEFT_YOURCLIENTAREA would be nice because then I could just use the last value I got from WM_MOUSEMOVE without worrying that the mouse has left the premises. Any suggestions? Thanks! -Alex
-
basic c/c++ question (const related)I'd just like to make sure of something that I'm kind of worried about. This is not ok: char *Foo() { char ret[100] = "hello"; return ret; } This is not ok: char *Foo() { char ret[100] = "hello"; return ret; } This is ok: const char *Foo() { return "hello world"; } main() { printf(Foo()); } Is this right? Thanks!
-
I thought I understood polymorphismThanks for your reply! I don't think I've gone polymorphism happy (in the everything-looking-like-a-nail sense.) My vision is to have code that says: pObject = new MyFoobarizedZonkObject(); and I want the initialisation of the foobarized part of it to take place as a virtual function because there might also be a MyFoobarizedBlipObject whose foobarized part might be initialized a bit differently from MyFoobarizedZonkObject's. I guess you could take all the code that makes the objects foobarized and put it into its own class and use containment rather than inheritance, but this might or might not be natural. Does this make sense? I don't know what I was thinking with the inline constructor except that I've just started using inline functions a lot and I'm used to putting 'inline' whenever I don't have the function defined in the cpp file. I know this isn't how it goes though and that 'inline' shouldn't be before the constructor declaration. Saying 'virtual' before the 'bar' declaration in the fooplus class is also redundant, right? I guess I don't quite see how the 'virtual constructor' would apply because I don't have a correctly initialized object to start with. What would the code look like to use it? Thank you, Alex
-
I thought I understood polymorphismIs the alternative to say: pMyThing = new Thing(); pMyThing->Init(); all the time? That would suck.
-
I thought I understood polymorphismI'm working around it by putting everything except the call to the overridden function in a new member function (Init). This way it works, but both constructors have the same code. foo() { init(); //foo::init() bar(); //foo::bar() } fooplus() { init(); //foo::init(); bar(); //fooplus::bar(); }
-
I thought I understood polymorphismThe wrong function is getting called. I believe it goes like this: class foo { public: inline foo() { bar(); } virtual bar(); }; class fooplus : public foo { public: inline fooplus() : foo() {}; virtual bar(); } The problem is that when I instantiate fooplus, foo::bar gets called instead of fooplus::bar. I believe that if you said fooplus fooinst; fooinst.bar(); then it would call foo::bar and then fooplus::bar. I'm trying to use more of the power of C++, but stuff like this is making me want to just use it like C with member functions like I used to. :(
-
stupid (template related?) linkage puzzleThis is one of those problems that would have been a nagging doubt for a long time. Thanks for explaining it to me! :rose:
-
stupid (template related?) linkage puzzleHi everyone! I've been programming in C++ for quite a while but I'm just learning the template stuff in the hopes of taking advantage of the STL. Anyway, I have a header file declaring two different classes, one of which is templated. The non-inlined member functions of these classes are defined in the same cpp file. When I try to build the program, the non-inlined member functions of the templated classes give me a linkage error (unresolved external symbol) while the corresponding functions of the non-templated class work fine. Furthermore, if I cut and paste the definitions of the member function of the templated class into the header file then everything links up fine. I know if I keep it like this I'll get reincarnated as a newt. Any suggestions? :confused: