 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers, Chris Maunder
The Code Project Co-founder Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 5.00/5 (3 votes) |
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers, Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
 |
Hello, folks, I want a menu like WinXP start menu. If it has to many programs installed. the menu will split into more than one column.
Thanks Hawk
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hello together,
may be this is a simple question. But I am missing a piece to put it all together. I have searched for patterns how to use COM in real life, but nothing told me that. I know how to implement interfaces, properties and methods and so on. So here is what I want to do.
I have a normal C++ object from a class like CSomeObject. This class implements a bunch of methods. Now I want to use this methods not only in the program itself but also in the outside world. So I put all the methods I want to use in a normal interface.
class CSomeObject : public ICommandProvider { ... };
class ICommandProvider { public: void Command1(); void Command2(int arg); };
Then I want to create a CoClass offering an interface like ICommandProvider, let's name the COM interface ICommands.
interface ICommands : IDispatch { HRESULT Command1(); HRESULT Command2([in] int arg); };
And the COM object is implemented using the ATL framework. The COM object should have a private pointer to the normal ICommandProvider interface.
class ATL_NO_VTABLE CoCommands : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CoCommands, &CLSID_CoCommands>, public IDispatchImpl<ICommands, &IID_ICommands, &LIBID_MyLib> { public: CoCommands(); ... private: ICommandProvider *m_pCommandProvider; };
Now it comes to my problem. I don't know how to set up the pointer. I can't do it in the constructor, because one need a default constructor to create a COM object using the CreateInstance methods. May be a solution is to implement another COM interface to set up the private pointer. But this sounds like overhead I don't need, right? So what is the normal pattern to set up a COM object with the internal data it should offer to some client?
Best regards!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In my experience COM is all about performing separate tasks like initalisation on different interfaces. You can either implement another interface to set your object up or add an Init(...) method to your existing interface which does the job but mixes up the two tasks. Various IPersist..... interfaces have InitNew or Load methods that might suit your needs so you don't have to reinvent the wheel.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello mbet878,
If the source codes for the CSomeObject class is in the same project as CoCommands (your ATL class), then there is nothing to stop you from doing something like the following :
m_pCommandProvider = new CSomeObject();
either in the constructor for CoCommands or in the FinalConstruct() function.
Then in the destructor for CoCommands or in the FinalRelease() function, call :
delete m_pCommandProvider; m_pCommandProvider = NULL;
Have you tried the above ?
- Bio.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
My aim is to learn the data structure, in the QuickSort algorithm . 0.6s to complete the order that is 1 million random numbers. 1. However, if the rand number such as rand ()% 2, such a random number will be occur stack overflow , the problem is very difficult for me , in order to keeping the rapid nature of QuickSort, may I ask how to solve the stack overflow problem.
2. But luckily no stack overflow if the situation is still rand ()% 2, such a random number calculate the time to reach 17s. Thank you very much. Attached on the source code:
void SwitchNum(int& n1,int& n2) { int nTemp=n1; n1=n2; n2=nTemp; }
void QuickSort(int *pnArray,int nSize) { if (nSize>1) { int nNum=nSize/2,i=0,j=nSize-1; while (i!=j) { for (;j>nNum;j--) { if (pnArray[nNum]>pnArray[j]) { SwitchNum(pnArray[nNum],pnArray[j]); nNum=j; break; } } for (;i <nNum;i++) { if (pnArray[nNum] <pnArray[i]) { SwitchNum(pnArray[nNum],pnArray[i]); nNum=i; break; } } } QuickSort(pnArray,nNum); QuickSort(pnArray+nNum+1,nSize-nNum-1); } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
crazy66 wrote: may I ask how to solve the stack overflow problem.
QuickSort() is a recursive procedure, so I can only guess that your recursion goes to too deep a level, hence stack overflow.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Im a beginner of WTL. I want to subclass a CStatic control, my code is very simple like following:
class CMyStatic : public CWindowImpl(CMyStatic,CStatic) { BEGIN_MSG_MAP_EX( CMyStatic) //message handle macros here END_MSG_MAP( ) //there are message implements } And, in the main dialog window, I use SubclassWindow function to subclass a spcified static control. But, the problem iss, when the main dialog is closing, i would get an atl assert: ERROR - Object deleted before window was destroyed. I know the problem is due to the deconstructor of its base class. It's deleted before the window has been destroyed. So, how to fix it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
You means Unsubclass the child control in its parent's WM_CLOSE message handler? Yes, i calls myContrl.UnSubclassWindow() before EndDialog() call.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi,
I created an ATL Exe Service using classwizard (VS60) and it contains 1 method. I installed the service using the -service keyword and manually started the service. However, when my client application tries to call the method of that service it basically hangs on the call. Any ideas?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I've written a multi-threaded WTL util to stress test an in-house service.
Comms threads signal to the main thread that they've quit, so the main thread can delete their corresponding object.
They make the signal as so:
PostThreadMessage(m_dwParentThreadId, WM_THREADQUIT, 1, m_dwNetThreadId);
My problem is how to deal with the custom message I've defined .
WM_THREADQUIT is #define'd as WM_USER + 10
I wanted to use an entry in the message map to call a handler, e.g.: BEGIN_MSG_MAP(CMainDlg) MESSAGE_HANDLER( WM_INITDIALOG, OnInitDialog ) MESSAGE_HANDLER( WM_THREADQUIT, OnThreadQuit ) ... REFLECT_NOTIFICATIONS() END_MSG_MAP()
However, OnThreadQuit is never called.
The only way I can handle it is by calling the handler explicitly in PreTranslateMessage:
virtual BOOL CMainDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_THREADQUIT ) { BOOL blHandled; OnThreadQuit(pMsg->message, pMsg->wParam, pMsg->lParam, blHandled); return TRUE; } return CWindow::IsDialogMessage(pMsg); }
I'm sure this isn't the correct way to do it ...
I'd love to know the correct way- can someone help!?
thanks
modified on Friday, November 6, 2009 6:46 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
MSDN documentation mentions as follows:
"...Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated with a window cannot be dispatched by the DispatchMessage function. Therefore, if the recipient thread is in a modal loop (as used by MessageBox or DialogBox), the messages will be lost. To intercept thread messages while in a modal loop, use a thread-specific hook..." http://msdn.microsoft.com/en-us/library/ms644946(VS.85).aspx[^]
You can consider using PostMessage() API.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi ,
I am using CreateWindowsEx()API to create button on toolbar. The code is as
CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,"Button","X",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN ,2,0,25,25,m_hWnd,NULL,_Module.GetResourceInstance(),NULL);
I can add button on toolbar, but color of button is gray, I want this button with white background. So please send any solution to change button color.
Regards abm
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hello. I have created an ocx control in delphi and i put it on form of ATL Composite Control (Insert ActiveX Controls). Now i trying to access properties and methods, but i dont know how to do....
I tryed everythig but i always get error assert debug failed... Is there any way that i "attach" or "getcontrol" like you can do with standard controls in toolbox?
Thanks, komofilms
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
By default, type library information is compiled into my ATL dll project. While I do want the .tlb file, I don't want it compiled into the dll. How do I turn that off?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello kcynic,
The type library information is stored as a resource in your ATL-based COM executable (i.e. DLL or EXE). To remove it, open the resource script file for your ATL project (i.e. <project name>.rc).
In your .rc file, look for a resource typed as "TYPELIB". It will usually be of the following form :
1 TYPELIB "<project name>.tlb"
Simply comment out this line.
By the way, besides removing type libs from your project's resource, you can also add more type libraries into your resource, e.g. :
2 TYPELIB "<some other type library>.tlb"
In this case, you must either supply a full path to the new type library or indicate a path to it in the "Resources" section of your project settings.
- Bio.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks, i have tried successfully. And another question, in some of my code, i use another interface witch is provided by ms, the code looks like following: CComPtr pI; HRESULT hr = pI.CoCreateInstance(CLSID_SomeInterface);
Here, if the code was used in my Atl dll project, i would got hr with E_NOINTERFACE error; but if i use that code in a normal project(Not atl com dll), hr will be S_OK.
why?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
>> And another question, in some of my code, i use another interface witch is provided by ms... Do you mean that in your ATL COM object class, you implement the MS interface ? E.g. :
class ATL_NO_VTABLE CMyClass : public ... public ISomeMSInterface, public ...
Or do you mean that the actual code :
>> CComPtr pI; >> HRESULT hr = pI.CoCreateInstance(CLSID_SomeInterface);
is called in some function of your ATL COM object source codes ? E.g. :
STDMETHODIMP CMyClass::SomeMethod() { CComPtr pI; HRESULT hr = pI.CoCreateInstance(CLSID_SomeInterface); ... }
- Bio.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
To confirm, the creation of object of coclass CLSID_SomeInterface is actually called in some function of your ATL COM object source codes, e.g. :
STDMETHODIMP CMyClass::SomeMethod() { CComPtr pI; HRESULT hr = pI.CoCreateInstance(); ... }
- Bio.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |