|
I need to invoke a script function programmatically through c++. I have the relevant html doc and there will be several script tags. I have the collection of tags and loop through them to find the script function. However, when I get to the script element that I know contains the function, the GetIDsOfNames method always returns "Unknown name."
CODE SAMPLE
CComBSTR bstrMember("SCRIPT");
pDoc3->getElementsByTagName(bstrMember, &pEltColl);
long len;
pEltColl->get_length(&len);
for(int i = 0; i < len; i++ )
{
CComPtr<idispatch> pEltDisp = NULL;
hr = pEltColl->item( CComVariant(i), CComVariant(i), &pEltDisp);
if(SUCCEEDED(hr))
{
IHTMLScriptElement* pElem = NULL;
hr = pEltDisp->QueryInterface( IID_IHTMLScriptElement, (void**)&pElem );
IDispatchPtr spDisp( pElem );
if(SUCCEEDED(hr))
{
OLECHAR FAR* bstrMember = L"MyFunction";
DISPID dispid = NULL;
**************Things go wrong here****************************
hr = spDisp->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(SUCCEEDED(hr) && dispid )
{
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1;
//Call JavaScript function
hr = pEltDisp->Invoke(dispid,IID_NULL,0,
DISPATCH_METHOD,&dispparams, &vaResult,&excepInfo,&nArgErr);
}
}
}
}
Suggestions would be welcome
|
|
|
|
|
I tried using the type library for Microsoft Mappoint to generate classes I need to use the activex control on my dialog, but couldn't seem to see any way to make that work. Now I've tried generating classes from the .ocx file, and that seems to give me all the classes I need for what I'm trying to do. However, I have no idea how to actually display the control on my dialog. There's a CMappointCtrl class that was generated, and all I see in the member functions is CreateDispatch(), not a Create() since it's not derived from CWnd. Also, there's a bunch of other classes that came from the .ocx that I would like to use (like CRoute,CMap). How can I use these with the control? Any help is appreciated. thanks
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
no.1 I've disabled all the virus software ,fireware&Internet Assistant
no.2 I've try to import the related item into register and copied dll files to system directory
but the Activex Control can not work still, hot can... how can I do?
<object id="factory" viewastext="" style="display:none"
="" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="/scriptx/ScriptX.cab#Version=6,1,431,1">
|
|
|
|
|
Hello All,
I have a question which I hope my esteemed peers here will be able to provide some comments :
1. After some time of researching, I found that a COM Object in a COM EXE Server cannot decide on its own Apartment Model (Apartment, Multithreaded, etc).
2. This is so despite indicating the model you want when creating an ATL COM object inside an EXE Server using the ATL Wizard.
3. The way to indicate the Apartment Model for your COM Object is to place your call to CoRegisterClassObject() on your COM Object Class Factory in a thread that has been initialized with CoInitializeEx(NULL, COINIT_MULTITHREADED) or CoInitializeEx(NULL, COINIT_APARTMENTTHREADED).
Any comments on this from anyone ?
Many Thanks, All,
Bio.
|
|
|
|
|
Hi Bio
Inspecting the CAtlExeModuleT class (from the ATL classes shipping with VC.net 2003), I notice the InitializeCom method, quoted below;
<snip>
static HRESULT InitializeCom() throw()
{
#if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) & defined(_ATL_FREE_THREADED)
return CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
return CoInitialize(NULL);
#endif
}
<snip>
which would lead me to believe that by setting _WIN32_WINNT, _WIN32_DCOM, and/or _ATL_FREE_THREADED to the desired values, you would be able to have the server enter the apartment of your choice.
HTH
Martin
|
|
|
|
|
Hello Martin,
Thanks very much for your advise, Martin. I was also observing the difference between a COM DLL Server and a COM EXE Server in terms of specifying the Apartment Model of objects.
DLL server objects indicate their individual Apartment Model in the registry. The ATL Wizard arranges for this. One advantage of using a DLL-based server is that you can specify two objects of different Apartment Models in the same server.
For Exe Server objects, I'm now wondering if it would be possible to specify two object classes with different Apartment Models. I think it may not be possible to do this using ATL. You would have to manually create threads to register the class factories. I'll do some experiments to confirm this.
Thanks again, Martin,
Bio.
|
|
|
|
|
i Don't know if this the right thread to post.. but...
our company is planning to buy a third party ActiveX/COM component.
But we need to use it in Java Code... I was wondering if I could call the COM component using J#?
|
|
|
|
|
I am wanting to use COM controls in my management scripts written in VBS. Which controls are available to me and how can I use them.
Thanks in advance.
God answers knee mail.
|
|
|
|
|
I am porting an app from VB to C++, it uses Crystal Reports and in the VB app an event is handled using the "Handles" operator, I now need to handle that event in C++.
I am #import'ing the CRAXDDRT20.dll and using the IApplicationPtr and IReportPtr objects to initialise and start a report export, the event fired is called "BeforeFormatPage" in VB, how would I go about handling it in C++? (This is the first time I have used COM in C++ BTW)
|
|
|
|
|
|
I have read that and played around with the example but I just don't get it.
I have found this code in the .tlh file for my object:
#pragma implementation_key(2)
inline HRESULT CRAXDDRT20::IReportEvent::BeforeFormatPage ( long PageNumber ) {
return _com_dispatch_method(this, 0x2, DISPATCH_METHOD, VT_EMPTY, NULL,
L"\x0003", PageNumber);
}
Does that give any clues as to what direction I should be heading in.
Sorry if this sounds really dumb, I feel really dumb, I can normally understand and make most things work but COM is really baffling me
Cheers,
Dan.
|
|
|
|
|
Why are you reading .tlh file sir!,that the compiler generate for you when you import COM dll in your project.
i think you Event returning LONG as parameter
"I Think this Will Help"
Alok Gupta visit me at http://www.thisisalok.tk
|
|
|
|
|
It was the .tli file, not .tlh, that was a typo but it was the only file I could find a reference to the event I was interested in and so thought it might provide a clue as to how to capture the event.
As for importing a COM dll into my project, I have never done that, would that possibly be a step towards capturing this event?
I am not using MFC or classes BTW, just plain C.
|
|
|
|
|
I am always getting a return value of E_INVALIDARG when the function AddNamedCommand is called:
CComPtr<envdte::command> pCreatedCommand;
hr = pCommands->AddNamedCommand(m_pAddInInstance, CComBSTR(commandname), CComBSTR(commandtext), CComBSTR(tb_name), VARIANT_FALSE, IDB_LOGO, NULL, EnvDTE::vsCommandStatusSupported+EnvDTE::vsCommandStatusEnabled, &pCreatedCommand);
IDB_LOGO is a 16x16 Bitmap.
I am using Visual Studio .NET 2003 on Win XP SP2. I have looked at the documentation and at other examples but I can't find where I am going wrong. I have exactly the same code as everybody else, but theirs works fine.
Any ideas?
I am the handsome one in the crowd.
|
|
|
|
|
Hello,
I want to implement an ActiveX Control (made in VB6) in VB 6 application.
It is working fine on my system, but if i am going to implement it on different computer it giving error like "The connection cannot be used to perform this operation. It is either closed or invalid in its context."
abc
|
|
|
|
|
Hi,
I'm pretty new to all this interop stuff, and I've come up against a bit of an obstacle. In my method I'm trying to return an instance of another class from C# assembly. Great! Except it doesn't work. I keep getting Error 5 "Object variable or with block not set" in my VB client. Here's some sample code I knocked together to demonstrate...
C# COM Server
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace COMReturnTest<br />
{<br />
[Guid("883EF833-3874-4831-9757-B44E987E80DF")]<br />
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]<br />
public interface _ReturnType<br />
{<br />
string TestString { get; }<br />
int TestInt { get; }<br />
}<br />
<br />
[Guid("29B3F02E-27A6-4535-8835-62D23BA2DA1E")]<br />
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]<br />
public interface _TestClass<br />
{<br />
COMReturnTest._ReturnType StringEmptyTest();<br />
COMReturnTest._ReturnType StringNullTest();<br />
COMReturnTest._ReturnType StringSetTest();<br />
System.String StringReturn();<br />
}<br />
<br />
[Guid("01A699E1-05ED-404e-A5B9-7C2735F97268")]<br />
[ClassInterface(ClassInterfaceType.None)]<br />
[ProgId("COMReturnTest.ReturnType")]<br />
public class ReturnType : COMReturnTest._ReturnType<br />
{<br />
#region class members<br />
<br />
private string _teststring = String.Empty;<br />
private int _testint = 0;<br />
<br />
#endregion<br />
<br />
#region class constructors<br />
<br />
public ReturnType(string TestString, int TestInt)<br />
{<br />
_teststring = TestString;<br />
_testint = TestInt;<br />
}<br />
<br />
#endregion<br />
<br />
#region _ReturnType Members<br />
<br />
public string TestString<br />
{<br />
get { return _teststring; }<br />
}<br />
<br />
public int TestInt<br />
{<br />
get { return _testint; }<br />
}<br />
<br />
#endregion<br />
}<br />
<br />
[Guid("73FB94E2-23EA-4e2c-A366-B234415FB4FE")]<br />
[ClassInterface(ClassInterfaceType.None)]<br />
[ProgId("COMReturnTest.TestClass")]<br />
public class TestClass : COMReturnTest._TestClass<br />
{<br />
<br />
public TestClass()<br />
{<br />
}<br />
<br />
#region _TestClass Members<br />
<br />
public COMReturnTest._ReturnType StringEmptyTest()<br />
{<br />
COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(String.Empty, 100);<br />
return rt;<br />
}<br />
<br />
public COMReturnTest._ReturnType StringNullTest()<br />
{<br />
COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(null, 100);<br />
return rt;<br />
}<br />
<br />
public COMReturnTest._ReturnType StringSetTest()<br />
{<br />
COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType("bugger", 100);<br />
return rt;<br />
}<br />
<br />
public String StringReturn()<br />
{<br />
return "Buggeration!!!";<br />
}<br />
<br />
#endregion<br />
}<br />
}<br />
The StringReturn function is just in there to make sure I can return something. Which I can!
VB6 Client
<br />
Option Explicit<br />
<br />
Private Sub Command1_Click()<br />
On Error GoTo Command1_Click_Err<br />
<br />
Dim tc As New COMReturnTest.TestClass<br />
Dim rt As COMReturnTest.ReturnType<br />
rt = tc.StringEmptyTest<br />
<br />
Command1_Click_Err:<br />
MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _<br />
"Description: " + Err.Description + vbCrLf + "Source: " + Err.Source<br />
End Sub<br />
<br />
Private Sub Command2_Click()<br />
On Error GoTo Command2_Click_Err<br />
<br />
Dim tc As New COMReturnTest.TestClass<br />
Dim rt As COMReturnTest.ReturnType<br />
rt = tc.StringNullTest<br />
<br />
Command2_Click_Err:<br />
MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _<br />
"Description: " + Err.Description + vbCrLf + "Source: " + Err.Source<br />
End Sub<br />
<br />
Private Sub Command3_Click()<br />
On Error GoTo Command3_Click_Err<br />
<br />
Dim tc As COMReturnTest.TestClass<br />
Dim rt As COMReturnTest.ReturnType<br />
Set tc = New COMReturnTest.TestClass<br />
rt = tc.StringSetTest<br />
<br />
Command3_Click_Err:<br />
MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _<br />
"Description: " + Err.Description + vbCrLf + "Source: " + Err.Source<br />
End Sub<br />
<br />
Private Sub Command4_Click()<br />
On Error GoTo Command4_Click_Err<br />
<br />
Dim tc As COMReturnTest.TestClass<br />
Dim str As String<br />
Set tc = New COMReturnTest.TestClass<br />
str = tc.StringReturn<br />
<br />
Command4_Click_Err:<br />
MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _<br />
"Description: " + Err.Description + vbCrLf + "Source: " + Err.Source<br />
End Sub<br />
Now having extensively googled (and I do mean extensively!) I've come to the conclusion that all I'm missing is some kind of attribute decoration, probably on the methods in the class. Infact I've been tinkering with the MarshalAs attribute with the UnmanagedType.IDispatch , UnmanagedType.Interface and UnmanagedType.IUnknown parameters. (With the return: override of course.) These don't seem to have much of an effect.
Has anyone done this kind of thing before? If you have, how did you do it? And if not, any pointers? Please?!?
Cheers, Steve
|
|
|
|
|
Of course after about twenty hours looking at this I discovered what the error was immediately after posting!!!
steve_hocking wrote:
Private Sub Command3_Click()<br />
On Error GoTo Command3_Click_Err<br />
<br />
Dim tc As COMReturnTest.TestClass<br />
Dim rt As COMReturnTest.ReturnType<br />
Set tc = New COMReturnTest.TestClass<br />
SET rt = tc.StringSetTest<br />
<br />
Command3_Click_Err:<br />
MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _<br />
"Description: " + Err.Description + vbCrLf + "Source: " + Err.Source<br />
End Sub
You need to SET objects in wonderful vb...
Thanks anyway, I'm just getting me coat, if you can call a taxi for me...
|
|
|
|
|
Hi!
I'm trying to use WIA Automation component to use a web cam (a standard Logitech USB) in a .Net app.
The API makes it very straightforward to grab one picture from the camera or to get a video preview (OCX) automatically embedded in a window. Neat.
Now my problem is that I actually want to get a video stream -- that is images, possibly between 1 and 10 frames per second. The "TakePicture" command is the only command support by the device, it cannot work at the same time than the VideoPreview and anyway taking one snapshot takes between 3 and 10 seconds (it seems to reinitialize the camera each time!)
So... how am I supposed to use this API to do anything useful with a video device besides automatic preview?
|
|
|
|
|
I want to use Band in Box with the rme Digi96/8 PAD but i cant get a virtual MIDI device running.
I tried Roland Virtual Sound Canvas or otherwise the Microsoft GS Wavetable SW Synth.
Using DxDiag i can test Microsoft GS Wavetable SW Synth and Tadaa it works over the Digi96 but its not possible to use it in System Audio Settings.
After hours searching the registry to activate SW Synth working with my Digi96, i gave up!!
I need help!!!!!
|
|
|
|
|
Hi All!
I am new in C++ but I am mad to listen voice of Telephone line via a Sound Card in my PC...
How can I write soft to forward voice (normal voice of telephone user)from the modem to the PCI Sound Card??? And then my microphone sound from Sound Card into the modem connected to the phone line...
Any idea? for Visual C++6 or Borland C++...
I do love comments a lot...in code...
Thanks
Vova
vovik@indiatimes.com:
sigh:
|
|
|
|
|
I think You are looking For TAPI i.e. Telephone API,you will good reference for it in DEVELOPER GUIDE to Visual C++ and MSDN
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
if you wanna start programming you should run away from windows
and thy b*!"#%!#$%
|
|
|
|
|
|
I'm very new to COM. For some reason I just cannot seem to create this object CLSID_VideoMixingRenderer9. I'm basically using code copied right out of the DirectX SDK. The program compiles fine but when the program runs CoCreateInstance returns doesnt create the object. I've compaired the HRESULT returned from CoCreateInstance to the possible return values listed for CoCreateInstance but none of them match. The value of HRESULT is -2147220877.
PLEASE HELP THIS IS DRIVING ME OUT OF MY MIND.
|
|
|
|
|
Either DirectDraw has not been installed or the Video Card capabilities are not suitable. Make sure the display is not in 16 color mode.
modified 21-Apr-21 21:01pm.
|
|
|
|