|
Thanks for all your help Stuart
It's working fine!
I'm trying to come up with some macros to make it configurable, but the inability to redefine a #define as part of another #define doesn't seem to be possible.
|
|
|
|
|
Stone Free wrote: I'm trying to come up with some macros to make it configurable, but the inability to redefine a #define as part of another #define doesn't seem to be possible.
No, it's not - the pre-processor's not that clever (probably just as well, really)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I created a ATL project with a modeless dialog. The ATL dll is called by a Delphi program. When the Delphi program invokes modeless dialog, it also creates a model dialog itself, so my modeless dialog in alt dell is insulated by the delphi model dialog in message sending.
|
|
|
|
|
That's nice.
Do you actually have a question?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have ATL web service Written in C++ long back.
We have already C++ web client using soap toolkit.
Now we need C++ web client Without Soap .
What are the solutions ?
Is it possible without .Net interface. That is it should work with old Vc++
6.0 IDE also.
|
|
|
|
|
ERLN wrote: Is it possible without .Net interface
Of course it is. If you're using MFC for the client (and MFC is a reasonable implementation route), then you probably want to get familiar with CHttpConnection [^] and CHttpFile [^].
Another route (which I used when writing a web service client in Haskell[^]) is to use libcurl[^] through its C++ bindings[^].
In both cases, you just need to construct an appropriate request, send it and read the response through the HTTP connection.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have two vectors holding different classes. The first class contains only data of integer/double type. I can create a vector of the first class, access it, manipulate it, no problems.
The second class contains a combination of data and several pointers to allocated storage space. The space is allocated on the fly as needed. The destructor of the class frees the space. The problem arises when adding new instances of the class to the vector. If there isn't enough space in the vector, the vector class clones itself, adds space, and the erases the old vector. Unfortunately in erasing "old" vector, it frees the storage space and the program crashes because the storage pointers are invalid.
Creating a vector of pointers to the class solves the problem but would involve a massive re-write of code.
Anyone have any suggestions how to handle this? Is there a graceful way to handle pointers inside the class when you don't know when the class will be destroyed by the container?
|
|
|
|
|
Having a copy constructor for the second class should solve the problem.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
In addition to Superman's answer - you need to create an assignment operator that manages your memory as well.
Something like this:
class A
{
public:
A(int i) : pi_(new int(i)) {}
A(const A& a) : pi_(new int(*a.pi_)) {}
A& operator=(const A& a)
{
*pi_ = *a.pi_;
}
~A() { delete pi_; }
private:
int* pi_;
};
The other way round this is to manage your storage with (for example) Boost shared pointers[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
When would the assignment operator be used?
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Any method that rearranges items in the vector. An example - the erase method (if you erase any except the last element).
Consider this example code:
#include <iostream>
#include <vector>
class Test
{
public:
Test() { std::cout << "Test::Test()\n"; }
Test( Test const& ) { std::cout << "Test::Test( Test const& )\n"; }
Test& operator=( Test const& ) { std::cout << "Test::operator=( Test const& )\n"; return *this; }
~Test() { std::cout << "Test::~Test()\n"; }
};
int main (int argc, char const* argv[])
{
std::vector<Test> a;
std::cout << "push_back\n";
a.push_back(Test());
a.push_back(Test());
a.push_back(Test());
std::cout << "iterator\n";
std::vector<Test>::iterator it = a.begin();
++it;
std::cout << "erase\n";
a.erase(it);
return 0;
}
It produces this output (with VS2008):
push_back
Test::Test()
Test::Test( Test const& )
Test::~Test()
Test::Test()
Test::Test( Test const& )
Test::Test( Test const& )
Test::~Test()
Test::~Test()
Test::Test()
Test::Test( Test const& )
Test::Test( Test const& )
Test::Test( Test const& )
Test::~Test()
Test::~Test()
Test::~Test()
iterator
erase
Test::operator=( Test const& )
Test::~Test()
Test::~Test()
Test::~Test()
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Wow, that explains a lot of the weird performance issues. Constructing large vectors (200-500) entries is what's taking up so much time. I am going with the vector of pointers because de-referencing them is fast compared to copying what can turn into very large classes. I am also reserving enough space so they won't constantly be copying themselves.
Thanks very much for the code example, it was very illuminating.
|
|
|
|
|
mjackson11 wrote: Constructing large vectors (200-500) entries is what's taking up so much time
Large? That's not large
I've tended to use vector s of Boost.SharedPointers[^] in the past, so I don't need to worry about deallocation (and also, it's easier to create indices into that vector, as you can just copy and re-sort the vector of smart pointers). That's been good for vectors with upwards of 10000 elements.
Another (and probably better) alternative would be a Boost pointer container[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. That is new information.
So if I have 20 object stored in a vector and I delete the first, operator= is called 19 times!!!
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Yep - that's why rvalue references[^] are being introduced in C++0x - they allow the introduction of 'move semantics', which allows the elimination of unnecessary copies like that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I had read about rvalue references and I'm able to admire it more now.
Thanks
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hello friend,
I need to show one small "Please Wait.." image screen whenewer some back end processing is in progress.
For e.g. whenever user changing his ip adress and port, before going checking and establishing the connection, I want to show a "Please wait ..." image.But while going for connection browser gets hangs because of connection and after connection checking is completed. It goes for next page.
I am using IWebBrowser2 interface through which, I am getting pointer of browser.Then I am using IHTMLELement through which I am getting pointer of current html content.After that I am using IHTMLImageElement to add one img tag inside current html page for please wait screen.
Please give me some suggestions.
Waiting for the positive reply
Thank you.
abhi
|
|
|
|
|
AbhijitAkude wrote: I am using IWebBrowser2 interface
From what? You did not provide any context.
|
|
|
|
|
Hi,
I am porting a VC6.0 code to VS2008. I have a class with following decalration
template<class>
type lowerBound,
type upperBound>
class TempClass
{
public:
TempClass(void );
//virtual ~TempClass(void);
protected:
type mValue;
};
template<class type="" lowerbound="" upperbound="">
TempClass<type,>::TempClass(void)
{
// TBI
}
I am declaring a pointer to this class as
TempClass <float, 1,2> *pT1;
I am getting the error
error C2993: 'float' : illegal type for non-type template parameter 'lowerBound'
error C2993: 'float' : illegal type for non-type template parameter 'upperBound'
how can I fix this problem?
I cannot use the pointers for lowerBound, upperBound.
|
|
|
|
|
Directly? You can't - C++ requires integral types for non-type template parameters.
How about supplying the parameters as ints and casting to the required type in the class, like this?
template<class Type, int LowerBound, int HigherBound>
class TempClass { ... };
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
template<class lowerBoundType, class upperBoundType>
Class TempClass
{
…
};
OR
template<typename lowerBoundType, typename upperBoundType>
Class TempClass
{
…
};
Reasonable Declarations:
TempClass<float, float>* pT1.
TempClass<double, double>* pT1.
TempClass<int, int>* pT1.
If both upper and lower bounds use the same type, which would make since, then a more reasonable template would be:
template<typename boundryType>
Class TempClass
{
…
};
Declaration:
TempClass<float>* pT1.
<div class="ForumSig">INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra</div>
|
|
|
|
|
Hi All,
I have a Multithreaded Application in which i am trying to open a Compounded Stream using OpenStream method of IStream interface in a following manner:
CComPtr<IStream> ptrDataStream;
hr = ptrStorage->OpenStream(strDataStreamName,0,STGM_READ | STGM_SHARE_EXCLUSIVE,0,&ptrDataStream);
if (hr)
return hr;
The problem which I am facing is that at some time not always OpenStream return Access Denied error. After getting this error I added a lock in this function which is released at the end of the function, but this change doesn't effect the error .
Please help me in this regard.
Thanks in Advance
Ankush Gupta
|
|
|
|
|
I use practically the same code when opening a stream from withing a compound storage file which is single threaded and have no problems. Presumably then this must be down to something keeping the stream open and the 'exclusive' access flag causing access denied to be returned. Sorry if I'm restating the obvious. Maybe a file not closed properly?
|
|
|
|
|
Thanks for the reply.
Is there any way of closing the stream?
I looked into the IStorage/IStream interfaces and found that there is no method of closing the storage or stream, but there exist one DestroyElement method. Can it be of any use?? Or there any workaround to fixup the issue.
Thanks
|
|
|
|
|
Code of the function where I am getting the error
CComQIPtr<IStorage> ptrStorage;
CStringW strPage;
HRESULT hr = FindStorage(storage,strName,strPage,ptrStorage);
if FAILED(hr)
return hr;
CComPtr<IStream> ptrMetaStream;
hr = ptrStorage->OpenStream(strPage,0,STGM_READ | STGM_SHARE_EXCLUSIVE,0,&ptrMetaStream);
if FAILED(hr)
return hr;
GUID clsidPageType;
hr = ptrMetaStream->Read(&clsidPageType,sizeof(clsidPageType),NULL);
if FAILED(hr)
return hr;
GUID clsidEntityType;
hr = ptrMetaStream->Read(&clsidEntityType,sizeof(clsidEntityType),NULL);
if FAILED(hr)
return hr;
CComBSTR strDataStreamName;
hr = strDataStreamName.ReadFromStream(ptrMetaStream);
if FAILED(hr)
return hr;
CComPtr<IStream> ptrDataStream;
hr = ptrStorage->OpenStream(strDataStreamName,0,STGM_READ | STGM_SHARE_EXCLUSIVE,0,&ptrDataStream);
if FAILED(hr)
return hr;
CComBSTR strFullName;
hr = strFullName.ReadFromStream(ptrMetaStream);
if FAILED(hr)
return hr;
CComBSTR strMimeType;
hr = strMimeType.ReadFromStream(ptrMetaStream);
if FAILED(hr)
return hr;
LONG nCodePage;
hr = ptrMetaStream->Read(&nCodePage,sizeof(nCodePage),NULL);
if FAILED(hr)
return hr;
CComPtr<IPage> ptrPage;
hr = ptrPage.CoCreateInstance(clsidPageType);
if FAILED(hr)
return hr;
hr = ptrPage->Load(lcid,ptrMetaStream,ptrDataStream,strFullName,strMimeType,clsidEntityType,nCodePage);
if FAILED(hr)
return hr;
hr = ptrPage.CopyTo(ppPage);
if FAILED(hr)
return hr;
|
|
|
|