|
s.reserve(n) makes sure that the string length can grow to at least n characters without reallocations. It doesn't have effect to the actual string length. You can use s.resize() to set the string length. There's no equivalent to GetBuffer() /ReleaseBuffer() , you can't directy manipulate the characters in the internal buffer.
|
|
|
|
|
markkuk wrote:
There's no equivalent to GetBuffer()/ReleaseBuffer(), you can't directy manipulate the characters in the internal buffer.
Thanks, that's what I thought. This is a pity as you have to waist time and code copying an STL string to a C string and back again at times. eg. When you call a function which only accepts a C string as a parameter, and the callee has an STL string.
Thanks for your help.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I noticed WTL programs often have implementation in the header files, I guess this is the convention ?
I noticed the option in VS.NET project creation to create .cpp files, but by defualt it is not checked.
I guess I should conform and implement in header files, correct ?
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Two reasons for that. First, with template classes, all the code has to be in a header file (well, technically that's not true, but most people do it that way). And second, when you use ClassView to add message handlers, it puts the code in the header file.
I personally hate this because it makes the header file a pain to maintain, and results in longer builds because you'll be changing header files all the time as you're developing.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I personally hate this because it makes the header file a pain to maintain, and results in longer builds because you'll be changing header files all the time as you're developing.
That is the big flaw in the design. It can be a huge problem for large scale projects.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hello,
I created a COM DLL. (with VC++.NET but this is not important).
And created some assembly the has a function, that create instance from the
COM class, and call some function from the COM object.
When I call the functions of the assembly as simple as possible, from some
console app, this is work.!
But if I do it via remoting, it isn't work!! and give this exception:
Unhandled Exception: System.InvalidCastException: QueryInterface for
interface ScreenCamaraASM.IScreenCapturing failed.
Server stack trace:
at ScreenCamaraASM.CScreenCapturingClass.GetNumber()
at RCServerNP.RCServer.GetScreenPicture() in d:\mydocs\visual studio
projects
\remotecommunication\rcserver\rcserver.cs:line 24
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(M
ethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInC
ontext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgDa
ta, Int32 type)
at RCServerNP.RCServer.GetScreenPicture() in d:\mydocs\visual studio
projects
\remotecommunication\rcserver\rcserver.cs:line 21
at Testing.Class1.Main(String[] args) in D:\MyDocs\Visual Studio
Projects\Rem
oteCommunication\Testing\Class1.cs:line 36.
Please, any solution?
Thank's, Itay.
|
|
|
|
|
Hi, everyone!
Here is an example about the usage of
bind2nd. But I do not understand what the
function is doing. I have used MSDN to find
help, but still puzzled because there is only
a little of material on the topic.
Who can tell me what is the function doing in
the following example?
--------
vector<int> v;
// fill v with 4 6 10 3 13 2
int bound = 5;
replace_if (v.begin(), v.end(), bind2nd (less<int>(), bound), bound);
// v: 5 6 10 5 13 5
--------
Thanks in advance,
George
|
|
|
|
|
In this particular case bind2nd is function that uses comparison function (less by default) to compare any argument to value of 'bound'.
So for each element in v.begin() ... v.end() range replace_if calls bind2nd and if true returned it replaces element value with value of 'bound'
Your example:
vector v;
// fill v with 4 6 10 3 13 2
int bound = 5;
replace_if (v.begin(), v.end(), bind2nd (less(), bound), bound);
//////////////////////////////////////////
another way(not the best):
const int bound = 5;
for(vector::size_type i = 0, size = v.size();i< size;++i)
{
if(v[i] <= bound)
v[i] = bound;
}
+
|
|
|
|
|
Thanks, AlexO buddie!
George
|
|
|
|
|
Hello guys,
Where can I find a good implementation of IClassFactory2 , whitout using that DECLARE_CLASSFACTORY2(CMyLicense) macro, to perform licensing capabilities to my software?
Thanks in advance,
Raphael Amorim Dantas Leite
VC++, VB, Java, .NET and eMbedded Programmer
|
|
|
|
|
I want to use the internet explorer inside my application. This works fine:
AtlAxWinInit();
HWND hwndChild=::CreateWindow( "AtlAxWin",
"Shell.Explorer.1",
WS_CHILD|WS_VISIBLE,
0,0,0,0,
hwnd,NULL,
::GetModuleHandle(NULL),
NULL);
IUnknown *pUnk=NULL;
AtlAxGetControl(hwndChild,&pUnk);
CComPtr<IWebBrowser2> spBrowser;
pUnk->QueryInterface(IID_IWebBrowser2,(void**)&spBrowser);
if(spBrowser)
spBrowser->put_Visible(VARIANT_TRUE);
But, I want this to be more abstract. How can I use the interface IDispatch instead.
My attempt to abstract it, returned a DISP_E_UNKNOWNNAME while calling GetIDsOfNames with "Visible" (it IS a member of IWebBrowser2). It has to be something like that...
using: [VISUAL STUDIO 6.0] [WIN98/2]
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
It is easily possible. I never tried it on IWebBrowser2 , but it should work on any IDispatch derived interface.
For your GetIDsOfNames , you have to check, if all flags was set properly.
Anyway, there is a helper classes in ATL to doing dispatch calls, if you don't want to program it yourself as a mental excersise.
CComDispatchDriver dispDrv( ipDispInterface );<br />
<br />
dispDrv.PutPropertyByName( bstrName, &variantValue );<br />
dispDrv.Invoke0( bstrName, NULL );
etc...
|
|
|
|
|
I've tried that CComDispatchDriver. <<atlcom.h>> is needed for that.
Now, during compilation, I receive errors from atlcom.h. like these:
VC98\ATL\INCLUDE\atlcom.h(2945) : error C2065: '_Module' : undeclared identifier
VC98\ATL\INCLUDE\atlcom.h(2945) : error C2228: left of '.Lock' must have class/struct/union type
...
My includes are like these:
#pragma comment(lib,"atl.lib")
#include <<atldef.h>>
#include <<atlbase.h>>
#define _ATL_DLL_IMPL
#include <<atliface.h>>
#include <<exdisp.h>>
#include <<atlcom.h>>
What have I done now?
But, frankly, all of the params in my call to getidsfromnames are valid (used it already to control an excel application). IWebBrowser2 doesn't seem to have "Visible", "Quit", ... but I saw it using the typeview tool.
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
the _Module refers to the current DLL (module). I no way how to test the include stuff on my compiler now, but generally somewhere in your code is extern CComModule _Module;
and the #include <atlcom.h> must stay behind that definition from the point of view of compiler (this is for VC6, I assume you have)
But the second part is really weird. Fortunatelly I had some project with WebBrowser manipulation, so I fired it up and tested the following code:
CComPtr<IWebBrowser2> m_spBrowser;<br />
CComDispatchDriver drva( m_spBrowser );<br />
_variant_t vtOut;<br />
drva.GetPropertyByName( L"visible", &vtOut );
on the end I had in vtOut vt=VT_BOOL value=VARIANT_TRUE
then at least on my IE6 the property is included = the way you are trying to go is right.
I would suggest to play with the headers a bit, or if it will take more than 10 minutes look to the srcs of the CComDispatchDriver and cut only the parts you need (but duplicating code is really the last chance solution )
|
|
|
|
|
I've included the atlcom.h just above my function and it works now. BIG TNX
Two remarks however...
1: you used L"visible" instead of L"Visible". Aren't those parameters case sensitive?
2: I've found a page on msdn about CComDispatchDriver, but it's not the dispatcher you showed me. It has GetProperty(), PutProperty() and Release(). That's all. So, which one are you talking about? Is it an extended dispatcher or what?
This is the link I've found http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_atl_ccomdispatchdriver.asp[^]
... and one again, thank you. (but the failure in getIdsFromNames(...) remains very strange )
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
1. these should not be case sensitive, at least the IDispatch requires that (else the VB Script will be also case sensitive). In fact developer can change it while implementing the IDispatch in his object, but I don't believe that Microsoft will break it's own rulez.
2. probably this is some older version than my, I am using the ATL7, so might be that this class is updated.
|
|
|
|
|
My euphoria came to quick. It still doesn't work.
the 0x80020006 error is still there...
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
I've tried some things, and this is the problem:
this works:
CComPtr<IWebBrowser2> m_spBrowser;<br />
pUnk->QueryInterface(IID_IWebBrowser2,(void**)&m_spBrowser);<br />
m_spBrowser->put_Visible(VARIANT_TRUE);
but this doesn't work:
CComPtr<IWebBrowser2> m_spBrowser;<br />
pUnk->QueryInterface(IID_IWebBrowser2,(void**)&m_spBrowser);<br />
CComDispatchDriver dispDrv(m_spBrowser);<br />
VARIANT x;<br />
VariantInit(&x);<br />
x.vt=VT_BOOL;<br />
x.boolVal=VARIANT_TRUE;<br />
hr=dispDrv.SetPropertyByName(L"Visible",&x);
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
Well, honestly I have nearly no idea, where the problem can be. Theoretically there can be problems with defining the LOCALE_USER_DEFAULT in the GetIDsOfNames selecting some other language for dispatch, but I do not believe, that someone uses that in real work , therefore I would assume this parameter is normally ignored.
Also I would check the code on another machine, if there is not a problem with instalation.
Anyway for your reference - in my project, where the get/put visible works, I am inicializing the WebBrowser control by following sequence:
HWND hWT = m_iewnd.Create( m_hWnd, rc, NULL, WS_CHILD + WS_VISIBLE );<br />
<br />
m_iewnd.CreateControl( "file://somewhere.htm" );<br />
<br />
m_iewnd.QueryControl( &m_spBrowser );<br />
m_iewnd.SetExternalDispatch( (IDispatch*)this );<br />
<br />
CComDispatchDriver drv( m_spBrowser );<br />
_variant_t vtOut;<br />
drv.GetPropertyByName( L"visible", &vtOut );<br />
<br />
|
|
|
|
|
Hi, everyone!
My STL tutorial said,
--------
A raw_storage_iterator enables algorithms to
store results into uninitialized memory.
--------
But I do not know what means uninitialized memory.
Who can give me an explanation of what means
uninitialized memory? Here are two examples given
by the tutorial. Please give me the explanation through
the following examples.
Example 1:
--------
vector<int> a (2, 5);
vector<int> b (2, 7);
int *c = allocate((ptrdiff_t) a.size(), (int*)0 );
transform (a.begin(), a.end(), b.begin(),
raw_storage_iterator<int*, int> (c), plus<int>() );
copy (&c[0], &c[2], ostream_iterator<int> (cout, " ") );
--------
Example 2:
--------
template <class T1, class T2>
inline void construct(T1* p, const T2& value) {
new (p) T1(value);
}
int a[10] = {1, 2, 3, 4, 5};
copy (&a[0], &a[5], raw_storage_iterator<int*, int> (&a[5]) );
--------
Thanks in advance,
George
|
|
|
|
|
Uninitialized storage is basically storage that has been allocated but not initialized. Imagine doing a "new [n] char". You have allocated char array, but the contents of the array is uninitialized.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
In my first example, I do not understand why the
storage that has been allocated but not initialized.
Can you give me an explanation?
Thanks in advance,
George
|
|
|
|
|
The allocate method is just a fancy malloc. All it does is reserve the space, it doesn't actually do anything to the memory.
It is sort of like building a road. First you must acquire the land to build the road. This is the allocation step. But just because you have acquired the land doesn't mean you have a road. The land is still "uninitialized". It isn't until you actually build the road that you have a fully "initialized" road.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
I do not understand why in example 1, (int*)0 is
used as the second parameter of allocate. What is the
meaning of (int*)0 here?
Thanks in advance,
George
|
|
|
|
|
First of all, a remark: the tutorial you're using is grossly outdated, there is no global allocate function, since C++ 98' standard this function is a member of std::allocator .
Now, the second parameter is a hint pointer, optionally used by the allocation engine to improve performance. If no hint is to be provided, the null pointer (0) can be passed. Now, consider the situation:
allocate(1,0); This cannot work because allocate does not know which kind of type you're allocating memory for. The ambiguity can be solved in one of these two forms:
allocate<int>(1,0);
allocate(1,(int*)0);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|