|
There is sucessful code in VB script but i cannt in C++
Dim DevSought : Set DevSought = Nothing
Dim Dev : Set Dev = Nothing
Dim DSF : Set DSF = CreateObject("DSF.DSF")
Dim ObjSought : Set ObjSought = Nothing
For Each Dev in DSF.Devices
If Dev.HasObject(CLSID) Then
Set ObjSought = Dev.Object(CLSID)
If Not ObjSought Is Nothing Then
Set DevSought = Dev
Exit For
End If
End If
Next
Set EnumSimulatedDevices = DevSought
xuanthinh
|
|
|
|
|
You can try
Set Dev = DSF.Devices(0)
or
Set Dev = DSF.Devices(1)
or test this variables in Debug and Watch window.
***Edit***
I think that Set Dev = DSF.Devices(CLSID) will be OK.
With best wishes,
Vita
|
|
|
|
|
Problem could be in the Variant type. The function might be validating against a different Variant Type.
Instead of VT_INT, try using VT_I4 and set corresponding lVal instead of intVal.
Sohail
modified on Friday, May 9, 2008 3:55 AM
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I was wondering whether the problem is resolved...
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Thanks for all,
Yeah
Instead of VT_INT, try using VT_I4 and set corresponding lVal instead of intVal.
This method is OK.
xuanthinh
|
|
|
|
|
Cool. I thought so, the problem could be there - basically the way the method is internally implemented.
Glad I could help.
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
All,
I have an MFC application and I am using the MSXML parser 4.0. I have the document object declared as a member variable,
<br />
CComPtr< MSXML2::IXMLDOMDocument2 > m_spDoc;<br />
and use the rest as stack variables - like
<br />
MSXML2::IXMLDOMNodePtr pNewChild;<br />
MSXML2::IXMLDOMElementPtr pDomElement;<br />
CComPtr<msxml2::ixmldomelement> spDomElement;<br />
</msxml2::ixmldomelement>
in a function. When I invoke the function the second time, call to createProcessingInstruction of the IXMLDOMDocument2 fails.
So, I thought second time initialization is an issue and hence called it only the first time.
Now, all calls to appendChild or CreateElement fail.
Can anyone tell me how to use the DOMDocument object the second time? Is there any clean up I can do before I invoke the fn the second time?
Cheers
Raja
|
|
|
|
|
It is almost impossible for us to know without more information. We could guess, but there are so many possibilities.
Post your actual code.
|
|
|
|
|
I need to sink some form.onsubmit and input.onlick events in a C# BHO that I'm starting. I tried the method prescribed in MSDN but found that immediately after attaching the event handler the browser would no longer respond to mouse clicks in the tab containing the instrumented document.
After some searching I found this: http://www.dotnet247.com/247reference/msgs/48/241776.aspx[^]
I've tried this solution (see implementation below) and it works fine, and cleared the mouse lockup problem as described. But I am getting persistent DisconnectedContext MDA alerts that I suspect are related to this implementation. These appear at seemingly random times (my guess is when garbage collector runs), but only if I close a browser tab that contains HTML elements that I have attached these event handlers to.
Is it not necessary to remove these event handlers from the HTMLDocument instances that they are attached to, before the document is unloaded (navigate away, close tab), and to remove them on the same thread that instantiated them? If so, how can I do this?
Or am I approaching this in the wrong way? If there is a more robust way to sink mshtml document events in C# please let me know.
A related question: since document (element) references handler, which references document, is it possible that this solution may contribute to IE memory leakage if the event handler is not removed from the document element before the document is unloaded?
public delegate void HtmlEvent(mshtml.IHTMLEventObj e);
[ComVisible(true)]
public class HtmlDocumentEventHandler
{
private mshtml.HTMLDocument htmlDocument;
public HtmlEvent eventHandler;
public HtmlDocumentEventHandler(mshtml.HTMLDocument htmlDocument)
{
this.htmlDocument = htmlDocument;
}
[DispId(0)]
public void Call()
{
this.eventHandler(this.htmlDocument.parentWindow.@event);
}
}
[ComVisible(true)]
public class HtmlDocumentFormElement
{
private mshtml.IHTMLFormElement element;
private mshtml.HTMLDocument document;
public HtmlDocumentFormElement(mshtml.HTMLDocument document, mshtml.IHTMLFormElement element)
{
this.document = document;
this.element = element;
}
public event HtmlEvent onSubmit
{
add
{
object old = this.element.onsubmit;
HtmlDocumentEventHandler handler = old is HtmlDocumentEventHandler ? old as HtmlDocumentEventHandler : new HtmlDocumentEventHandler(this.document);
this.element.onsubmit = handler;
handler.eventHandler += value;
}
remove
{
object old = this.element.onsubmit;
HtmlDocumentEventHandler handler = old is HtmlDocumentEventHandler ? old as HtmlDocumentEventHandler : null;
if (handler != null)
handler.eventHandler -= value;
}
}
}
mshtml.IHTMLFormElement element = form as mshtml.IHTMLFormElement;
HtmlDocumentFormElement formElement = new HtmlDocumentFormElement(this.HTMLDocument, element);
formElement.onSubmit += new HtmlEvent(OnSubmitEventHandler);
Kim Briggs
Kinek Technologies
kim.briggs@kinek.com
|
|
|
|
|
I was curious if anyone currently had a C++ COM Library. I am wanting to use it to create various IE COM functions.
|
|
|
|
|
thatsgreat2345 wrote: I was curious if anyone currently had a C++ COM Library
I have written a few. What are you asking, exactly ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Retrieving the COM class factory for component with CLSID {F9504F0D-7A6C-4373-85B3-DB7E47593270} failed due to the following error: 80040154.
hi in my application, i have one DLL developed by VC++ 6.0( ATL COM Component)... I have added as ref and created object... during the runtime, but i need tot work with web application also using webservice....
i need to access the COM Class in my webservice class file.
while calling, ia have error like this...
Retrieving the COM class factory for component with CLSID {F9504F0D-7A6C-4373-85B3-DB7E47593270} failed due to the following error: 80040154.
can anybody help this issue...please...
Actually this asp.net c# web appplication...
public class JQLiteServer : System.Web.Services.WebService //// ( Webservice class)
{
ClientNotifyNWStorage notifyStorage=null; ( client created class inherited from the COM Interface)
public JQLiteServer ()
{
objectClient = new ClientNotifyNWStorage(); //// ( Here i am having error in this line objClient )
}
}
a.prabakar83@yahoo.com
|
|
|
|
|
I have a C# program that uses a COM object in late binding:
Type DllObj;
object ClsObj;
DllObj = Type.GetTypeFromProgID("MyDLL.MyClass");
ClsObj = Activator.CreateInstance(DllObj);
My problem is that after the call is returned, the DLL MyDLL.DLL is stil in memory. I can see it using the Process Explorer utility.
How can I release that DLL?
My original code used early binding, and I released the COM object after using it by calling System.Runtime.InteropServices.Marshal.ReleaseComObject(). It does not seem to work when I pass it the ClsObj.
|
|
|
|
|
|
thanks but I cannot call CoFreeUnusedLibraries() from a .NET C# code.
|
|
|
|
|
I believe it can be called using P/Invoke just like any other Win32 API.
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I have an application(MFC), which should work with some "registration-free" com-components. I have extended the the application manifest and created a "com-manifest", as shown in the ms-examples. Everything works fine.
BUT, one of my menuitems starts a userthread which needs one of the
"registration-free" com-components, an ocx. The creation of the component succeeeds, but the QuickActivate() fails with an access violation.
Some ideas what goes wrong?
Hoping for help, thank you.
|
|
|
|
|
Jürgen Jung wrote: I have an application(MFC), which should work with some "registration-free" com-components. I have extended the the application manifest and created a "com-manifest", as shown in the ms-examples. Everything works fine.
BUT, one of my menuitems starts a userthread which needs one of the
"registration-free" com-components, an ocx. The creation of the component succeeeds, but the QuickActivate() fails with an access violation.
Some ideas what goes wrong?
Hoping for help, thank you.
A .ocx file sounds like an ActiveX control dll, and ActiveX controls can only run in the user interface thread. It seems likely that whatever object you need to access would need special thread safety additions. If the component you need is itself an ActiveX control, then your problem is more difficuld. You can either find some way to get the control accessed from the UI thread, or you could factor out whatever you need access to into a thread safe component.
Nathan
|
|
|
|
|
Hi,
I am having an issue compiling the ATL/Com dll;
I have Three classes and their interfaces in a com dll as:
1- IMailInterface
2- IMyInterface1
3- IMyInterface2
Now,MFC application uses these interfaces. My application will never directly deal with 2nd and 3rd interface. Everything will be done with the help of IMainInterface. I want to add a method to IMainInterace as
GetMyInterface1(IMyInterface1** ptr); which will retrun the IMyInterface1 pointer
But while comiling getting an error error as:
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18):error MIDL2025 : syntax error : expecting a type specification near "IMyInterface1"
D:\Work_ganesh\MPlusSrvOpticalDevice\Work In Progress\Ganesh\Samples\DemoCOM\DemoCOM.idl(18) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
Error executing midl.exe.
I tried adding header file but it didn’t worked.
Thanks.
"A winner is not one who never fails...but the one who never quits"
|
|
|
|
|
The forward declaration will help:
interface IMyInterface1;
...<br />
[uuid...]<br />
interface IMyInterface : Ixxxx<br />
{<br />
...GetMyInterface1([...]IMyInterface1** ptr); <br />
};
With best wishes,
Vita
|
|
|
|
|
hi,
i wrote a program that changes the titel of a document.(the text that is displayed in the explorer if you enable the column "titel")
i used this sample-code for doing that: http://www.codeproject.com/KB/files/SummInfoPropSetFile.aspx[^]
so far setting the titel works fine, but if i open the file with word and click on properties i should see the whole text i set. but i only see the first letter of the titel text i wrote in the file.
the explorer displays the name correct and in full length so i'm not sure what i am during wrong, can someone help me?
my code to write the titel of files:
<br />
bool FileManager::setNewTitelOfFile(std::wstring path, std::wstring titel)<br />
{<br />
FMTID PropSetfmtid={0xf29f85e0,0x4ff9,0x1068,{0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 }};<br />
<br />
HRESULT hr = S_OK;<br />
IPropertyStorage *pPropStg = NULL;<br />
IPropertySetStorage *pPropSetStg = NULL;<br />
PROPSPEC propspec; <br />
PROPVARIANT propWrite;<br />
<br />
hr = StgOpenStorageEx( path.c_str(),<br />
STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,<br />
STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage,<br />
reinterpret_cast<void**>(&pPropSetStg) );<br />
<br />
if (hr == S_OK)<br />
{<br />
hr = pPropSetStg->Create(PropSetfmtid,<br />
NULL,<br />
PROPSETFLAG_DEFAULT,<br />
STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,<br />
&pPropStg);<br />
<br />
if (hr == S_OK)<br />
{<br />
propspec.ulKind = PRSPEC_PROPID;<br />
propspec.propid = 0x00000002;<br />
<br />
TCHAR titelAsTCHAR[1024]={0};<br />
StringCbPrintf(titelAsTCHAR, 1024, L"%s", titel.c_str());<br />
char titelAsChar[1024] = {0};<br />
<br />
WideCharToMultiByte(CP_ACP,<br />
NULL,<br />
titelAsTCHAR,<br />
static_cast<int>(titel.length()),<br />
titelAsChar,<br />
static_cast<int>(titel.length()),<br />
NULL,<br />
NULL);<br />
<br />
propWrite.pszVal = titelAsChar;<br />
propWrite.vt = VT_LPSTR;<br />
<br />
hr = pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE);<br />
<br />
if (hr == S_OK)<br />
{<br />
pPropSetStg->Release();<br />
pPropStg->Release(); <br />
return true;<br />
}<br />
}<br />
else<br />
{<br />
pPropSetStg->Release();<br />
pPropStg->Release();<br />
}<br />
}<br />
<br />
return false;<br />
}<br />
<br />
<br />
</int></int></void**>
|
|
|
|
|
can nobody help me?
a clue or a guess what the reason could be would be fine too.
|
|
|
|
|
Hey Everybody!
I wrote a COM in C#, and I imported teh tlb in c++, and calling a function without parameters works great!
The problem is that when I call a function in c# that has parameters I'm getting
HRESULT == "E_OUTOFMEMORY"
also, in the output I'm getting:
"Access violation reading location 0x0328fffc."
just to give some more information, here are the functions:
public void printme() { Console.WriteLine("It's ALIVE! ALIVE!"); } // <--- Works great!
public void printme(string text) { Console.WriteLine(text); } <--- returns E_OUTOFMEMORY!
THANKS IN ADVANCE!
|
|
|
|
|
Please, post some C++ code where you call "printme" nethod. I think you have a mistake there.
With best wishes,
Vita
|
|
|
|
|
Thanks!
Here is the C++ code:
::CoInitialize(NULL);
ITestPtr ptrTest;
HRESULT hr = ptrTest.CreateInstance(CLSID_CTest);
BSTR text(L"Text");
::SysAllocString(text); // <-- I tried with and without allocating string.
hr = ptrTest->printme(text);
::CoUninitialize();
Thanks again!
|
|
|
|