|
SNI wrote: But when i am trying to call this Interface from member function of the same DLL it is giving "-2147417843" error.
This error is a COM related error.
The description is this:
"An outgoing call cannot be made since the application is dispatching an input-synchronous call."
I'm not able to follow your explanation of how the different modules are connected, in what process the DLL is located, what calls are made from where to what and in what order.
And what do you really mean by "callback"?
Is it a COM event sink or what? I suspect it is.
However, I'm quite familiar with the error you've got.
It means that you are making a call to a COM server that resides in another apartment and that COM server wants to call you back in the same call chain.
This is not allowed since it would generate a deadlock.
I suppose you've heard that COM threads always have to process messages, at least the ones that create COM objects.... The reason is that when you make a call from one apartment to another, the call will generate a message that is sent from the calling apartment (the proxy) to the called apartment (the stub). When the call has been processed a message is sent back that the calling apartment is waiting for. During that time the calling apartment is not available for incoming COM calls and thus the COM library generates an error if you're attempting to do it.
This is the same problem you'll get if you're sending a message to another thread with ::SendMessage() instead of ::PostMessage() ; if the receiving thread does not process messages you'll get a nice little deadlock.
SNI wrote: Please suggest is there any possiblity to call CallBack / Interface implemented in ATL (EXE server) component from DLL.
I strongly recommend that you re-evaluate your design in a way that you don't make an outgoing call from the called interface function. You could post a message inside the server with the information needed.
There is another solution.
It will probably make your project increase in complexity ten fold at least, but you could make the servers free-threaded and let effected threads live in the multithreaded apartment of the process.
It's possible, but don't say I didn't warn you.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks for your reply.
I would like to put the same question in other words. I am rephrasing this to understand the question properly.
-----------------------------------------------------
I have created Office AddIn Exe (Out Proc Server ) Com Component in VC++.
When i am creating instance of COM Exe in my MFC DLL by following way,
HRESULT hRes = CoInitialize(NULL);
HRESULT hr=::CoCreateInstance(CLSID_TestILGAddIn,NULL,CLSCTX_LOCAL_SERVER,IID_ITestILGAddIn,(LPVOID *)&pILGComAI);
if (hr != S_OK)
{
AfxMessageBox(_T("CreateInstance Failed"));
}
Here CoCreateInstance is failed with return error no "-2147417843"
------------------------------------------------------
Please let me know what can we do in this case?
Thanks
SNI
SNI
|
|
|
|
|
SNI wrote: I have created Office AddIn Exe (Out Proc Server ) Com Component in VC++.
When i am creating instance of COM Exe in my MFC DLL....
If this is an Office AddIn, doesn't the Office application create the server?
Why do you have to create it?
It should be "installed" or "registered" in the Office application so it knows that the server should be created at start up.
From where is your DLL called when you're trying to create the server?
SNI wrote: Here CoCreateInstance is failed with return error no "-2147417843"
Without knowing from where your code is called, I cannot answer why you get this error better than in my previous post.
But, since this is a dll, you may be called in a thread that doesn't pump messages. So you should create a secondary UI-thread (one that pumps message) and create your server from there. Also be sure to initialize COM in that thread.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,
Thanks for your reply and it is very usefull. We are sending msg using SendMessage which bolcks the thread. We have simulate this using by sending msg using SendMessage and it reproduced. So we use PostMessage instead of that and it resolves the problem.
Is there any way other than PostMessage we can use?
Thanks
SNI
SNI
|
|
|
|
|
Hi,
we need to send some information such as file name and we can do it by sending msg using SendMessage but we cannot send it thru using PostMessage. Is there any way by which we can send file name to other thread.
Thanks
SNI
|
|
|
|
|
Hi all,
I have a ATL&COM project, the problem is when I add a new object of ATL it pop a dialog and displayed like this "Currently ATL objects may only be added to ATL projects, or certain types of MFC projects (EXE, Control, Regular DLL)."
Who can tell me how to deal with this poblem?
Thanks
|
|
|
|
|
I just created a small ATL DLL project (with VS2003). Commenting out the declaration of the variable _AtlModule and/or its type caused this issue for me - so make sure you're not doing that! You may need to rebuild the project to get VS to recognise your project's ATL-ness.
I think the ATL class wizard is looking for a valid LIBID definition?
|
|
|
|
|
hi all,
i need help for making a CTrackBarCtrl transparent.
followed various threads around, but still haven't found
a working answer.
I have a template class:
template <class t=""> class CTrackBarTransparentT : public CWindowImpl<ctrackbartransparentt><t>,CTrackBarCtrl>
{...}
with handled WM_ERASEBKGND and WM_PAINT:
...
HDC dc = (HDC)wParam;
HBRUSH hbrOld = NULL;
HBRUSH hbr = NULL;
hbr = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
//hbr = CreateSolidBrush(RGB(255,0,0)); //to impart color
hbrOld = (HBRUSH)SelectObject(dc, hbr);
RECT rc;
GetClipBox(dc, &rc);
PatBlt (dc , rc.left, rc.top, rc.right - rc.left , rc.bottom - rc.top,PATCOPY);
SelectObject(dc, hbrOld);
...
but this got no effect...
i think that the point should be to paint with an hollow brush, but this doesn't seems to
work for me.
Thanks in advance
|
|
|
|
|
Looking at this article[^], the difference between that and what you've got is setting the DC's background mode[^] - don't know if that'll make the difference.
I also saw this article[^] which says:
A TrackBar control does not repaint itself until it gets the focus. So, if you enable run time changes of appearance, and you have one, you'll have to set and reset the focus in order to show it properly.
That may be of more relevance...
|
|
|
|
|
hi experts,
Currently I m doing a COM DLL which exports some functions and enums structures.
can anybody help me to exports the enums from COM.
my enum definition is like this:
typedef enum LANG{
HIN,ENG,MAR,JAP,CAN
}LANG;
how can i declare this so that i can use it in client side using VB.
and I m using VC++ 6.0 and VB 6.0
plz help me.
thanx in advance.,
regards,
Victory
|
|
|
|
|
I did a quick search for enum in my .idl files and found the following where an enum is used as a parameter in an interface if its of any help. This was definitly for VC++ 6.0 COM called from VB.
typedef [v1_enum] enum CoolingSystem
{
System1 = 0x00000001,
System2 = 0x00000002
}CoolingSystem;
[
uuid(B30CF430-3E47-11D5-8088-0050DAD52C1D),
helpstring("IFridge Control Interface"),
]
interface IFridgeControl : IUnknown
{
[id(0x00000001), helpstring("Select working System")]
HRESULT SelectSystem([in] CoolingSystem System);
|
|
|
|
|
Having found the VB files that used this interface to call C++ implemented COM I see:
An object declared usaing the tlb namespace:
Dim WithEvents m_objController As CONTROLLERLib.CoController
Then in a sub procedure I can type the namespace CONTROLLERLib and on typing the . after it the intelli-sense displayes all the enumerated values from the . idl file.
I can then type:
CONTROLLERLib.CoolingSystem = CONTROLLERLib.System2
though I don't think this correct and I'm not set up to try actually run antything
I also came across the enum (CoolingSystem) used in a VB Sub declaration:
Private Sub m_objController_TemperatureChanged(ByVal ErrorCode As Long, ByVal System As CONTROLLERLib.CoolingSystem, ...
Maybe it's something to go on.
|
|
|
|
|
Thanx budy..
it works..
but i dont want it to add into COM property..
so only above declaration got useful
|
|
|
|
|
Make sure the enum is in the 'library' part of the IDL file: I just built and registered a little COM DLL with this IDL:
import "oaidl.idl";
import "ocidl.idl";
[
uuid(AB41E782-D178-47AA-950A-91406234E0A5),
version(1.0),
helpstring("aa 1.0 Type Library")
]
library aaLib
{
importlib("stdole2.tlb");
typedef enum LANG{ HIN,ENG,MAR,JAP,CAN }LANG;
};
Opening it in the Object Browser in Word's VBA IDE showed the enumerated type and the enumerations.
HTH!!!
|
|
|
|
|
I want to retrieve information from secured(requires user name and
password) web service. I can connect it with .NET 2.0 web service using
NetworkCredentials class. But when I tried it with C++, I cannot even
send the username and password. The code doesn't send any authentication information. So the
server send HTTP 401 Authectication error back.
I'm searching web. I read and tried all I found.
I use VS2008 with ATL Server Library & tools.
thanx.
|
|
|
|
|
|
class CSampleBasicAuth : public CBasicAuthObject, public IAuthInfo
{
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
username = _T("user");
password = _T("password");
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
Service::CService *srv = new Service::CService();
CAtlHttpClient &httpClient = srv->m_socket;
CSampleBasicAuth *basicAuth = new CSampleBasicAuth();
httpClient.NegotiateAuth(true);
httpClient.AddAuthObj( ATL_HTTP_AUTHTYPE_BASIC, basicAuth, basicAuth );
srv.doSomeThing()..
what's wrong ?
thanks
|
|
|
|
|
Does the web service accept basic authentication or does it require some other authentication?
[edit]I'd recommend using Fiddler[^] to spy on the HTTP traffic[/edit]
|
|
|
|
|
It's solved. Thank you.
CSampleBasicAuth *basicAuth = new CSampleBasicAuth();
changed
CSampleBasicAuth basicAuth;
if authentication obj is a pointer,
inline bool CBasicAuthObject::DoBasicAuthenticate() throw()
{
bool bRet = false;
ATLASSUME(m_pClient);
ATLASSUME(m_pAuthInfo);
.
.
thanks for your help.
|
|
|
|
|
I have a Dialog, inheriting from CDialogImpl , which contains a CListViewCtrl with three columns. In order to get the list items ordered correctly a custom sort function is used. It is in my handler for LVN_COLUMNCLICK< (Clicking a column header) that that the column header has the triangular bitmap indicating sort direction set.
On creation of the dialog, without the workaround shown below, no sort direction arrow appears on the header. I then have to call the LVN_COLUMNCLICK handler (see code) from OnInitDialog to force a sort of the first column in the order that my LVN_COLUMNCLICK handler sets the sort order triangular bitmap in the column header.
LRESULT CPortsDlg::OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
...
int idCtrl = 0;
NMLISTVIEW nmlv;
nmlv.iSubItem = 0;
BOOL bHandled = FALSE;
LPNMHDR lpNMHDR = reinterpret_cast<LPNMHDR>(&nmlv);
OnLvnColumnclick(idCtrl, lpNMHDR, bHandled);
return 0;
}
This doesn't seem right; am I missing some feature that will ensure that upon creation a particular list column is sorted (using my custom sort) in, say, ascending order with the appropriate column header bitmap displayed to indicate this?
LRESULT CPortsDlg::OnLvnColumnclick(int , LPNMHDR pNMHDR, BOOL& )
{
if(!::IsWindow(m_hWnd))
{
return 0;
}
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
HDITEM HeaderItem;
HeaderItem.mask = HDI_FORMAT;
CHeaderCtrl HeaderCtrl = m_ListViewCtrl.GetHeader();
if(!::IsWindow(HeaderCtrl.m_hWnd))
{
return 0;
}
int nColumnCount = HeaderCtrl.GetItemCount();
for(int nSelectedColumn = 0; nSelectedColumn < nColumnCount; nSelectedColumn++)
{
HeaderCtrl.GetItem(nSelectedColumn, &HeaderItem);
HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
if(nSelectedColumn == pNMLV->iSubItem)
{
m_SortAscending = (m_CurrentSortItem != pNMLV->iSubItem) ? true : !m_SortAscending;
HeaderItem.fmt |= m_SortAscending ? HDF_SORTUP : HDF_SORTDOWN;
}
HeaderCtrl.SetItem(nSelectedColumn, &HeaderItem);
}
m_CurrentSortItem = pNMLV->iSubItem;
m_ListViewCtrl.SortItems(SortFunc, (DWORD_PTR)this);
return 0;
}
|
|
|
|
|
It doesn't seem unreasonable to me that you have to tell the control how it's sorted - I suspect that setting HDF_SORTDOWN or HDF_SORTUP on the relevant column and calling m_ListViewCtrl.SortItems would be sufficient - if that's the case, maybe you should refactor the header flag setting and control sorting into a separate function, so it could be called from OnInitDialog rather than calling the OnClick handler?
[edit]Maybe CSortListViewCtrl will do some of the sorting tasks for you, simplifying the overall job?[/edit]
|
|
|
|
|
Stuart,
I've done a test using CSortListViewCtrl (which I didn't know about) instead of CListViewCtrl . It seems that simply calling SetSortColumn(0) both makes my handler for LVN_COLUMNCLICK redundant and removes the need to call it from InitDialog. I haven't tried this with a custom sort yet but can see I will need to call SetColumnSortType(0, LVCOLSORT_CUSTOM) .
Much neater.
Thanks.
|
|
|
|
|
Hi,
I got code for ICopyHook interface which traps FOLDER's CUT,COPY, PASTE operation but I want the same thing for Word file. Is there any way by which we can trap the CUT, COPY and PASTE operation for WORD file.
Thanks
SNI
|
|
|
|
|
Do you mean a cut, copy or paste performed within Word? If so, I don't think so - the documentation[^] seems pretty clear that an ICopyHook handler is a shell extension, so would form part of Explorer, and that it only gets to approve/disapprove operations on folders or printers.
|
|
|
|
|
|