|
Hi all,
I am converting two floats to LPTSTR and trying to concatenate them. I have tried _tcscat, StringCbCatW, lstrcat, and lstrcatW. With all of these methods, after concatenation, I am only getting the value in "message" but not the concatenated part of "message1". And the application that uses this file (dll) crashes after showing the first part.
Can someone please suggest something? Any help is appreciated.
Here is a part of the code:
float a = 45.670;
float b = 2323.78;
LPTSTR message = TEXT("");
LPTSTR message1 = TEXT("");
std::stringstream sstr;
sstr << a;
std::string str1 = sstr.str();
message = (LPTSTR)str1.c_str();
std::stringstream sstr1;
sstr1 << b;
std::string str2 = sstr1.str();
message1 = (LPTSTR)str2.c_str();
_tcscat(message,message1);
//StringCbCatW(message,BUFSIZE,message1);
//lpvMessage = lstrcatW(message,message1);
|
|
|
|
|
akhanal wrote: And the application that uses this file (dll) crashes after showing the first part.
Can someone please suggest something? Any help is appreciated.
Because message does not point to any allocated memory that is large enough. Why not do something like:
float a = 45.670;
float b = 2323.78;
std::stringstream sstr1;
sstr1 << a;
std::stringstream sstr2;
sstr2 << b;
std::string str = sstr1.str() + sstr2.str();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
That was great, it worked.
Thanks, appreciate your help.
|
|
|
|
|
I'm using a custom entry point.
instead of winMainCRTStartup=>WinMain, I'm using my own AppBoot().
Too make the exe a little leaner.
I've got custom new and delete and don't use exceptions.
That's all great.
But when I start using double and math funcs like sin(),
I get the above error.
my linker subsystem is windows and I have a custom entry point.
So I'm guessing one or some of the math funcs are pulling in mainCRTStartup??
Not sure why it'd pull that instead of the WinMainCRTStartup??
Anybody run into this before?
Thanks,
...Steve
|
|
|
|
|
Hi.
I want to name subgroups in regex:
For example, if I would use .Net it would be like this:
using namespace System::Text::RegularExpressions;
...
Regex^ re="(?<letters>[a-zA-Z]*)(?<numbers>[0-9]*)";
MatchCollection^ matches = re->Matches(szInput);
for each (Match^ match in matches){
MessageBox::Show(Match->Groups["letters"]->Value);
MessageBox::Show(Match->Groups["numbers"]->Value)
}
Can I do the same thing in MFC using Boost::Regex libraries?
|
|
|
|
|
I try to use Modal & Modeless dialog to show WARNING within 2 seconds as the following:
CDialog *dlg;
dlg = new CDialog;
int id = dlg->Create(IDD_DIALOG_MESSAGE, this);
dlg->ShowWindow(SW_SHOW);
Sleep(2000);
dlg->DestroyWindow();
But it always appearing under the other Window dialog, even I remove the comment out as parent, but it doesn't help
Any one know how to do it?
|
|
|
|
|
Try with BringWindowToTop[^]. However, freezing your GUI thread for 2 seconds (leaving it completely unresponsive and undrawn) isn't such a good idea, you could try bringing your window up and then removing it later using a timer (WM_TIMER)...anyways, if you insist on the sleep you might need to explicitly redraw [^] your warning window before the sleep.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Why not just use a modal dialog that automatically closes itself after 2 seconds?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Can you provide any link how to show it in 2 seconds?
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Dear everybody,
I have a question about the meaning of & operator in the following expression:
((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
1) What role does the & operator do here ?
2) Why do programmers often use & with hexadecimal, not integer or long integer or double ?
I'm looking forward to seeing your reply soon.
Best regards,
Jetflower
|
|
|
|
|
Thang wrote: 1) What role does the & operator do here ?
Bitwise AND.
Thang wrote: 2) Why do programmers often use & with hexadecimal, not integer or long integer or double ?
Bits, bytes, and words are easier to visualize in base-16.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Okay, lets say that l = 3131961357
This is the same as 0xBAADF00D
Which is the same as 10111010101011011111000000001101
Which means your expression looks a little something like this:
((WORD)(((DWORD)(0xBAADF00D) >> 16) & 0xFFFF))
3131961357 >> 16 = 47789
0xBAADF00D >> 16 = 0x0000BAAD
10111010101011011111000000001101 >> 16 = 00000000000000001011101010101101
47789 & 65535 = 47789
0x0000BAAD & 0x0000FFFF = 0x0000BAAD
00000000000000001011101010101101 & 00000000000000001111111111111111 = 00000000000000001011101010101101
Basically, the code simply takes a 32 bit number and returns the top (most significant) 16 bits of them.
The >> 16 followed by the & 0xFFFF is unnecessary - the bitshift right 16 bits automatically fills the top 16 bits with 0s.
This code is functionally the same:
(WORD)((DWORD)(l) >> 16)
See how much easier things are when we use hex/binary?
Edited && --> &
|
|
|
|
|
We're lucky that
0XDEADBEEF != 0XBAADFOOD
This signature was proudly tested on animals.
|
|
|
|
|
|
Dear Mr enhzflep and Mr DavidCrow,
First of all, thank you so much about your clearly explanation.
I just still have a consideration, why the small expression (& 0xFFFF) has been still used in the expression ((l) >> 16) & 0xFFFF) here .
And this expression origins from window library, hix.
Why they still have used this expression if it was not necessary in here ?
Once again, thanks for your help, Mr enhzflep and Mr DavidCrow.
Best regards,
Duong Quoc Thang
|
|
|
|
|
Hi,
I'm trying to place a slider control (CSliderCtrl) on the status bar. The slider bar appears fine and I can move it around (either manually or by calling SetPos). However, I can't find where the WM_HSCROLL messages from the slider bar are sent to! I set the parent of the slider control to the status bar, but no WM_HSCROLL is sent to that window! Any ideas?
Here's what my code looks like. First off, I derived a class from CStatusBar to handle WM_HSCROLL:
class CMyStatusBar : public CStatusBar
{
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};
In my view class (e.g. CMySimpleProjctView) I added two members:
CSliderCtrl videoPosSlider;
CMyStatusBar statusBar;
and also a function called InitSliderBar() which is something like this:
void CMySimpleProjctView::InitSliderBar()
{
CMainFrame* frame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
statusBar = (CMyStatusBar*)(frame->GetStatusBar());
RECT rc;
statusBar->GetItemRect(0, &rc);
VERIFY (videoPosSlider.Create(WS_CHILD | WS_VISIBLE, rc, statusBar, 1));
videoPosSlider.SetRange(0, 50, 1);
videoPosSlider.SetPos(5);
}
When I run the program, the slider bar appears and I can move it around, but CMyStatusBar::OnHScroll() is not called when I move the slider. To test if everything else is fine, I changed the parent of the slider control to the view window in the code as
VERIFY (videoPosSlider.Create(WS_CHILD | WS_VISIBLE, rc, m_hWnd, 1));
and now CMySimpleProjctView::OnHScroll *is* called (but of course the slider bar appears at the wrong place, not on the status bar). I tried Spy++ to see where the WM_HSCROLL is sent to (when parent=status bar) but no WM_HSCROLL is sent at all! In fact no messages are passed when I move the slider around!!
Any ideas? thanks.
-Babak
(by the way, videoPosSlider.GetOwner() and videoPosSlider.GetParent() both return pointers that are identical to statusBar)
|
|
|
|
|
Hello,
I'm maintaining an MFC application that reads and writes from/to the registry. Previously, it used the HKEY_LOCAL_MACHINE key. However, this meant that Vista users needed full OS administrative privileges, (and perhaps non-admin XP users, but there aren't a whole lot of those around) which isn't desirable. So, I changed the key used to HKEY_CURRENT_USER. This just appears to not work at all on Vista as a regular user, though it does work elsewhere.
How can I store values in the registry without administrative privileges?
Regards,
Sternocera
|
|
|
|
|
Sternocera wrote: This just appears to not work at all on Vista as a regular user...
Do the registry functions fail?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
You need to include a security section in your manifest file to prevent Registry and File Virtualization for your application (or have the user turn User Access Control [UAC] off).
I would recommend the manifest resource file with the security section since it allows you to use registry and file functions without getting false positives from virtualization. I use "AsInvoker" for user apps.
"Windows via C/C++, Fifth Edition" by Richter has some good information on dealing with Vista and using manifests correctly.
The Microsoft endorsed way of properly designing an application for UAC is to use a security manifest section in your manifest file/resource.
Windows Vista Application Development Requirements for User Account Control Compatibility[^]
Create and Embed an application manifest[^]
Certified for Logo Test Case[^]
|
|
|
|
|
Bob,
Thanks for that, but all I want to do is stored some key:value pair application settings! Surely there is a simpler way?
bob16972 wrote: You need to include a security section in your manifest file to prevent Registry and File Virtualization for your application (or have the user turn User Access Control [UAC] off).
Why? I thought that registry and file virtualisation where ways in which
Vista supported applications that used the registry.
Regards,
Sternocera
|
|
|
|
|
Just brushing up my C++ here, and a quick question.
I see people pass by reference using the following methods
&int x;
int & x;
int &x;
Difference? Which is better practice? When declaring a function definition and you want that function to accept a reference, how do you define that function heading?
double myFunction(&int);
?
or do you include the variable name?
double myFunction(int &x);
Sorry to make you go over the basics, my book isn't very clear...
|
|
|
|
|
AFAIK, this: &int x; isn't valid C++.
the other two are identical.
double myFunction(&int);
that's not legal, either.
i always include the variable name, since the header is the first place i look when looking for documentation.
|
|
|
|
|
Hey, thanks for the response.
So you include the variable name in the function definition? Seems like the smart thing to do I guess, I'll try to pick up on that habit.
Thanks for the reply. 5'ed.
|
|
|
|
|
EliottA wrote:
So you include the variable name in the function definition?
yeah. it's not strictly required, but it's really handy to people who want to use the function.
|
|
|
|