|
lstrcpynA(errmsg, bufsize);
If using TCHAR, do:
<br />
lstrcpyn(errmsg, bufsize / sizeof(TCHAR));
(lstrcpyn is a tiny bit more efficient than strncpy since it doesn't fill the rest of the buffer with zeros after completing the copy. With large buffers, this is generally a waste of cycles.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
I have created an SDI application with tabbed view. I have used view class derived from CTabView (class from MFC Feature Pack). I want to show different toolbars on the MainFrame for each tab and alternately change the toolbars when the tab selection is changed. But i have problems with swithching the toolbars. Is there any way to switch the toolbars or associate a custom toolbar for each tab of the view?
Thanks
|
|
|
|
|
Dear All,
I have two classes Test and Test1. I have a static variable in the class Test and I have to access it in another class Test1 from a funtion. When I access it, I got linker error. The error is :
1>Test1.obj : error LNK2001: unresolved external symbol "public: static int Test::cnt" (?cnt@Test@@2HA)
1>Test.obj : error LNK2001: unresolved external symbol "public: static int Test::cnt" (?cnt@Test@@2HA)
Code snippet :
class Test : public CDialog,public CDemux
{
DECLARE_DYNAMIC(DecodeTS)
Public
static int cnt;
.......
void Test1::GetData()
{
int cnt =Test::cnt;
}
|
|
|
|
|
This is a known quirk in C++: For static variables in a class, you need to repeat the declaration in the .cpp file.
So add this:
int Test1::cnt;
to your .cpp file and it will stop this linker error.
|
|
|
|
|
I have the static variable in Test class. When I declare again in Test.cpp it shows redefinition error. I do like this in Test.cpp file.
int Test::cnt;
Linker error gone but another error occur as redefinition.
|
|
|
|
|
Hello Alan,
Now I have fixed it, the problem is that I give the int Test::cnt; in the constructor and thats why the error I got. Now I give the line at the top of the cpp file and it is working fine.
Thank you very much.
Many thanks.
|
|
|
|
|
Alan Balkany wrote: This is a known quirk in C++: For static variables in a class, you need to repeat the declaration in the .cpp file.
It's not a quirk, and you're not re-declaring the variable.
The one-and-only static member variable instance needs to exist
somewhere, so you have to define that instance.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
But this is counterintuitive; you don't have to redeclare the non-static class members.
I got burned by this quirk years ago. I've seen several other people run into this same problem on this forum over the years. There's no good reason for this behavior.
|
|
|
|
|
Alan Balkany wrote: you don't have to redeclare the non-static class members.
A declaration is not an instance. You are NOT declaring static member variables twice.
You declare the variable once, and you also must provide an instance of the variable.
Non-static members are not the same - every existing object (instance) of the type gets its
own instance of the variable.
Alan Balkany wrote: There's no good reason for this behavior.
You'll have to ask Bjarne for the good reason
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yet people continue to get burned by this "feature".
I see bad design every day.
|
|
|
|
|
"burned"? How so? It's just a simple linker error - a LOT easier
than tracking down a runtime error
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Burned: You write code that the compiler accepts, but it doesn't work. You waste hours or days until you (somehow) learn the gimmick that gets by the quirk.
Good language design minimizes instances of this. Stroustrup isn't infallible, and the fact that he implemented this doesn't automatically make it good.
|
|
|
|
|
Right. I never said it was good. Every language has its trade-offs.
This particular case has always been the case. Had the C++ designer(s) let the
compiler choose where to create the instance, there's would be a whole lot
of us whining because we don't have control over the storage of our variables.
I use C++ for the low level control. I understand how objects exist and where, and
I take advantage of the control I have over that. So to me it is not counter-intuitive
to have to explicitly state where an object is stored. For times I don't care, I'll use
a higher level language - C# works just fine
The whole "static" thing in itself is kind of an abomination itself - mixing linkage with compilation.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Since there's only one instance of a static variable, it doesn't matter where it's stored.
It's counterintuitive because neither instance variables NOR "ordinary" static variables require two declarations, and the thousands of people who have had their time wasted by this quirk support this assertion.
|
|
|
|
|
Alan Balkany wrote: and the thousands of people who have had their time wasted by this
Thousands? I thought EVERYONE went through it at least once
I get where you're coming from - I just do not agree that there's two declarations. There's
a distinct difference between declaration and an actual instance of an object.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
This linked fine for me:
class Test : public CDialog
{
DECLARE_DYNAMIC(Test)
public:
static int cnt;
};
class Test1
{
void GetData()
{
int cnt = Test::cnt;
}
}; Can you compare it to what you have?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
I fix the problem. Please refer the above.
|
|
|
|
|
That shouldn't link, at least not if you actually use one of those classes
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: ...at least not if you actually use one of those classes
I didn't.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Anyone know of an x64 PKWare compatible compression library (or a library with source code that would allow me to build the x64 version). I currently use an old version of the PKWare Data Compression Library that allows blocks of data to be compressed and restored but there isn't a 64bit version and PKWare don't list 64 bit versions of anything on their website.
|
|
|
|
|
Hi,
I have created a LIB using Win32 Static Library in which i have overriden the CWnd ::Create method.
when i use this LIB in MFC application to create the Window its giving ASSERSETION
due to parent window handle is becoming NULL.
|
|
|
|
|
Window handles don't just "become NULL".
The problem could be anything from mismatched or multiple MFC libraries
to errors in your code. Have you tried to debug it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have created the Win32 Static Library which has MFC Support and Using Precompiled Header
(This LIB has been created by selecting Win32 Static Library from MFC Project Option )
I have added one class to library which is derived from CWnd, In Derived Class i have overriden the
Create()method to create the window.
At Application side
I have MFC SDI application which has multiple splitters where each pane of splitter corrsoponds to one class.
One of the class wants to create the window using the LIB that i have created.
when i give call to the Create from application side it is giving assertion on
ASSERT(afxCurrentInstanceHandle != NULL)
To Test LIB,i have tried for following things
I have created the TestApp using MFC SDI and while generating the Application CTestView is derived from the CFormView.
here call to Create of LIB is working fine.
|
|
|
|
|
Hello,
I need to parse a data file which contains reals.
The decimal separator use is always the dot '.'
I try to extract the values using a stringstream to get the result into a double.
As you probably know, stringstream use the current locale to determine the decimal seperator to use...
and that is my problem !
How can I tell to my stringstream to use the dot separator regardless the current locale ?
I can not find a "simple" snippet to do this.
Any idea ?
|
|
|
|
|
jeremie.delaitre wrote: Any idea ?
I don't know the specific answer. Based on my limited knowledge of STL I would think you could create a specific locale and make the stream use it. I think streams have like imbue() function or something to make them use specific locales.
led mike
|
|
|
|