|
I have a whole bunch of coclasses and corresponding interfaces.
I want to get an interface, IA, say:
IA* pIA;
CComPtr<IUnknown> pIUnknown;
pIUnknown.CoCreateInstance(__uuidof(A));
pIUnknown->QueryInterface(__uuidof(IA), (LPVOID*)&pIA);
But I also have coclass B and interface IB.
When I run this piece of code, __uuidof(A) is definitely getting the CLSID of A and not B (I've chased it down as far as I can go):
__checkReturn HRESULT CoCreateInstance(__in REFCLSID rclsid, __in_opt LPUNKNOWN pUnkOuter = NULL, __in DWORD dwClsContext = CLSCTX_ALL) throw()
{
ATLASSERT(p == NULL);
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
}
But, "p" in the above code points to B and no to A, despite rclsid clearly showing CLSID of A.
I've gone through my code several times checking order of things being declared, variables not getting cleared when reused, GUIDs getting mixed up etc. None of these seem to be the problem. In fact, CoCreateInstance to this coclass works fine in other parts of the program. It just fails in this particular instance.
Any ideas how to approach this problem?
Please help!
|
|
|
|
|
Does A also expose interface IB? If so, then that's entirely understandable - you expose two interfaces, each derived from IUnknown. The vtable layout of IA will have the methods of IUnknown immediately before the methods of IA (presuming IA derives directly from IUnknown), and the vtable layout of IB will have the methods of IUnknown immediately before the methods of IB (again presuming IB derives directly from IUnknown).
What's going to happen when you have A deriving from IA AND IB? Well, it concatenates their vtables, so that they both have an IUnknown vtable immediately preceding their own methods, preserving the layout you'd see for any one of the interfaces. So, when you ask for an IUnknown interface pointer, it has to pick one of them, so an IUnknown pointer will point at either an IA or IB interface - it doesn't really matter.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the idea, but no, A doesn't expose IB.
|
|
|
|
|
Ummm - one other thought - why bother with all that explicit IUnknown stuff? You could do this:
CComPtr<IA> pA;
pA.CoCreateInstance(__uuidof(IA));
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi, I was wondering if someone could look at this code and tell me what I have done wrong. I have been trying to create a Win32 client but I get build errors. Thanks
<br />
#include <windows.h><br />
<br />
#define WINDOW_WIDTH 980<br />
#define WINDOW_HEIGHT 750<br />
<br />
const char lpClassName[] = "MyProject";<br />
HWND mainWindow<br />
<br />
LRESULT CALLBACK WindowEvent(HWND, UINT message, WPARAM wParam, LPARAM, lParam);<br />
<br />
int WINAPI WinMain(HINSTANCE, hInstance, HINSTANCE, hPrevInstance, LPSTR lpCmdLine, int nShowCmd<br />
<br />
{<br />
WNDCLASSEX wc;<br />
wc.style = CS_VREDRAW | CS_HREDRAW;<br />
wc.lpszMenuName = NULL;<br />
wc.lpfnWndProc = WindowEvent;<br />
wc.hInstance = hInstance;<br />
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br />
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);<br />
wc.cbWndExtra = 0;<br />
wc.cbSize = sizeof(wc);<br />
wc.cbClsExtra = 0;<br />
<br />
RegisterClassEx(&wc);<br />
<br />
mainWindow = CreateWindowEx(<br />
NULL,<br />
lpClassName,<br />
"MyProject",<br />
WS_OVERLAPPEDWINDOW | WS_VISIBLE, <br />
(GetSystemMetrics(SM_CXSCREEN) / 2 - (WINDOW_WIDTH / 2),<br />
(GetSystemMetrics(SM_CYSCREEN) / 2 - (WINDOW_HEIGHT / 2),<br />
WINDOW_WIDTH,<br />
WINDOW_HEIGHT<br />
NULL,<br />
NULL,<br />
hInstance,<br />
NULL<br />
);<br />
<br />
if (!mainWindow)<br />
return 0;<br />
<br />
UpdateWindow(mainWindow);<br />
<br />
MSG msg;<br />
while (1)<br />
{<br />
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br />
{<br />
if (msg.message == WM_QUIT)<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
<br />
return (int) msg.wParam;<br />
}<br />
<br />
LRESULT CALLBACK WindowEvent(HWND, UINT message, WPARAM wParam, LPARAM, lParam);<br />
{<br />
switch (message)<br />
{<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
return 0;<br />
break;<br />
}<br />
<br />
return DefWindowProc(hWnd, message, wParam, lParam);<br />
}<br />
Andrew McIntyre
|
|
|
|
|
What 'build errors' did you get (i.e. Please be specific)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
MrMcIntyre wrote: tell me what I have done wrong.
Quite a lot! If you had read the messages produced by the compiler it would have pointed you to the missing semi-colons, additional commas etc. It took me about five goes to get a clean compile but there is still a bug in there. Might I suggest you start with a sample program produced by the Visual Studio wizard, in order to see the stages of a basic windows program.
|
|
|
|
|
Hope not telling about the syntax errors, which is there in your code.
Величие не Бога может быть недооценена.
modified on Tuesday, September 15, 2009 5:08 AM
|
|
|
|
|
|
I just tried your code snippet on a modified c:\boot.ini file and it read fine. The tab character was in pBuf .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all
i am new member of this forum.I need some help for Get Active window name.Can any one give me API or function name?
Thank in advance.
|
|
|
|
|
|
Hi
I want to set the background of a static control to transparent. How to do this?
I tried the methode described in MSDN ( using the ON_WM_CTLCOLOR() and ON_WM_ERASEBKGND() ) but not working.
My intention is to set the background to a blue gradient or just a solid fill. I have lot of static controls and check boxes in my dialog. I mangaed to set the background of my dialog to solid blue with the help of MSDN documentation. But static control background becomes white whatever i do according to the documentation. Compailer complainted that m_brush is not declaired. I declaired it as CBrush m_brush; in .h file. I have not initialized and not sure how to initialise it.
Am i doing something wrong? Please help. Below is what I got from the MSDN (FYR)
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkMode(TRANSPARENT);
hbr = m_brush;
}
return hbr;
}
BOOL CTestDlg::OnEraseBkgnd(CDC* pDC)
{
CBrush backBrush(RGB(255, 128, 128));
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
|
|
|
|
|
|
Randor wrote: return((HBRUSH)GetStockObject(NULL_BRUSH));
Dear Randor,
It done the job for static texts. Thank you very much. But the check boxes give COLOR_BTNFACE as background colour if I return it only for the static text.
if (pWnd->GetDlgCtrlID() == IDC_STATIC_DATE)
{
hbr = ((HBRUSH)GetStockObject(NULL_BRUSH));
}
return hbr;
If I return it for all controls, check boxes become black. What to do?
sorry if I am asking silly questions.. I am newbie
Thanks in advance!
Deepak
|
|
|
|
|
Hi Deepak,
Deepak.Prahlad wrote: If I return it for all controls, check boxes become black. What to do?
If you are custom coloring multiple controls in your WM_CTLCOLOR handler then it would be better to use a switch statement with a single call to the pWnd->GetDlgCtrlID() function.
To handle both the static and the checkbox try something like this:
int iCtrlID = pWnd->GetDlgCtrlID();
switch(iCtrlID)
{
case IDC_STATIC_DATE:
{
pDC->SetBkMode(TRANSPARENT);
hbr = ((HBRUSH)GetStockObject(NULL_BRUSH));
break;
}
case IDC_YOUR_CHECKBOX:
{
RECT r;
pWnd->GetClientRect(&r);
pDC->BitBlt(0, 0, r.right - r.left, r.bottom - r.top, pWnd->GetDC(), r.left, r.top, SRCCOPY);
hbr = ((HBRUSH)GetStockObject(NULL_BRUSH));
break;
}
default:
break;
}
|
|
|
|
|
Dear Randor,
Once again thank you for your great help. That did the Trick! I have one more issue in the static text. It doesn't properly update the text. I think it is writing over the old text in each iteration. I am using a static text to display the current time. In each second it is being updated with new time with the help of a timer. It was working fine before we went for the transparent background. now it seems to be overwriting. Do I need to clear the text before updating it? I mean use some thing like
SetDlgItemText(IDC_STATIC_DATE,_T(" ")
SetDlgItemText(IDC_STATIC_DATE,_T("HH:MM:SS")
Thank you
Deepak
|
|
|
|
|
Hi Deepak,
Are you Invalidating the CStatic window after you update the text?
SetDlgItemText(IDC_STATIC_DATE,_T("HH:MM:SS"));
CWnd *pWnd = GetDlgItem(IDC_STATIC_DATE);
if(NULL != pWnd)
{
pWnd->Invalidate();
pWnd->UpdateWindow();
}
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: Invalidating the CStatic window
Hi David,
That has no effect.
Thanks
Deepak
|
|
|
|
|
Sorry... I somehow misunderstood what your trouble was.
Now I understand your problem. The parent needs to redraw what was under the child something like this:
CWnd *pWnd = GetDlgItem(IDC_STATIC_DATE);
if(NULL != pWnd)
{
RECT r;
pWnd->GetWindowRect(&r);
ScreenToClient(&r);
InvalidateRect(&r);
}
Best Wishes,
-David Delaune
|
|
|
|
|
Hi David,
It is working nicely now.
But I could not set text colour for the Check boxes and Radio buttons. IT shows up as black always regardless of SetTextColor(). Is there any other thing I have to do in CtlColor method for it? Also how to control the colour of Tab control ?
Thank You
Deepak
|
|
|
|
|
Hi Deepak,
This tells me that your Windows theme is overriding the colors. You can disable the theme for an individual control using the SetWindowTheme Function[^]. Lets use your checkbox as an example:
case IDC_YOUR_CHECKBOX:
{
RECT r;
pWnd->GetClientRect(&r);
pDC->BitBlt(0, 0, r.right - r.left, r.bottom - r.top, pWnd->GetDC(), r.left, r.top, SRCCOPY);
pDC->SetBkMode(TRANSPARENT);
hbr = ((HBRUSH)GetStockObject(NULL_BRUSH));
pDC->SetTextColor(RGB(255, 0, 0));
SetWindowTheme(pWnd->m_hWnd, L"", L"");
break;
}
We have disabled the theme on this control. It might not be what you want, maybe it will be ugly in your eyes.
Best Wishes,
-David Delaune
|
|
|
|
|
Compiler complained that
Error 1 error LNK2001: unresolved external symbol __imp__SetWindowTheme@12 LoggerDlg.obj
Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\deepak.p\Desktop\Logger Working\Logger 13-Sep-2009
From the documentation you provided it says to include "uxtheme.h" but it din't solved the compile error.
Do we need any other includes ?
|
|
|
|
|
Add:
#include "uxtheme.h"
#pragma comment(lib, "uxtheme.lib")
Or you can add the uxtheme.lib into the project linker settings.
Best Wishes,
-David Delaune
|
|
|
|
|
Dear David,
Sorry for the late reply. I was on leave due to some health problems
I tried your suggestion for the check boxes. But it shows some strange behaviors. Okay I will go with the black letters. But can you please tell me how to change the Tab controls color and button colors?
Thanks in advance
Deepak
|
|
|
|
|