|
So what's the value of hr ? CoCreateInstance reports the reason for a failure.
You do occasionally get badly-implemented COM components which return a success code when asked for their primary interface, but fail (returning E_NOINTERFACE ) when asked for IUnknown . This is of course an implementation error - all components must implement IUnknown .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Are you calling CoInitialize(NULL)?
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hello,
i try to use late binding for office automation with powerpoint and c#.
I found some examples for word which work fine:
<br />
Type comType;<br />
object comObject;<br />
<br />
comType = Type.GetTypeFromProgID("Word.Application"); <br />
comObject = Activator.CreateInstance(comType);<br />
<br />
object o = comType.InvokeMember("Application", BindingFlags.Public | BindingFlags.GetProperty, null, oPptAppObject, null);<br />
...<br />
...<br />
So far everything works fine. The Compiler is happy
But when i replace the ...("Word.Application")... with ...("PowerPoint.Application")...
i get an exception (which says: unknown name) for line with:
object o = comType.InvokeMember.....
Also "Application" is a Member of PowerPoint, like it is in Word.
I also tried other Members from PowerPoint but was not lucky.
I googled the whole day, but no solution.
Can anybody help me please?
It have no idea what to do.
Thanks a lot!
|
|
|
|
|
"Word.Application" is the ProgID, it doesn't mean access the "Application" member of "Word".
I don't have PowerPoint installed on my computer, just the Viewer. I would use "PowerPointView.Application" to instansiate the viewer.
Do you have PowerPoint installed on your computer?
PeterRitchie.com
|
|
|
|
|
In *.idl file:
interface Ixxxx : IDispatch
{
[id(1), helpstring("method GetData")] HRESULT GetData(LPCTSTR Key, DWORD *Data);
[id(2), helpstring("method SetData")] HRESULT SetData(LPCTSTR Key, const DWORD Data);
}; Both these methods generate warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'Key' of Procedure 'GetData' ( Interface 'Ixxxx') ]. Other than these warnings the interface seems to run correctly. Is it something I have to worry about or can I safely ignore them. If I have to worry about it, how do I go about fixing it? All MSDN says is make sure the interface is derived from IUnknown or IDispatch.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Classes marked as "dual" have implied oleautomation attribute.
The oleautomation attribute simply means that the interface is compatible with older versions of Visual Basic, VBScript, JavaScript, etc. (i.e. untyped scripting languages).
If you don't need your interface to be compatible with any of those, then you can ignore the warning.
If you need to be compatible, you can get rid of the error by replaycing LPCTSTR with BSTR.
PeterRitchie.com
|
|
|
|
|
Thanks, I don't need them to be compatible (so far ) but I hate getting warnings in my code, makes me nervous that I am doing something wrong. I changed the LPCTSTR s to const BSTR s and all is well.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
How Can I catch Key Event When I have focus on Webbrowser object in my application?There are a lot of articles about context menu etc, but no one has said anything about catching Key Event. Is there some solution by using some API or?
|
|
|
|
|
Hi BorisKco,
You encounter to the infamous problem with WebBrowser control.
There r some work arounds for this problem.
BTW, wht r u exactally looking at ?
Cheers,
Vishal
|
|
|
|
|
I have solved the problem already. But, thanks anyway.
Boris
|
|
|
|
|
requirements minimum to install an application developed in C #using COM+ [. NET] in a computer with WIN98?
lang
|
|
|
|
|
hello..
I have finished an application developed in C #using COM+ and I have the following errror:
at System.EnterpriseServices.ServicedComponentProxy.CleanupQueues(Boolean bGit)
at System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj)
at WinInterface.Login.btnAceptar_Click(Object sender, EventArgs e)
The type initializer for "System.EnterpriseServices.ServicedComponentProxy" threw an exception.
The application has been created in WINXP and will settle in WIN98SE.
Code Sample ... All BusinessLogic.
[Guid("35D02EB6-BC99-4c57-8078-1CF58CFE1FE7"),
JustInTimeActivation(),
Synchronization(SynchronizationOption.Required),
Transaction(TransactionOption.Required)]
public class ClienteBL : ServicedComponent
Help me ... please
lang
|
|
|
|
|
I have a minimal C# project with a form containing a AxSHDocVw.AxWebBrowser. The project also contains a UserControl that has been given a GUID to act as an ActiveX-compnent. The UserControl has its backgroup color set (yellow) but besides that it does "nothing".
During execution the HTML code: "<html><body><object classid=\"clsid:#GUID#\"></object></body></html>"
is loaded into the AxWebBrowser and the yellow UserControl is shown.
The problem occurs after Dispose. When the form is closed it's Dispose method is called and the application freezes.
The stack trace tells me that the execution has stopped in system.windows.forms.dll!System.Windows.Forms.Control.ActiveXImpl.SetClientSite
If I explicitly call AxWebBrowser.Dispose() the application freezes at that line of code.
If I omit the ActiveX from the HTML the problem does not occur.
Any suggestions?
Thanks in advance
/Dan
|
|
|
|
|
I am using an IHTMLDocument class to sent text information to the printer in HTML format. One problem I have encountered is that I want to send many HTML documents in one go. There is no HTML tag for "page break" so I must send each document as a different print job. If I'm doing this the print dialog box will be thrown up 20 times (being a real pain for the user).
I know that the flag PRINT_DONTBOTHERUSER can be set to stop the dialog being activated but there is next to no info on Google and MSDN is really unhelpful. Has anyone with experience in COM done this before? Is there any example code you could demonstrate?
For info, here is the code I am using to perform the print job:
// includes for COM stuff
#include <comdef.h>
#include <mshtml.h>
#pragma warning(disable : 4146) // see Q231931 - MSDN
#import <mshtml.tlb> no_auto_exclude
// end of COM stuff
......
bool CSomeClass::PrintHTMLNotes(void)
{
// get IHTMLDocument handle
MSHTML::IHTMLDocument2Ptr pDoc;
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, (void**)&pDoc);
if (pDoc==NULL)
return false;
// convert string to safearray
SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT,0,1);
VARIANT *param;
hr = SafeArrayAccessData(psa,(LPVOID*)¶m);
param->vt = VT_BSTR;
SAFEARRAY* psaIn = SafeArrayCreateVector(VT_VARIANT,0,1);
VARIANT *pvaIn;
hr = SafeArrayAccessData(psaIn,(LPVOID*)&pvaIn);
pvaIn->vt = VT_ARRAY;
pvaIn->iVal = PRINT_DONTBOTHERUSER;
// write data to document
bstr_t bsData;
for (int i=0; i<m_ncurrentnote; i++)
="" {
="" bsdata="m_csaNotes[i];
" param-="">bstrVal = (BSTR)bsData;
hr = pDoc->write(psa); // write buffer
}
hr = pDoc->close(); // close document (applys code)
SafeArrayDestroy(psa); // clean up
// print the file
CComQIPtr<iolecommandtarget> spTarget = pDoc;
if (spTarget != NULL)
spTarget->Exec(NULL, OLECMDID_PRINT, 0, pvaIn, NULL);
else
return false;
return true;
}
|
|
|
|
|
If you have control over the HTML you can add page breaks to it. I'd have to find the code but if you do let me know.
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hi!
I have a COM Class (say MyCOMClass). I'm able to create an object in Access and call its methods. The problem is that the COM object throws events, and i don't know how to handle them.
For example in VB.NET i have
Dim WithEvents myCOMObject as New MyCOMClass
Then, i can catch the events that myCOMObject throws easily. But I have try to do the same in VB for Applications and i can't use WithEvents. So, is there another way?
I'm not a VB programmer, I'm just doing some testing applications for my COM project.
Thanks for the help.
|
|
|
|
|
VBA supports WithEvents. You cannot use it in a standard module but you can declare an object WithEvents in a form or a class in MS Access (or any VBA project).
You cannot use WithEvents with the new keyword.
Suppose you have a form in Access.
In the code behind the form add:
Private WithEvents myCOMObject As MyCOMClass
In the Form_Load procedure add:
Set myCOMObject = New MyCOMClass
Presto. Events.
|
|
|
|
|
Happy Friday! Gurus,
I am trying to use the logics from Intel OpenCV DLLs, which were originally compiled by MSVC++ 6. From C# or ASP.NET Apps, when I was trying to add reference to these DLLs (i.e. cv096.dll or cxcore096.dll), I got this error:
“A reference to ‘D:\Programs\OpenCV\bin\cv096.dll’ could not be added. This is not a valid assembly or COM component. Only assemblies with extension ‘dll’ and COM components can be referenced. Please make sure it is a valid assembly or COM component.”
Note: The source code of Intel OpenCV DLLs is open source. I can open this source code project in either MSVC++ 6 or VS.NET 2003.
Question: How can I use these DLLs in .NET environment, preferably in ASP.NET and C# projects?
Thanks with a million
Khang
|
|
|
|
|
That means it is a standard C/C++ DLL, not a COM Dll. You cannot add a reference to the DLL and use it directly like a COM component.
That means you'll have to use API style declarations to access whatever functions the dlls export. You'll also have to figure out how to translate all the unmanaged types into C# compatible types. I'd start looking for a OpenCV user group if I were you.
Robert
|
|
|
|
|
Hello Robert,
I appreciate your tip very much!
Thanks & Have a good weekend,
Khang
|
|
|
|
|
Hello
I want to write my COM object so that a C++ program can use it and a VB program can use it also. When I build my COM object using the wizard I get the IDispatch interface which means I can access my COM object using automation. My COM object has methods all of which return either S_OK or S_FALSE depending on what happens during the method call. My C++ program can get the results of a method call to my COM object to find out what went wrong if an error occurred. My VB program cannot do this.
What is the best solution to this problem?
Is there anywhere a guide as to how best write COM objects in C++ that are as language independent as possible but especially C++ and VB?
|
|
|
|
|
VB actually does receive the S_OK and S_FALSE values. It just processes them behind the scenes so you do not see them in VB.
When you are building the Com object in the wizard check the Support ISupportErrorInfo option and the VB client will be able to receive error information.
To fill in the error info you need to call the Error method in CComCoClass in your ATL component. It has various overloaded versions that allow you to fill in the error info you want to return.
Robert
|
|
|
|
|
Thank you for the reply. So it processes them behind the scenes? Can I tell if S_OK or S_FALSE was returned then? Is S_OK equal to 0 in VB? What type does it return a string or an integer? I tried it with an integer and it did not work or if it returns S_FALSE will it raise an exception in VB?
|
|
|
|
|
Anonymous wrote:
Can I tell if S_OK or S_FALSE was returned then? Is S_OK equal to 0 in VB? What type does it return a string or an integer? I tried it with an integer and it did not work or if it returns S_FALSE will it raise an exception in VB?
Sorry, it's been a long time since I looked at this stuff. I'll try to explain as much as I can remember.
1) Your attempt to return an integer failed because VB requires all COM calls to return an HRESULT.
2) You cannot ever get the original value of an HRESULT in VB because the runtime pre-processes it behind the scenes. You cannot tell if S_OK was returned or if S_FALSE was returned, because you can never get directly at the actual HRESULT returned.
3) Returning a S_FALSE will not raise an error in VB because S_FALSE is actually a success code, not an error code. The first thing VB does when it processes the HRESULT behind the scenes is strip out the low word and check it for a severity level. An S_ code is always considered successful based on the low word, so VB just discards the rest and keeps going. In order for an error to be raised in VB the severity level of the low word must be an error level. So if your method returns E_FAIL, VB will look at the low word of the HRESULT, see it is an error level severity and go from there.
4) What happens in VB if you return an E_ HRESULT depends on how you've written your COM component:
If you support rich error information:
Your COM object must first call SetErrorInfo and fill the EXCEPINFO parameters. (If you are using ATL you can just call "Error(...)" and it provides overloaded constructors that will do all the work for you).
Then your COM object returns an E_ level HRESULT.
VB catches the E_ severity code level and will query your COM object to see if it supports the ISupportErrorInfo interface. Since in this case you do, it will call GetErrorInfo to get the EXCEPINFO structure.
If you do not support rich error information:
Your COM object simply returns an E_ level HRESULT.
VB catches the E_ severity code level and will query your COM object to see if it supports the ISupportErrorInfo interface. Since in this case you don't, VB does not attemnpt to call GetErrorInfo.
Since rich error info is not supported, VB tries to process the high word of the E_ HRESULT and translate it into a VB friendly standard error and standard VB message.
For example, suppose VB calls a method on your COM object and the method returns E_OUTOFMEMORY. The VB runtime strips out the low word, sees it is an error, looks at the high word and maps the error to the standard VB "Error 7 Out of Memory".
Finally,
The only ways to return an actual value to VB if you do not want to raise an error is by a [retval] parameter or by a ByRef [in, out] parameter. Of course all COM calls are functions - they return HRESULTS. But here is how VB interprets COM mmethods:
COM:
HRESULT MySub([in] long mylong);
VB:
Sub MySub(ByVal mylong As Long)
---------------------------------
COM:
HRESULT MySubByRef([in, out] long mylong);
VB:
Sub MySubByRef(ByRef mylong As Long)
----------------------------------
COM:
HRESULT MyFunction([in] long mylong, [out, retval] bool* p_boolRetVal);
VB:
Function MyFunction(ByVal mylong As Long) As Boolean
In all cases you never can get access to the HRESULT values in VB.
Hope this helps ...
Robert
|
|
|
|
|
Sorry, this stuff is complicated.
I have to make a correction to the above statements.
I said you could never get the HRESULT. That is not exactly true.
You can never get S_ level HRESULTS because VB discards them.
You can get E_ level HRESULTs in one of two ways:
If your COM object does not support rich error info, you could reconstruct the original E_ value if you know how to map the VB Err.Number back to an oreiginal E HRESULT. For example E_OUTOFMEMORY returns Error 7 in VB which can be mapped back to 8007000E.
If your COM object supports rich error info then the Err.Number property in VB will correspond exactly to the original HRESULT, i.e if you look at Hex(Err.Number) in VB the value will be 8007000E for E_OUTOFMEMORY.
But for what you were trying to do, i.e get an S_OK or S_FALSE in VB, the answer is still no, you cannot do it.
Robert
|
|
|
|