|
But in my testing program, all kinds of exceptions including zero-dividing or NULL pointer can be caught by catch(...). Why? Does that mean we can always use C++ try/catch in C++ programs?
|
|
|
|
|
Lane Yu wrote: But in my testing program, all kinds of exceptions including zero-dividing or NULL pointer can be caught by catch(...). Why? Does that mean we can always use C++ try/catch in C++ programs?
As my previous post indicated, the fact that you can use try /catch to catch NULL pointer references and zero-dividing indicates that:
- You're using an old and non-standard compiler such as Microsoft Visual Studio 6.
- You're using a compiler with a non-standard extension with enables this non-standard behaviour; such as the later Microsoft compiler's /EHa switch.
In standard C++ try /catch can NOT catch these exceptions!
Steve
|
|
|
|
|
Thank you. I'm using VC6.
|
|
|
|
|
I have developped a software. Now I need to make a setup file. I have used "Visual Studio 2005" to created a setup file. But it needs to install "Framework 2.0" when the user install it, it is very inconvenient.
Does anybody know some other tools to make it?
Thanks a lot.
|
|
|
|
|
there are plenty of tools out there, but you should be able to do a VS2005 install without .NET.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
In my college course, we mainly did console C and C++ programs. Now I studied MFC and C#.NET for GUI programs but I prefer good old C++.
My question is MFC is what is used to make applications for Windows? Like small apps like uTorrent for example to common programs like Winamp or basically the programs found on Download.com.
The thing is I can't find a good book on MFC. Seems like it is "old" technology especially with the push of C# and .NET
I really want to get started making some simple applications in C++ for Windows. Is MFC the only way?
|
|
|
|
|
There are many class libraries, but the two you'll hear the most about are MFC and ATL/WTL. (WTL is a set of GUI classes that build upon ATL.) However, you don't have to use a class library, and in fact it's my strong opinion that you should not use any class library at all until you understand how to do GUI programming at the Win32 API level.
EDIT: Forgot to give my thoughts on uTorrent. From what I see in Spy++, it looks like it was all hand-rolled. I don't see any window classes or names that indicate MFC or ATL was used. Last modified: 38mins after originally posted --
|
|
|
|
|
Firestorm ZERO wrote: The thing is I can't find a good book on MFC
Unfortunately, Microsoft pushed it down so hard, that many books vanished in a very short period about 1-2 years ago. MFC seems to be a four letter word around here anymore as far as some Microsoft MVP's are concerned.
I've been trying to weed myself away from it but I'm finding it hard to give up.
For what it's worth, we just decided to base a very large and important app on MFC if your asking "who's using MFC nowadays?"
As for .NET using C++, I took a good hard look at Nish's book "C++/CLI in Action" and he makes a good effort at trying to explain it all but I was so lost toward the middle due to C++/CLI's complexity and lack of traditional C/C++ programming concepts that I had to put it down. I think I have a better chance learning the STL before C++/CLI. The little experiment with managed extensions also lends to the confusion of what is what anymore when referring to .NET from a C++ perspective.
Firestorm ZERO wrote: Is MFC the only way?
If your intent is to use C++, COM appears to be the easiest way to provide interfaces for other languages and MFC is the way to go for that if you dislike template programming first hand. If looking at template code does not make your eyes cross then ATL/WTL might be worth looking into. Mr. Dunn provides some fairly interesting tutorials on WTL here on CP.
|
|
|
|
|
Firestorm ZERO wrote: I really want to get started making some simple applications in C++ for Windows. Is MFC the only way?
No, of course, it isn't the only way. You can use directly Win32 API, or other class libraries. If you aren't stuck with C++, then you can use C# to develop Windows applications.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I am trying to access a C# dll from MFC application. One of this dll method, XMLDoc(), returns an XMLDocument object. When I compile the c++ project, a tlh file is created where I find:
virtual HRESULT __stdcall XMLDoc (
/*[out,retval]*/ IUnknown * * pRetVal ) = 0;
Seems this method returns IUnknown instead of XMLDocument object directly. I am facing problem getting the XMLDocument object from this IUnknown interface.
Can anybody show me a way/sample to do this?
Thanks in advance.
Nazmul
|
|
|
|
|
Probably a cast of pRetVal pointer will be harmless. Anyway, the better (and safer) way is asking the IXMLDocument interface via the (*pRetVal)->QueryInterface method.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi all. Im trying to find some information on the ConductEchoSession() API. Google only has one result, as well as Yahoo. And they both point back to a post on a forum a few months ago. MSDN doesnt have a clue what it is or provide any information about the function. The name seems to be self explanitory Conduct echo session. But i like to be able to look things up and since i cant do that for this function i need the help from someone to give a brief explanation. Thanx in advance!
|
|
|
|
|
It's not an API, it's a function that someone wrote. The code is provided in the post[^].
|
|
|
|
|
I am not 100% sure how keyboard input works, so I thought I'd ask it here.
I already asked about blocking joystick devices in C++, but I got no answers
See here: http://www.codeproject.com/script/comments/forums.asp?msg=2038033&forumid=1647&mode=all&userid=4049045#xx2038033xx
[^]
Mostly, I am curious if there is a way to detect keyboard input from a "real keyboard" and differentiate it from a clicker/macro program. I want to do this in C++. I know there are WinAPI functions as well as Direct3d functions for such things, but I couldn't find any information on if it's possible to tell them apart.
Any answers would be appreciated. Thanks in advance.
|
|
|
|
|
You can use SetWindowsHookEx() with the WH_KEYBOARD_LL parameter to monitor all low-level keyboard messages. From the callback function, LowLevelKeyboardProc(), you can block any of the messages by returning a nonzero value, so that the message isn't sent to the target window. You could do something like this:
...
//Prototypes
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
...
//Global variables
HHOOK hLowlevelKeyboardHook; //Low-level keyboard hook handle
...
//Main Window Callback function
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
...
switch(msg)
{
case WM_CREATE:
hLowlevelKeyboardHook=SetWindowsHookEx(WH_KEYBOARD_LL, //Low-level keyboard messages
LowLevelKeyboardProc, //Hook Callback function
NULL, //Monitor all system messages
0 //Monitor all system messages
);
break;
}
...
}
...
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LPKBDLLHOOKSTRUCT kbdst;
if(nCode<0) //No message to process
return CallNextHookEx(hLowlevelKeyboardHook, nCode, wParam, lParam);
//Block all keyboard messages, if they are the letter 'A'
kbdst=(LPKBDLLHOOKSTRUCT)lParam;
if(kbdst->vkCode==41)
return -1;
//Otherwise, send the message to the next hook
return CallNextHookEx(hLowlevelKeyboardHook, nCode, wParam, lParam);
}
Hope this helps!
--PerspX
|
|
|
|
|
I have a requirement to read data from a serial port and send it out over a network port. The data must be sent when either of these two conditions are met:
1) 1400 bytes read.
2) 20 milliseconds have elapsed since the last read finished (if no data is present wait another 20 ms or until condition 1)
To try an meet these goals I am using overlapped IO. Here is the read:
ReadFile(hComm, ReadBuffer, 1400, &dwRead, &osReader);
I am trying to use a Waitable Timer to signal the 20 ms for requirement 2. The problem is how do I stop the current read operation and get all the characters that have been read when the timer expires? I tried using WaitForMultipleObjects but I am stuck on what to do when the timer expires.
I am writing this application in VC++ using Visual Studio 2005, target platform is Windows XP.
|
|
|
|
|
RMLPilot wrote: The problem is how do I stop the current read operation
Have you looked at SetCommTimeouts() ?
|
|
|
|
|
Hans Dietrich wrote: Have you looked at SetCommTimeouts()?
I tried a look at SetCommTimeouts() but it did not work. Perhaps I had the parameters wrong. I used the following:
COMMTIMEOUTS Timeouts;
ZeroMemory(&Timeouts, sizeof(COMMTIMEOUTS));
Timeouts.ReadIntervalTimeout = 20;
Timeouts.ReadTotalTimeoutMultiplier = 0;
Timeouts.ReadTotalTimeoutConstant = 20;
Timeouts.WriteTotalTimeoutMultiplier = 0;
Timeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(Timeouts);
My understanding of these values is the I shouldn't get the event unless either 20 ms has passed between input bytes or (0 ms * 1400 bytes) + 20 ms has passed. This did not seem to work, I got about a second delay between events. Did I misinterpret the documentation on this call?
|
|
|
|
|
|
How about using async I/O, aka overlapped I/O, to talk to the serial port and, then if your timer expires, cancel the ReadFile using the CancelIo.
One thing to consider is if a partial block of data comes in when your timer expires. What will you do if 500 bytes have come in when your timer expires?
Assuming the source of the data always puts the data onto the serial line in 1400 byte chunks, another idea to consider is to not use a continuous retry loop to read the data. Instead, use the WaitCommEvent function to detect when a byte has been read by the port and then calling the ReadFile to read the 1400 bytes.
Judy
|
|
|
|
|
i have been mad on my code it give me results i cant fingure out how they come
i want to find how many words there are in a string
yes123ok2 no but !@#$ ok <=== 5 words
my code
int CInfoRecoverDlg::WordDocu(CString line)
{
int y= 0;
int x = line.GetLength();
for ( int i = 0 ; i < x ; i++)
{
if ( x >1)
{
if ( !_istalpha((line.GetAt(i)) && _istalpha(line.GetAt(i-1))))
{
y = y +1;
}
}
}
return y;
}
void CInfoRecoverDlg::OnButton1()
{
CString str1;
CString str = "yes";
CString line = "2d1s";
CString str2;
str2.Format(_T("%d"),WordDocu(line));
AfxMessageBox(str2);
}
i dont care so much to correct the code but for how much stupid f***ing retard i could be
the AfxMessageBox appear me 4 while
i try to say with my code if index = not character and (index-1) = character then there will be 1 word
|
|
|
|
|
I guess first of all, how do you define a word?
What separates words? Any non alphabetic character including whitespace?
Just whitespace?
How many words are in this string - "yes123ok2"
How many do you expect in this string "!@#$ ok" ?
I thought I read in other post that you're looking for words like google search line.
If so, looking for whitespace seems the way to go.
So a string like "yes no maybe" is 3 words.
Is that what you are trying to do?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i am trying to do yes123ok2 = 2 words
!@#$ok = 1 word !!@#$ ok = 1 word
yes no maybe = 3 words
|
|
|
|
|
Also
Hello !My name is Papas, John Papas!
i want to take as words My Papas and Papas too (not only the words between whitespace)
|
|
|
|