|
Thank pal.
You help a lot.
Best regards.
Maer
|
|
|
|
|
I have a CList of ptrs (ptrList) to CItems in a supporting class (CGroup) of my program, with an override of SerializeElements. This works fine until I add a second CArray or CList of the same type of ptr as a member of CMainframe. Then I get a linker error:
Group.obj : error LNK2005: "void __stdcall SerializeElements(class CArchive &,class CItem * *,int)" (?SerializeElements@@YGXAAVCArchive@@PAPAVCItem@@H@Z) already defined in MainFrm.obj
I gather that the linker is unable to deal with an alternate version of the SerializeElements function, but how do I get around this while keeping the SerializeElements override in the CGroup.cpp file?
Any help is appreciated.
Thanks
WJ
|
|
|
|
|
So you have two definitions of SerializeElements(CArchive&, CItem **, int)? Do they differ?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I have only created one definition of SerializeElements, the one in class CGroup. This was needed to serialize the items pointed to rather than the ptrs in the list. I'm guessing that the linker is somehow first linking the default version when it encounters it in CMainFrame, then is unable to resolve what it percieves as an alternate version ( which does differ in function ) in CGroup.
Actually, the SerializeElements method will never be used in the MainFrame Array, but the linker doesn't know that.
--WJ
|
|
|
|
|
You should make one or both SerializeElements static. 'Static' function is visible only within the containing .cpp or .c file.
The other solution would be putting these functions in unnamed namespace.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
How do I wait for a worker thread to finish? I am trying to use WaitForSingleObject(), waiting on the thread handle, but it does not want to wait for the thread to finish. What else can I use? Or am I approaching this all wrong?
In my dialog based app's InitInstance() function I have this code
...
dlg.DoModal();
CWinThread *pThread = WriteLog (_T("GetSamples : Done"));
TRACE ("Wait for thread at 0x%08X\n", pThread);
WaitForSingleObject(pThread->m_hThread, WAIT_OBJECT_0);
TRACE ("Exiting\n");
return FALSE;
}
Here is my WriteLog() function
UINT WriteLogThreadFunction(LPVOID lp)
{
TRACE ("WriteLogThreadFunc() Start\n");
LPTSTR LogEntry = (LPTSTR)lp;
CMutex mutex(FALSE, _T("WriteLog - {AE4E28C0-84E6-11d5-B625-F80C283F7922}"));
CSingleLock lock(&mutex, FALSE);
lock.Lock();
CRotatingLog rl(_T("C:\\Bird_Log.txt"), 500, 100);
rl.AddLine(LogEntry);
delete[] LogEntry;
TRACE ("WriteLogThreadFunc() End\n");
return 0;
}
CWinThread* WriteLog (LPCTSTR EntryString)
{
COleDateTime dt = COleDateTime::GetCurrentTime();
CString LogEntry = dt.Format("%d/%m/%y %H:%M:%S - ");
#ifdef _DEBUG
LogEntry += _T("DEBUG - ");
#endif
LogEntry += EntryString;
LPTSTR String = new TCHAR[LogEntry.GetLength() + 1];
_tcscpy(String, LogEntry);
TRACE ("Starting WriteLogThreadFunc()\n");
return AfxBeginThread(WriteLogThreadFunction, (LPVOID)String);
}
And here is the debug output
Starting WriteLogThreadFunc()
Wait for thread at 0x00771CC0
Exiting
The thread 0xFFF552F3 has exited with code -1 (0xFFFFFFFF).
Detected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {4004} client block at 0x00771CC0, subtype 0, 112 bytes long.
a CWinThread object at $00771CC0, 112 bytes long
{4003} normal block at 0x00771820, 46 bytes long.
Data: <29/08/01 17:12:3> 32 39 2F 30 38 2F 30 31 20 31 37 3A 31 32 3A 33
Object dump complete.
The thread 0xFFF5443B has exited with code 2 (0x2).
TIA
Pete
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
The 2nd parameter in WaitForSingleObject is the number of milliseconds it should wait.
WAIT_OBJECT_0 is a possible return value.
I hate to be to critical but a quick look at the documentation would point this out.
|
|
|
|
|
I highly recommend getting the book Programming Windows with MFC by Jeff Prosise. The chapter on Threads and Thread Sychronization is very informative.
|
|
|
|
|
Hello,
Is it possible to derive one ATL COM Object from another? I've been trying to do so but VC++ doesn't want to let me or when it does CoCreateInstance tells me class not available. Anyone know of any good leads, articles about this. Thanks in advance.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Yes!!
Well, sort of. You can't derive anything from the actual coclass, but you can achieve nearly the same effect. Separate all of the implementation code into a separate class, templated on the type of the implemented interface, and derive the coclass from that. Since the implementation classes are not COM coclasses, they can be extended like normal C++ classes, and you can arrange these in a heirarchy to suit your needs. The idea is to put absolutely no source code in the COM coclass, it should inherit ALL of its functionality from the impl classes. This might look something like this:
// In your idl file:
interace IA : IDispatch
{
HRESULT Method1([out,retval] double* pVal);
}
interface IB : IA
{
HRESULT Method2([out,retval] double* pVal);
}
// The definition of your coclass for A:
class ATL_NO_VTABLE CA :
public CComObjectRootEx<ccomsinglethreadmodel>,
public CComCoClass<ca, &clsid_a="">,
public IDispatchImpl<iaimpl<ia>, &IID_IA, &LIBID_ABCDLib>
{
// etc.
}
// The definition of the coclass for B:
class ATL_NO_VTABLE CB :
public CComObjectRootEx<ccomsinglethreadmodel>,
public CComCoClass<cb, &clsid_b="">,
public IDispatchImpl<ibimpl<ib>, &IID_IB, &LIBID_ABCDLib>
{
// etc.
}
// The definition of the implementation class for A:
template<class base="">
class IAImpl : public Base
{
public:
IAImpl();
~IAImpl();
// Methods of IA
STDMETHOD(Method1)(/*[out, retval]*/ double* pVal);
};
// Implement the methods and stuff here . . .
// The definition of the implementation for B:
// B inherits stuff from A
template<class base="">
class IBImpl : public IAImpl<base />
{
public:
IBImpl();
~IBImpl();
// Methods of IB
STDMETHOD(Method2)(/*[out, retval]*/ double* pVal);
};
// Implement methods of B here
Anyway, one implementation can inherit stuff from another, and implementations of generic stuff can be put into base classes, etc., etc.
Someone else may be able to suggest other methods; this one has worked well for me.
Good Luck!
|
|
|
|
|
I would like to add an internet hyperlink to my homepage on the about dialog box of an application. I have seen this in other applications but can't find a code snipplet for it. Thanks for any help.
|
|
|
|
|
Look for the CHyperLink class on this site. I used it for precisely that purpose. Kinda cool.
|
|
|
|
|
WTL, which is included in the Platform SDK, has a CHyperLink class. There is also the Hyperlink class http://codeguru.earthweb.com/controls/hyperlink.shtml created by someone named Chris Maunder. Never heard of him.
I'm sure the code is also here but I couldn't find it. Chris?
|
|
|
|
|
Hi there,
I had previously asked but just to make sure that it doesn't go away into the back pages, how do you force a listctrl to keep focus after you click as oppose to after a return..This is all after performing a label edit.
|
|
|
|
|
Don't know for sure, but have you treid handling LVN_ENDLABELEDIT for the listctrl?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi All!
I have C++ custom control created as descendant from CWnd.
Is there any easy way to make ActiveX and/or DLL from it (best will be to do it automatically like in Delphi, but the only tool that promised that for VC++ is not working .
I understand how to build ActiveX and/or DLL from the scratch, but I want to have ONE source (to simplify maintanance) as C++ control, and some template/tool/whatever that will translate it to ActiveX or DLL each time I need update.
SY-
Kosta.
|
|
|
|
|
I had this problem a year ago, when I was trying to take a treectrl and listctrl from MDI into ActiveX.
The only way I could find was to build an MFC ActiveX that doesn't inherit
from any main MFC classes.
Then, I would include my header and cpp for the controls in the project and in its OnCreate Event of the ActiveX, create an instance of each item.
i.e.
in the ActiveX header,
CTreeCtrl MyTreeCtrl;
CListCtrl MyListCtrl;
and in OnCreate of the ActiveX:
MyTreeCtrl.Create(.....)
MyListCtrl.Create(.....)
So, it wasn't plug and play but i didn't have to do things from scratch
either.
|
|
|
|
|
But this will only make CTreeCtrl member of this ActiveX, and all methods, properties and events you'll need to put manually, like:
MyActiveX::DoSomething ()
{ MyCppControl.DoSomething();
}
Is that what you mean? If yes, I need something different. I.e.:
// my C++ control h file:
CMyControl : public CWnd
{ int DoSomething();
}
// my C++ control cpp file:
int CMyControl::DoSomething()
{ /* some processing here*/
}
// My ActiveX h file:
CMyActiveXControl : public CMyControl
{ // no redeclarations from CMyControl here
}
And than after compile I will have OCX where all public methods, properties and events will be available to other programs.
I understand, that simple declaration
CMyActiveXControl : public CMyControl
will not be correct, and I'm looking either for utility that will automatically generate code for CMyActiveXControl given code of CMyControl, or some declaration that will not require me to rewrite methods, properties and events in the cpp file for CMyActiveXControl (may be like CMyActiveXControl : public CMyControl, COleControl ???), or something else.
What I'm trying to avoid is maintaining two or three cpp files (for C++, ActiveX and DLL) that have identical code except declarations and, possible, function names (for example, COleControls has OnDraw instead of OnPaint).
Is it possible in MSVC++? (I know that in C++ Builder and Delphi they have tool allowing to do it automatically).
SY-
Kosta.
|
|
|
|
|
Hello,
I'm new to programing and I'm trying to use a ListBox control(report style).. I have read all the atricles in the ListBox areas and they have helped alot.. the problem I'm having is probably simple to resolve but I'm unable to find any info on it(well atleast examples).. I have a simple listbox(report style).. I'm able to populate it just fine.. I have 8 collumns and 3 rows with data in each field.. I need to pull the data from each field and assign each field with its own member variable.. so in the above example, I have created 24 CString type member variables (one for each field).. how do I pull the data/string from each field and assign it to the variable that I want? Can someone provide me with a little code.. I can understand that type of example better.. Thanks in advance.
Rob Jones
|
|
|
|
|
Why must you create variable for each field? To get the text just use the CListCtrl::GetItemText function.
To retrieve the text from say row 2, column 4
CString strText = GetItemText(1, 3);
|
|
|
|
|
CString str = wndYourList.GetItemText ( nRow, nCol ); And just FYI, you're using a list view control; a list box is the old Win 3.1 control.
--Mike--
http://home.inreach.com/mdunn/
You are the weakest link, GOODBYE!
|
|
|
|
|
Thanks for all your help!!!
Rob
|
|
|
|
|
Hi,
I've written a very simple custom static control that allows you certain control over formatting via HTML type tags (bold, italic and underlined).
I've got it working, but when you drag a window over the control and it gets repainted, the memory usage for the program goes up collosally, which is obviously a memory leak.
I've traced the problem to creating the fonts, via CFont, but despite DeleteObjects and just plain deletes of the CFont object/pointer, the memory leak is still there.
I'm creating a font every time the WM_PAINT message is called using the CreateFont() function. I've tried saving the old font then restoring the old font at the end but this doesn't help either.
Is anyone who knows what they're doing with GDI willing to have a look through the code (180 lines .cpp and .h) if I email it to them, as I really haven't a clue what's wrong.
Many thanks,
Peter
|
|
|
|
|
This is a classic. You're trying to call DeleteObject on a GDI object selected into device context. If you're dealing with font, save the CFont pointer returned SelectObject, and select it back before calling DeleteObject:
CFont f;
f.CreateFont(...);
CFont *pOldFont = dc.SelectObject(&font);
dc.SelectObject(pOldFont);
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for the tips but it didn't help.
I've posted the full OnPaint code under the original thread so maybe that will help?
Cheers,
Peter
|
|
|
|
|