|
Shouldn't a call to reserve() do fine?
--
...Coca Cola, sometimes war...
|
|
|
|
|
Hmmm - I thought string was like vector - which it isn't entirely, now that I check - you can call reserve to aattempt to reduce the amount of allocated storage.
However, both the C++ Standard and MSDN say that it's non-binding (i.e. the library doesn't have to honour your request). And the STL with VC++ 7.1 doesn't honour requests with capacity less than the current size (i.e. it won't shrink strings). So half a mark each - strictly, you can try to use reserve like this, but in practise, it doesn't shrink string allocations.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
That sounds like bad design. They ought to replace the reserve() function and with a set_capacity() function IMO.
--
...Coca Cola, sometimes war...
|
|
|
|
|
I'm having quite a problem. I have a class that has this attribute: a vector template. Something like the following:
<br />
extern "C" class __declspec(dllexport) AnotherClass { ... };<br />
<br />
extern "C" class __declspec(dllexport) MyClass<br />
{<br />
private:<br />
vector<AnotherClass> m_vecClass;<br />
};<br />
When I compile it, I get this warning message:
warning C4251: 'm_vecClass' : class 'std::vector<AnotherClass,class std::allocator<class AnotherClass> >' needs to have dll-interface to be used by clients of class 'MyClass'.
I don't know what to do, though I guess I should do something like
<br />
__declspec(dllexport) vector<AnotherClass> m_vecClass<br />
Still, it is not working.
I hope someone can help me. Thanks a lot.
|
|
|
|
|
|
You can't extern "C" a class. A class is a C++ specific feature, and I don't see how you could give it a C compatible linkage.
--
...Coca Cola, sometimes war...
|
|
|
|
|
I use extern "C" for the mangling. If I do not add extern "C", the compiler mangles the class as it wish, and there is no standard for that. So even when the class is a C++ class, if I create a class in Visual C++ and try to import it from its DLL with a Borland C++, it will not compile.
The use of extern "C" prevents the compiler of this mangling situation. Like the use of ordinals in a MAKE file.
Fools say I know you don't know,
silence like a cancer grows;
hear my words, that I might teach you;
take my arms, that I might reach you;
but my words like silence raindrops fell...
echoed the will of silence.
|
|
|
|
|
I use extern "C" for the mangling. If I do not add extern "C", the compiler mangles the class as it wish, and there is no standard for that. So even when the class is a C++ class, if I create a class in Visual C++ and try to import it from its DLL with a Borland C++, it will not compile.
The use of extern "C" prevents the compiler of this mangling situation. Like the use of ordinals in a MAKE file.
Fools say I know you don't know,
silence like a cancer grows;
hear my words, that I might teach you;
take my arms, that I might reach you;
but my words like silence raindrops fell...
echoed the will of silence.
|
|
|
|
|
I see..
--
...Coca Cola, sometimes war...
|
|
|
|
|
AFAIK you CANNOT share C++ code compiled with one vendor's compiler for use by another vendor's compiler. So if you write a C++ class in MSVC and make it into a DLL, you can't then use that dll/class with another vendor's compiler (like Borland). The problem is that each vendor has different ways of layout various C++ internals, such as virtual function tables, multiple inheritance, name mangling (for function overloading, a C++ feature), etc. Plus other features, like operator new/delete may be done differently and the vendor's underlying C Runtime may have a different memory manager, which will cause problems for stuff like the STL (classes like std::basic_string use the C runtime).
Part of the reason for COM was that C++ couldn't be shared this way. You'll note that when application's expose their API for 3rd party plug-ins in C++ they ALWAYS state the compiler you have to use. For example, Alias|Wavefront's Maya program (a powerful 3D Editor) has a sophisticated plugin API in C++, but you MUST use the MS VC compiler to develop for it - you can't use Borland, Digital Mars, GCC or anything else.
This is a known problem, and so far the vendor's have never agreed to a common C++ ABI. It's slightly less of a problem on other platforms, but it's still there. For example on linux most people use GCC and the GCC folks have published and (supposedly) adhere to an open binary ABI for C++. Mac OS X also shares this ABI and I believe that vendor's like Metroworks also honor it (at least on OS X).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
You have to export an explicit instantiation of vector<AnotherClass> . The procedure is thoroughly explained in this MSKB article[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi
How to resize an ATL activeX Control ? (from inside the Control's code)
I use SetWindowPos or MoveWindow and they work..But when the contol is activated (the user clicks it) it's resized back to the original size.
any help with this ?
I use ATL 3.0
|
|
|
|
|
|
However if your constol is being hosted in Internet Explorer - that won't work.
The "trick" in IE is to find the IHTMLObjectElement that represents your ActiveX control & change it's height / width. This will cause IE to adjust it's layout & resize your ActiveX control's window.
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
Jason De Arte wrote:
However if your constol is being hosted in Internet Explorer - that won't work
Are you sure ?
In fact I used this in IE6 and worked fine !!
does this change for other IE versions ?
|
|
|
|
|
I am as certain of that just as I am certain of my ability to spell the most common of words.
constol d'oh!
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
Dear Sirs,
Would you be so kind as to suggest me how it is possible to make IE Toolbar in your sample multiline. I tried SetRows() but it does not help me(of course I used TBSTYLE_WRAPABLE). I have read similar article here about problems with SetRows() in a simple floating Toolbar, it was solved be resizing parent control (or so?). I also had no luck in this approach. I always getting one line (but seems to me SetRows return correct coordinates as it should be to display the whole toolbar).
By the way, I used cmnctrl1 sample from MSDN and here SetRows works to set 2 lines(but not 3) even without TBSTYLE_WRAPABLE.
Best Regards,
Igor
|
|
|
|
|
I'm mentally preparing myself to start using std::vector instead of C-style arrays when interacting with legacy C APIs like the Win32 API. I mean to use &vec[0] to pass a pointer to a writable buffer to the APIs, but I wonder if &vec.front() is enough (I'd prefer it to be so).
In the std implementation we use (the one by Plauger), &vec[0] and &vec.front() evaluates to the equivalent result. Is it guaranteed to be so, or is one of them preferred over the other in this case?
Thanks for any input!
--
The Blog: Bits and Pieces
|
|
|
|
|
Both formulations are the same, and guaranteed to be so.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_subclas3.asp
Note Do not superclass the scroll bar control class because Windows uses the class name to produce the correct behavior for scroll bars.
But I cannot find any special code that handle the scrollbar in ATL.
|
|
|
|
|
You can subclass the scrollbar. Subclassing doesn't affect the class name. The article mentions that superclassing scrollbars don't work.
I.e., create the scrollbar, and then subclass it. See CWindowImpl::SubclassWindow() .
retinoscopy wrote:
But I cannot find any special code that handle the scrollbar in ATL.
Scrollbars are usually handled by intercepting WM_HSCROLL and WS_VSCROLL . When the scrollbar is manipulated by the user, it sends either of those messages, depending on its orientation, to its parent window. Windows can be created using the WS_HSCROLL and WS_VSCROLL window styles, which will automatically add scrollbars to the window. This is done by windows itself, and not ATL (MFC nor WTL for that matter).
See this[^] for information about scroll bars, and then take a look at either CWindowImpl::SubclassWindow (to implement a class which handles the subclassing), or see CContainedWindowT[^] (to intercept scroll bar messages in another class' message map).
If you haven't already, take a look at WTL, as it makes windowing with ATL a lot easier.
--
...Coca Cola, sometimes war...
|
|
|
|
|
Thank you for you timely reply.
|
|
|
|
|
I don't have the WTL yet, but I will download it to look into the code.
I wonder why the scrollbar must be handled differently from all other controls, i.e. cannot be superclassed? Suppose that I want to create a scrollbar control and I want intercept all windows messages sent to it, if I cannot superclass it, I have to globally subclass it, otherwise I have to setup some CBT hook before creating the control. If I globally subclass the scrollbar, however, I think I have to undo the subclassing of all scrollbar that are created (just after I globally subclass the scrollbar control) by another threads from some DLLs made by other people.
|
|
|
|
|
retinoscopy wrote:
I don't have the WTL yet, but I will download it to look into the code.
WTL is sort of like MFC, but very much ATLish. WTL provides all the standard controls with CWindow-derived counter parts, as well as a couple of controls implemented in WTL (CWindowImpl-derived). For the most part, the MFC docs are valid.
retinoscopy wrote:
I wonder why the scrollbar must be handled differently from all other controls, i.e. cannot be superclassed?
Probably due to some laziness of a Microsoft hacker It was probably a tradeoff they made to make some implementation aspect easier.
--
...Coca Cola, sometimes war...
|
|
|
|
|
Hi I've basically created a Class called a Session which uses the STL <vector> container to Add 'Jobs objects'. The Job objects add further record objects.
The class as it stands is working fine.
What i want is to write the Session object to a file.
then the next time the app starts i want to read back in the class data from the file.
What i've tried:
1:
I've played with File Mapping, and it seems fine with structures but when i try it with my class using STL, it falls over.
2:
ofstream using the binary flag. - this seems to write it away ok but i have real trouble reading it back in.
Have you had any experience writing a class object to a file that uses the STL?
thanks in advance
Carl
Assemblysoft.com
|
|
|
|