|
Well spotted. An excellent bit of remote diagnosis. That's exactly what I didn't do. I selected the wrong one. Thanks.
Dave
|
|
|
|
|
I made a generic purpose windows class as follows.
template< class CExtBaseWnd = CWnd>
class CChartWndParent : public CExtBaseWnd
{
....
CMyClass m_classX;
}
But I also wanna use my custom class m_classX as a member variable.
This class is unfortunate separated with h/cpp, so failed to compile..
Is there any way of compiling this class?
|
|
|
|
|
You should be able to use it by adding a forward declaration of CMyClass above the definition of the CChartWndParent class.
<br />
class CMyClass;<br />
<br />
template< class CExtBaseWnd = CWnd><br />
class CChartWndParent : public CExtBaseWnd<br />
{<br />
....<br />
CMyClass m_classX;<br />
}<br />
|
|
|
|
|
This wouldn't work. If you want to use forward declarations, you must declare m_classX member as pointer to CMyClass .
(A stupid question: Why you cannot include the header file, where CMyClass is defined?)
Robert-Antonio
Love, truth and electric traction must gain victory over hate, lie
and diesel traction.
|
|
|
|
|
Hi All!
Are there D3D templates for WTL?
P.S. I'm lazy to write it
|
|
|
|
|
I learn to create ActiveX project to use in C#. I want to use mciSendString create some procedure same as Open, Play , Stop.
somebody can help me write this code step by step, or send to me your code.
thanks.
Nho'c Ti`
|
|
|
|
|
Some time ago, I tried using a vector to read from a file as follows:
vector<float> vec;
vec.reserve( 256 );
vector<float>::iterator it = vec.begin();
_read( m_FH, reinterpret_cast<unsigned char*>(it), 256 );
Unfortunately, vec.size() = 0, even though the elements could be accessed using vec[] or vec.at(). At the time, I couldn't find a way around this problem. vec.resize(256) didn't work because this calls size() and all the elements are reinitialised to 0.0.
Other than vec.assign(256), can this problem be resolved - or is this just a bad idea in the first instance?
John
|
|
|
|
|
|
Hello everyone
I have a wtl(VC6.0 and wtl7.1) project and a mfc dll.(not UNICODE)
in the mfc dll,
LPSTR a;
a = new TCHAR(nLen + 1);
memcpy(a, otherstr, nLen * sizeof(TCHAR));
a[nLen] = _T('\0');
in the wtl project, I want to free it as the following:
delete a;
but the program is died.
Could you tell me how to free it?
Thank you.
-Freehawk
|
|
|
|
|
a = new TCHAR [nLen + 1]; //mistake #1
delete [] a; // mistake #2
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thank you for reply.
How to modify it?
-Freehawk
|
|
|
|
|
Well, you're trashing your stack due to the new[] bug that's been pointed out.
After you fix that, the problem becomes one of where is the memory being allocated? Unless you can be sure that both modules are using the same heap, you can't alloc in one module and free in the other. Because MFC has its own spiffy memory management, it probably has its own heap(s).
The way I usually do it is to alloc with CoTaskMemAlloc() and free with CoTaskMemFree() . Those use an allocator that the entire process can access.
[edit]Actually, it's not doing anything to the stack, since the memory is on the heap. It was late when I wrote that The code does write past the end of an allocated block of memory, though.[/edit]
--Mike--
Personal stuff:: Ericahist Updated Feb 6! | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
Actual sign at the laundromat I go to: "No tinting or dying."
|
|
|
|
|
Ack, I didn't even notice that Michael, thanks.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
try:
LPTSTR a; //TCHAR* a
...
delete[] a;
|
|
|
|
|
There are some ATL templates and macros that help catch COM events.
As IDispEventSimpleImpl, SINK_ENTRY_INFO etc.
But what I must to do if I do not know all events before a program start.
For example, there are Outlook::ItemsEvent for Outlook folders. I can catch any one. But I want catch all to one function. How can I register events dynamically?
Your ideas?
================================
My home is here!
|
|
|
|
|
Brigsoft wrote:
But what I must to do if I do not know all events before a program start.
Then you're in for a rough ride. COM events are either tied to a vtable entry (non-dispinterface source) or to a DISPID (dispinterace source). In both cases, the events are tied to an interface ID. You must know in advance what you're dealing with. Of course, one could devise a more dynamic homebrew event scheme - but alas, that's not the case here. COM events are as static as stone.
Brigsoft wrote:
But I want catch all to one function.
You can do this quite easily if the source interface is a dispinterface. Simply implement the dispinterface "manually" in a separate class like this:
template <typename T, typename SourceInterface, int ID>
class CSourceInterfaceImpl {
public:
HRESULT Init() {
...
}
void Finalize() {
}
STDMETHOD(GetIDsOfNames)(...) {
}
STDMETHOD(GetTypeInfo)(...) {
}
STDMETHOD(GetTypeInfoCount)(...) {
}
STDMETHOD(Invoke)(...) {
return static_cast<T>(this)->EventInvocation(
ID,
...
);
}
};
#define ID_FOR_EVENTS_X 1
#define ID_FOR_EVENTS_Y 2
#define ID_FOR_EVENTS_Z 3
class ATL_NO_VTABLE CMyCOMClass :
public ...,
public CSourceInterfaceImpl<CMyCOMClass, ISourceX, ID_FOR_EVENTS_X>,
public CSourceInterfaceImpl<CMyCOMClass, ISourceY, ID_FOR_EVENTS_Y>,
public CSourceInterfaceImpl<CMyCOMClass, ISourceZ, ID_FOR_EVENTS_Z>
{
...
HRESULT FinalConstruct() {
HRESULT hr;
hr = CSourceInterfaceImpl<CMyCOMClass, ISourceX, ID_FOR_EVENTS_X>::Init();
hr = CSourceInterfaceImpl<CMyCOMClass, ISourceY, ID_FOR_EVENTS_Y>::Init();
hr = CSourceInterfaceImpl<CMyCOMClass, ISourceZ, ID_FOR_EVENTS_Z>::Init();
}
void FinalRelease() {
CSourceInterfaceImpl<CMyCOMClass, ISourceX, ID_FOR_EVENTS_X>::Finalize();
CSourceInterfaceImpl<CMyCOMClass, ISourceY, ID_FOR_EVENTS_Y>::Finalize();
CSourceInterfaceImpl<CMyCOMClass, ISourceZ, ID_FOR_EVENTS_Z>::Finalize();
}
HRESULT EventInvocation(int nId, ... ) {
switch(nId) {
case ID_FOR_EVENTS_X:
break;
case ID_FOR_EVENTS_Y:
break;
case ID_FOR_EVENTS_Z:
break;
default:
ATLASSERT(false);
return E_NOTIMPL;
}
}
}
Caveat Emptor; I have not tried this in a compiler. As you can see, I've left a lot of implementation details out of the picture. But I think the "theory" is sound, and it achieves what you are requesting. Filling in the missing pieces should be trivial if you look up the functions I mention in MSDN and have at least some experience with COM/IDispatch.
Did I make any sense? Did I understand your problem (at all?)
--
Gott weiß ich will kein Engel sein.
|
|
|
|
|
Suppose i have got a struct with vectors inside
<code>
struct A
{
int a;
vector<int> b;
};
vector <A> b;
Is this safe or do i have to write a copy contructor ?
"Just looking for loopholes." W. C. Fields American actor, 1880-1946, explaining why he was reading the Bible on his deathbed.
|
|
|
|
|
Perfectly safe. The compiler will automatically generate a copy constructor using what's defined by the aggregated objects.
Generally, a copy constructor is only needed if the structure contains pointers, and aliasing them would be a bad ideatm.
Imagine this scenario:
struct S {
int* p;
S() { p = new int[10]; }
~S() { delete [] p; }
};
{
S a;
S b(a);
}
In cases like this it's necessary to write your own copy constructor which either a) makes a complete copy of the array inside the object being copied from, or b) you implement some reference counting mechanism. There are gigantic semantic differences between the two cases, as you may understand. It's basically a question of "by value" or "by reference". If I chose b), any modification to let's say a.p[0] would be visible in b.p[0] .
In your example, std::vector has a well defined copy constructor. By the way, std::vector implements "by value" semantics. Anyway, the C++ compiler will always automatically generate a copy constructor if, and only if, you omit one. The generated code would look something like this:
A::A(const A& other) : a(other.a), b(other.b) { } . And how a and b are copied is defined by their copy constructors.
--
Gott weiß ich will kein Engel sein.
|
|
|
|
|
I need to show more than two views in a sdi frame window.
My code like this:
<br />
RECT rc;<br />
GetClientRect(&rc);<br />
m_hWndClient = m_view.Create(m_hWnd,rc);<br />
m_view.ShowWindow(SW_SHOW);<br />
m_view.SetFocus();<br />
m_view2.ShowWindow(SW_HIDE);<br />
It can show m_view2,but not like default view.
How can I switch views correctly??
opening view with wild mind
|
|
|
|
|
You need to call Create() on m_view2. Then, in your code that switches the view, you need to hide m_view, show m_view2, and then set m_hWndClient to m_view2.
|
|
|
|
|
To add to what TFrancis said, after setting m_hWndClient , call UpdateLayout() to make sure the view is sized correctly to fit the client area of the frame.
--Mike--
Personal stuff:: Ericahist Updated Feb 6! | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
Hi!
I am starting from ground up. I am with simple Win32 Application and I want add ATL functionality in it by fooling wizard. I planned:
1)a cpp file that has the same name as the project .
2)an ATL object map (the map can be empty, but it must be present).
3)an IDL file with the same name as the project and this file must have a Library block.
Need feedback on 2 and 3.
|
|
|
|
|
What kind of feedback?
That's how to fool the wizard. The easiest way to get examples of (2) and (3) if that's what you need is to run the VC++ AppWizard and select ATL. That will generate you the appropriate files, and you can cut and paste from there.
I've done this before, and it works.
Steve S
|
|
|
|
|
Problem with (3) is with
the entire IDL file.As it should not compile. So What modifications should I do in the project settings when I add it to the project.
And working on Ur copy paste tip. What should be the type (EXE or DLL )of ATL WORKSPACE.
Thanx for all that feedback. And feedback always for learning.
|
|
|
|
|
The IDL file can be as simple as this;
import "oaidl.idl";
import "ocidl.idl";
[
uuid(FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF),
version(1.0),
helpstring("myapp library")
]
library MyApp
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
};
You don't even need to use a different UUID, since you're not going to be registering it.
Your 'dummy' can be either, I tend to use DLL out of habit, since I write in-proc servers quite often
Steve S
|
|
|
|