|
Hi, all!
I had met a problem when I developing an addin for Excel. I want to create a new OLE control which developed by myself into Excel sheet. But an error occurred when I add it.
I had try to do this by two ways. One is to call the method "Add" of the class "OLEObjects". Another is to call the method "AddOLEObject" of the class "Shapes". Both are all failure.
When I call OLEObject.Add, an exception was throwed which said a com_error occured in Excel. The code I used is as below:
CComPtr<MSEXCEL::_Workbook> spBook;
HRESULT hr = m_spAppExcel->get_ActiveWorkbook(&spBook);
if(spBook == NULL)
{
return;
}
CComPtr<MSEXCEL::Sheets> spSheets;
spBook->get_Sheets(&spSheets);
CComPtr<MSEXCEL::OLEObjects> spObjs;
CComVariant vtIndex(1);
spSheets->get_Item(vtIndex,(IDispatch**)&spObjs);
VARIANT vtResult;
VariantInit(&vtResult);
CComVariant ClassType(_MYPROGID);
CComVariant vtFalse(VARIANT_FALSE);
CComVariant left,top;
int x,y;
GetInsertPosX(x,y);
left=x; top = y;
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
CComPtr<MSEXCEL::_OLEObject> pObj;
try
{
pObj = spObjs->Add(ClassType,vEmpty,vtFalse,vtFalse,vEmpty,vEmpty,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);
if(pObj == 0)
{
return;
}
}
catch(...)
{
DWORD dwError = GetLastError();
TCHAR info[10];
wnsprintf(info,10,L"%x",dwError);
MessageBox(NULL,info,L"Error",MB_OK);
return;
}
When I call Shapes.AddOLEObject, the calling is success. But the value it returned can't be converted to the pointer I need. The code is as below:
CComPtr<MSEXCEL::_Workbook> spBook;
HRESULT hr = m_spAppExcel->get_ActiveWorkbook(&spBook);
if(spBook == NULL)
{
return;
}
CComPtr<MSEXCEL::_Worksheet> spSheet;
spBook->get_ActiveSheet((IDispatch**)&spSheet);
CComPtr<MSEXCEL::Shapes> spShapes;
spSheet->get_Shapes(&spShapes);
ATLASSERT(spShapes);
VARIANT vtResult;
VariantInit(&vtResult);
CComVariant ClassType(_MYPROGID);
CComVariant vtFalse(VARIANT_FALSE);
CComVariant left,top;
int x,y;
GetInsertPosX(x,y);
left=x; top = y;
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
CComPtr<MSEXCEL::Shape> spCtrl;
spCtrl = spShapes->AddOLEObject(ClassType,vEmpty,vEmpty,vtFalse,vEmpty,0,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);
if(spCtrl == 0)
{
return;
}
CComPtr<MSEXCEL::OLEFormat>spOleFormat;
spOleFormat = spCtrl->get_OLEFormat();
IDispatch *pObj;
pObj = spOleFormat->get_Object();
CComQIPtr<ICASign> cpCASign(pObj);
if(cpCASign == 0)
{
return;
}
When I use the second way, I had found the constructor of CCASign had been executed. But when constructor is return, the value of cpCASign is still zero. I think maybe ICASign isn't matched with CCASign. But this object can be inserted into Word correctly. When adding this object into word, the same procedure is done. The value after converted is correct. So I don't know the reason of this error. I hope someone could be kind to help me. Thank you!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
CComPtr<MSEXCEL::OLEFormat>spOleFormat;
spOleFormat = spCtrl->get_OLEFormat();
IDispatch *pObj;
pObj = spOleFormat->get_Object();
CComQIPtr<ICASign> cpCASign(pObj);
change that to ...
CComPtr<MSEXCEL::OLEFormat>spOleFormat;
spOleFormat = spCtrl->get_OLEFormat();
CComPtr<IDispatch> pObj;
pObj = spOleFormat->get_Object();
CComPtr<ICASign> cpCASign;
HRESULT hr=pObj.QueryInterface(&cpCASign);
and at least you'll have a error code to work with
|
|
|
|
|
Problem still exist. The value of hr is "E_NOINTERFACE". I feel very strange that the same operation can completed within Word. I check the interface declaration of CCASign many times. No mistake was found. Please continue to help me! Thank you!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
what's the object written using?
if it's ATL, use the _ATL_DEBUG_QI to watch for it being queried
Not done much with Excel or Word, but it wouldn't surprise me if they use separate threading models, and the E_NOINTERFACE you're getting is because it can't get to an IMarshall interface
have a look at http://msdn.microsoft.com/en-us/library/ms687205(v=vs.85).aspx[^]
|
|
|
|
|
My control is written in C++. I had read the article you recommand. My control's ThreadModel is Single-Threaded apartment. I had tried the other key-word. Only "Apartment" and "Both" can work. I think maybe I hadn't implement some methods, so the conversion is failure. I hope you can list all methods I must implement. Thank you!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
ok - first things first - you need to find out if this is the problem
If you're using ATL, enable the _ATL_DEBUG_QI define for the project - this will show you what your project is being queried for (as long as you are running your object under the debugger)
If you're not using ATL, you'll have to change your QueryInterface method so it prints out interfaces that are requested, that it doesn't support
|
|
|
|
|
 I had add _ATL_DEBUG_QI define in my project. Then message below is output:
CComClassFactory - IUnknown
CComClassFactory - IClassFactory2 - failed
CComClassFactory - IClassFactory
CCASign - IDispatch
CCASign - IConnectionPointContainer
CCASign - IProvideClassInfo
CCASign - IConnectionPointContainer
CCASign - IProvideClassInfo
CCASign - IOleObject
CCASign - IOleControl
CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
CCASign - IPersistStreamInit
CCASign - IConnectionPointContainer
CCASign - IProvideClassInfo
CCASign - IOleContainer - failed
CCASign - IDataObject
CCASign - IPersistPropertyBag - failed
CCASign - IRunnableObject - failed
ATL: IDataObjectImpl::QueryGetData not implemented.
_CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
CCASign - IRunnableObject - failed
ATL: IDataObjectImpl::QueryGetData not implemented.
_CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
CCASign - IPersistStreamInit
These message are output when calling Shapes.AddOleObject. I check the interface marked as fail. Such interfaces are not needed to implement except "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". I don't know what interface is "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". My own interface is registered already. And its CLSID isn't {049948D1-5686-11CF-8E0D-00AA00A74C5C}. Is this the reason of problem?
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
your addoleobject call is succeeding
You need to look at the debug trace when you call
HRESULT hr=pObj.QueryInterface(&cpCASign);
because that's the call that is failing
|
|
|
|
|
I had make clear that the reason of problem is the interface I need i can't be queried.
When the following code executed, nothing output.
HRESULT hr=pObj.QueryInterface(&cpCASign);
But i don't know how to fix it. Pls help me. Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
ok - that would imply that the pObj you get back is not your object
does excel manufacture some form of object-site object?
looking at the vba excel docs, your object should also turn up in
OLEObjects container; I would write some code to see if I get the same, or different behaviour
i.e.
Add object to shapes as you are currently doing
then look for it in the OLEObjects container
then QI that object for your interface
modified on Tuesday, May 3, 2011 8:07 PM
|
|
|
|
|
Pleasure to see your reply. Thank you very much!
Some days ago, I find a message at MSDN. It said that if you want to add an OLE object into Excel worksheet, you should call OLEObjects.Add(), not Shapes.AddOLEObject(), because Shapes encapsulate the OLEObject returned by AddOLEObject. So the next operation such as OLEFormat.get_Object() can't get the raw point of the object inserted.
I had tried the way it recommend. But I can't get a OLEObjects from worksheet. I find that the reason of failure is the wrong LANGID parameter. I am trying to find the right parameter for it now. If you can't be success from the code above, you can try to do by this way. And if you know what parameter of LANGID is right, I will be very pleased to know it from you.
Sincerely
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
The message I get tell me that I should call _WorkSheet.OLEObjects() to get an OLEObjects, then call OLEObjects.Add() to insert my own object. But I get an error whose code is 0x800A03EC. This means I should set the right CultureInfo before calling OLEObjects.Add(). But I can't find any hint to set it besides using .NET framework. Should I using .NET just for this?
I had try to call GetSystemDefaultLCID() and ConvertDefaultLocale() to fix it. But the same error occurred. What shall I do?
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
I'm afraid I don't know - sorry ...
Things *I* would look at ...
1. What interfaces are being queried from your object during the OLEObjects.Add; do any of those want or return an LCID - if no interfaces are being queried it may be something missing from your type library
2. I would try doing the Shapes.AddObject as before, but then querying the OLEObjects rather than the object shape returns - the docs suggest the object will turn up in both places
3. If neither of those got me anywhere, I'd start looking at the object Shapes.AddObject returned, querying it for standard container interfaces and see if i could get to the 'real' object underneath (IOleContainer for instance)
best of luck
|
|
|
|
|
Sorry, maybe I make you nervous. That's my fault.
1. Nothing output when I call OLEObjects.Add. Maybe it's because I call the Dispatch.Invoke() to add. The reason of I call Dispatch.Invoke() instead of OLEObjects.Add() is that an error of 0x800A03EC always occurred for OLEObjects.Add().
2. I can't get the meaning of your second suggestion. You tell me to query OLEObjects at the object Shapes.AddObject returned?
3. Your meaning is that I should query some container interfaces such as IOleContainer for the object returned by Shapes.AddOLEObject(), isn't it? Why?
By the way, the error of 0x800A03EC isn't means wrong cultureinfo. The correct meaning is that another operation background is executed on the same object. I must make the object such as button lost focus. This is a bug for Office 2003.
Following is the explanation from Microsoft:
http://support.microsoft.com/kb/823988/en-us[^][]
I had try to do as the code provided by Microsoft. But nothing changed.
I hope you can help me in advance. Thank you!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
2. make the previous
spShapes->AddOLEObject(ClassType,vEmpty,vEmpty,vtFalse,vEmpty,0,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);
call, but then look for your object in the OLEObjects() collection
3. Yes - I am assuming that Shape wraps your object in some form of container, so you *might* be able to get to that container, and ask IT for the enclosed object - alternatively, from within your IOleObject, find out what it's clientSite is, and see if that's the object Shape is giving you
|
|
|
|
|
Hi, barneyman.
I had fixed this problem. The reason of problem is that I missed a procedure. The right step is:
1. Get a pointer of OLEFormat with calling Shape.get_OLEFormat()
2. Get a pointer of _OLEObject with calling OLEFormat.get_Object()
3. Get a pointer of Dispatch with calling _OLEObject.get_Object()
4. Convert the Dispatch to my own object's pointer.
Thank you for waste your time to help me. I hope I could get more help from you later! Good luck!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
I need to programmatically update/set contents of Mozilla Firefox browser Controls Contents using the IAccessible , IAccessible2
COM Interface MSAA Architecture .
The put_AccValue method in IAccessible Interface gives Return Code Not Implemented .
How do I set text programmatically ?
Can anybody provide some Sample code or reference to links ?
Kamal Jagesia
|
|
|
|
|
Not every program supports IAccessible .
According to what you said, Mozilla Firefox browser Controls Not Implemented it.
|
|
|
|
|
Hi
I just wanted to replace a '%' character in CComBSTR with "%%". But the code does not support CString. The solution should be UNICODE support.
Any methods to perform this operation ?
Thanks In Advance.
Babu
Today is a gift, that's why it is called the present.
|
|
|
|
|
CComBSTR does not have a Replace method, but you could use a temporary CString to make the replacement.
CString cstr(bstr.m_str);
cstr.Replace(L"%", L"%%");
bstr = cstr;
|
|
|
|
|
I have injected my DLL into Mozilla firefox browser. Using this DLL I want to get the IWebBrowserApp Interface , IHtmlDocument2 Interface for the current Active Instance of Mozilla Browser. How do I achieve this ? I do not want to use ATL or MFC .
|
|
|
|
|
I am using OPC client which connects to OPC driver but if the loading takes more than 2 mins it's automatically shutdown the driver please suggest me something.
Tested with other clients also but the same problem persist.
The problem is with CoCreateInstance if it takes more than 2 mins it abort the driver gracefully.
Thanks in advance!!!!
Truth Is The Simplest !!!!
|
|
|
|
|
Are you connecting to a local or remote OPC Server? What is your error code?
|
|
|
|
|
Hi,
I am a COM novice so please bear with me if information is incomplete/incorrect. I have a C++ application interacting with a .NET application through a COM. The C++ application is launched by the .NET application, which received events from the C++ application through COM interface using COleDispatchDriver.InvokeHelper method (described here - http://msdn.microsoft.com/en-us/library/zwx803ex(v=vs.80).aspx[^].
My question is - say my .NET application dies and my C++ application remains alive and tries to send an event to the .NET application through this COM interface, is there any way I can know that .NET application's gone.
Please let me know if you need more information.
Thanks,
Anshuman
|
|
|
|
|
I'm trying to access an an XAudio2 interface (IXAudio2 for example) in C#.
Some background: I'm writing a tool that will allow a sound artist to play back some music (among other things). I require playback of streaming multichannel audio from any location in the file, the tool is written in C#. DirectSound is depricated, XACT can't do this as far as I know, other packages (NAudio and SlimDX) are options but I'd like to stick with what our artists already have installed if possible. That leaves me with xaudio2, but it's not managed.
I've scanned my registry and opened the XAudio2 dll in OLE-COM Object Viewer, as well as several dll inspectors, none list the interfaces in the coclass. I'm following the directions here to access the COM interfaces but I require the IID of interfaces like IXAudio2.
Is there any way of getting this information or am I going down the wrong path all together?
TIA
|
|
|
|