|
I have a .lib generated in VC6. How can i create a COM wrapper for this lib( with some related .h files), which can be used within a VC8 application. Since i am not much aware of COM wrapper,please help me with some details....
|
|
|
|
|
If you want to access the exported methods from Managed C++ then I beleive you may want to look at Interoperability topic in .NET.
Following may be helpful, if you require a COM wrapper over existing DLL -
1. Create a new ATL COM DLL project
2. Add a simple ATL object
3. Add methods [and properties, if required] to the interface of this object. These methods [and properties] correspond to the methods in your DLL. You have the declaration in the .H file already
4. Implement these methods [and properties]. Usually you will only call the exported function of your DLL from each method.
Let me know if this helps. Anyone who knows more specific or can correct me, please do.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Thanks...
|
|
|
|
|
How would I distinguish between a normal COM component and an ActiveX control by looking at the code?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
It’s rather simple to write an unmanaged C++ application that crashes when it performs a callback. It’s impossible to write a managed application that does the same, thanks to delegates. - Jeff Prosise
|
|
|
|
|
From MDSN:
At a higher level, an ActiveX control is a COM object that implements several main ActiveX technologies, including regular incoming COM interfaces, the OLE embedding protocol, connection points, and property pages. At a lower programmatic level, ActiveX controls are just COM classes implementing certain families of interfaces. When some client code successfully queries for one of these interfaces, the client code then knows it's dealing with an ActiveX control.
The interfaces exposed by an ActiveX control fall into three general categories. First, ActiveX controls are embeddable objects; that is, they implement most of the OLE Document in-place activation and embedding protocols. ActiveX controls implement the following interfaces: IOleObject, IPersistStorage, IDataObject, IOleInPlaceActiveObject, IOleInPlaceObject, IViewObject2, and IRunnableObject (this is rarely used). Second, ActiveX controls usually support property pages so the client has a means of modifying the control's properties. Finally, ActiveX controls usually implement outgoing interfaces that the client can find out about using COM's connection point technology.
So basically you can determine if it's an ActiveX control by what interfaces it's exposing and whether it has a property page or not.
I got the text from this article[^].
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
|
HakunaMatada wrote: Dunno why I didn't look up MSDN
Nah, you've got to know what to look for as well.
I knew you can tell from the interfaces, but couldn't remember them, and I wanted some writings to refer to.
No worries, mate!
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Can i know how to ping remote systems on windows 2000 professional operating system using WMI can u please provide example in C++.
i have the following script example
strComputer = "PC1;PC2;"
sArray = Split(strComputer, ";")
strDomain = "WOrkArea"
strUser = InputBox("Enter user name")
strPassword = InputBox("Enter password")
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
For each Machine in sArray=
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
"root\CIMV2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" + strDomain)
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
Next
can u please help with c++ code using WMI to run on Windows 2000 professional
Thanks in Advance
abhi
|
|
|
|
|
Hi all ,
I have just started doing COM , I have Written a Code for popup
blocker(I have given it below) .
Whenever a new popup comes the control will call Invoke Method
and goes inside "case DISPID_NEWWINDOW2" and execute
pdispparams->rgvarg[0].pvarVal->vt = VT_BOOL;
pdispparams->rgvarg[0].pvarVal->boolVal = VARIANT_TRUE;
these codes but after this an unhandled exception is coming and I am unable to
do something on it . why it is coming and is there any problem with my code.
I have given all the codes in Implementation file below . Please help me
/////////Code starts here//////////////////
CComQIPtr<iwebbrowser2, &iid_iwebbrowser2=""> m_spWebBrowser2;
CComQIPtr<iconnectionpointcontainer,
="" &iid_iconnectionpointcontainer=""> m_spCPC;
IConnectionPointContainer* connectionPointContainer;
STDMETHODIMP CMyBhoExp::SetSite(IUnknown* pUnkSite)
{
m_spWebBrowser2 = pUnkSite;
if (m_spWebBrowser2 == NULL)
return E_INVALIDARG;
// Retrieve and store the IConnectionPointerContainer pointer
m_spCPC = m_spWebBrowser2;
if (m_spCPC == NULL)
return E_POINTER;
// Retrieve and store the HWND of the browser. Plus install
// a keyboard hook for further use
//RetrieveBrowserWindow();
// Connect to the container for receiving event notifications
return Connect();
//return hr;
}
STDMETHODIMP CMyBhoExp::GetSite(REFIID riid, void **ppvSite)
{
HRESULT hr;
return hr;
}
HRESULT CMyBhoExp::Connect(void)
{
HRESULT hr;
DWORD m_dwCookie;
CComPtr<iconnectionpoint> spCP;
// Receives the connection point for WebBrowser events
hr = m_spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &spCP);
if (FAILED(hr))
return hr;
// Pass our event handlers to the container. Each time an event occurs
// the container will invoke the functions of the IDispatch interface
// we implemented.
hr = spCP->Advise( reinterpret_cast<idispatch*>(this), &m_dwCookie);
return hr;
}
HRESULT CMyBhoExp::Invoke(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags,DISPPARAMS * pdispparams, VARIANT * pvarResult,EXCEPINFO * pexcepinfo, UINT * puArgErr)
{
switch(dispidMember)
{
//Pop up blocker
case DISPID_NEWWINDOW2:
TRACE("Pop Up Blocked");
pdispparams->rgvarg[0].pvarVal->vt = VT_BOOL;
pdispparams->rgvarg[0].pvarVal->boolVal = VARIANT_TRUE;
break;
case DISPID_DOCUMENTCOMPLETE:
TRACE("\ncase DISPID_DOCUMENTCOMPLETE:");
break;
}
return S_OK;
}
//////////////////////Code ends here////////////////////////
Thanks
George
|
|
|
|
|
Hai All,
How can I minimize , maximize or close my Internet Explorer Main Window
by using Browser Object, that I am recieving in SetSite().
Please Help me
Thanks in Advance
George
|
|
|
|
|
when I use IWebBrowser2::goForward() or goBack() method in thread that begin from overrided SetSite() method, Browser Helper Object with InternetExplorer occur Error window.
"Memory Access Violation..."
why occur this Exception? here is that part of code.
void SensorWorker( LPVOID lParam )
{
USHORT x,y;
int shock, count = 0, exe = 0;
ACCELREPORT data;
if(sensorFunction) {
sensorFunction(&data);
x = data.LatestZeroG_X;
y = data.LatestZeroG_Y;
}
CIESensorMove * bControl = (CIESensorMove *)lParam;
CString str;
CComBSTR bstrURL("http://www.naver.co.kr");
CComVariant vtEmpty;
while(1){
if(sensorFunction != 0){
sensorFunction(&data);
shock = (int)data.LatestAccelDataY - (int)y;
if(shock == 0 ) exe = 0;
if(bControl->m_spWebBrowser2 != NULL && exe == 0)
str.Format("%d", count);
if( shock > 3 ){
// bControl->m_spWebBrowser2->GoForward();
bControl->goForward();
count++;
exe = 1;
bControl->m_spWebBrowser2->put_StatusText(str.AllocSysString());
// bControl->m_spWebBrowser2->Navigate(bstrURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty);
Sleep(200);
}else if (shock < -3){
// bControl->m_spWebBrowser2->GoBack();
bControl->goBack();
count--;
exe = 1;
bControl->m_spWebBrowser2->put_StatusText(str.AllocSysString());
Sleep(200);
}
}
Sleep(100);
}
}
|
|
|
|
|
The explanations for the crashes can be numerous, but one serious conceptual error has been made in the code you provided:
You've spawned a secondary thread that uses the interfaces you've got in the main thread.
When you access COM servers from other threads than the one that created the server, you have to (a) initialize the new COM apartment with a call to CoInitialize() and (b) marshal the interface to the secondary thread.
You have to fix this before digging further down in your chase for the cause of the crashes.
You can read about it in MSDN[^], or Lim Bio Liong's excellent articles on the subject here (1)[^] and here (2)[^].
Hope this helps
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Hello All,
I have small and simple COM program to access a Add function in Dll and I am accessing this function from main program.
For the simple add function it is working, interface and dll files are working properly.
For this interface I am trying to add one more function by name getdate() which of return Char* .. can any one please help how to declare the getdate() function in interface ???
Below are declaration and files with there names ….
// File interface.h
// This file contains interface related declarations.
#ifndef _A_INTERFACE_H_
#define _A_INTERFACE_H_
DECLARE_INTERFACE_(IMyA,IUnknown)
{
STDMETHOD_(LONG,MyAdd)(INT,INT) PURE;
};
--- ---
--- ---
file :- MyA.h
class CMyA : public CCmdTarget
{
DECLARE_DYNCREATE(CMyA)
CMyA();
-- -- -- - - -- -- -- - -
-- -- -- - - -- -- -- - -
-- -- - -
-- -- - --- -- -- - --- -- -- - -
protected:
virtual ~CMyA();
DECLARE_MESSAGE_MAP()
BEGIN_INTERFACE_PART(MyAObj,IMyA)
STDMETHOD_(LONG,MyAdd) (INT,INT);
END_INTERFACE_PART(MyAObj)
DECLARE_INTERFACE_MAP()
DECLARE_OLECREATE(CMyA)
};
// MyA.cpp : implementation file
-- -- -- --- -- --
//IMyA Functions
STDMETHODIMP_ (LONG)
CMyA::XMyAObj::MyAdd (INT x,INT y)
{
return (x+y);
}
-------------------------------
// function to be added to Interface can u please help me how to declare this function in interface.
char* getDate()
{
struct tm *newtime;
char am_pm[] = "AM";
-- - - -
--- - -- - - -
}
Thanking you,
Suresh H.
|
|
|
|
|
Hi All,
I need to know how can i call from application that i wrote in C++ in visual studio 6 a function from C# ( visual 2005 ) application ?
What i mean is call function in way like calling com interface function - ( in com i can call function from application X that i have pointer to it in application Y ).
Can i do it ?
Thanks for any help.
|
|
|
|
|
Yanshof wrote: What i mean is call function in way like calling com interface function - ( in com i can call function from application X that i have pointer to it in application Y ).
read Interoperability dude~
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Hi,
How does one go about implementing an event sink (in CLI C++) for a COM object that supports the IConnectionPoint interface without access to it's type library. In essence, how can it be done late-bound at runtime?
More information:
I'm having trouble implementing a late bound event sink (without a type library). I would like to subscribe to events from a COM object that implements the IConnectionPoint interface. I instantiate the object using Activator::CreateInstance . I then enumerate its connection points using IConnectionPointContainer::EnumConnectionPoints . Upon successfully obtaining a pointer to the IConnectionPoint interface, I call its Advise function like Advise(this, cookie) , where this is a simple public ref class. Initially, the function was failing with a Cast Exception. However after specifying the ComVisible(true) for the class, the function succeeded returning a cookie.
Now, my issue is, the source COM object uses the IDispatch and IUnknown interfaces of the object I pass it to determine what events to send and to actually send the events. How can I specify my own implementations of these two interfaces, so that they get called instead of the default system implementation? Maybe I am approaching this the wrong way, but I haven't found any documentation regarding late-bound event handling from COM objects.
Thanks!
|
|
|
|
|
An event sink is just an interface, typically an IDispatch interface. If it is an IDispatch interface normally you only need to implement IDispatch::Invoke .
Steve
|
|
|
|
|
Thanks for your response.
I guess what I meant was, how would you go about doing it in CLI/C++. How can I define a managed class that implements the IDispatch interface in CLI/C++ because apparently the base class for all managed types (Object ) internally implement the IDispatch / IUnknown interfaces. How can I override the default implementation with my own? Thanks!
|
|
|
|
|
If you're making a source inteface you'll probably want to assign the DISPID explictly. See here[^]. I'm no dotNET expert however; I'm a C++ programmer with no plans to "upgrade" unless forced (which will probably happen sooner or later).
Steve
|
|
|
|
|
Thanks, I'll give it a shot. For the time being I resorted to wrapping the functionality I required in a native COM C++ class and calling it using marshaling from my managed code. Thanks again!
|
|
|
|
|
hi
i have to include one namespace in my program but i don't know the dll file in which it is present how can i know the name of the dll in which that namespace present.
thanks in advance.
|
|
|
|
|
We have to implement a com server as an executable which will be communicating with a COM dll. COM server would need to call certain functions in COM dll and the com dll would also need to invoke certain functions in the com exe. That is, both would be acting as a server as well as a client. What are the design issues to be considered? Any code samples, tips and suggestion would be most welcome.
Thanks
C++beginer
|
|
|
|
|
When thinking in terms of "client" and "server" it's generally a good idea not to mix those two up.
Or to put it in other words: the server serves the client in the aspect of solving a problem which usually is well defined and the server is considered a black box and you don't know how it looks inside and neither want to know nor need to.
If you somehow get the impression that the client should serve the server, you should generally get suspicious.
If the server need information from the client it does not call the client; the server is provided the information by a call from the client presumably in a struct defined in the IDL-file for the server, or through method parameters.
A situation where the server actually calls the client would be during an asynchronous operation when the server informs the client that the operation has finished, e.g. connection points.
If you still think your client should behave like a server, please describe your problem further.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Hi !!
I have to port an OLE Server from W2K to WXP. I didn't create the code (that was russian guys infact).
At the moment, We will consider, there is only One Server and One Client (an OCX). Both are in VC++ 6.
The first approach was to simply install the package (which was working under w2K) on the WXP computer.
Then, we saw that when the OCX connects to the Server, both the server and the OCX crashes.
The second approach, was to compile them under WXP, and then launch it. no changes, the server and the OCX crashes.
Third thing i did, I launched the Server and the Client step by step and saw where exactly it crashes. The server crashes on a DispatchMessage instruction in the _tWinMain function. But what makes the server to crash is a AfxConnectionAdvice instruction. I got no explanation. My understanding of technical aspects of COM is quite limitated. I Just started to retrieve some tuorials, aso...
I looked further to see what could make that to crash, and didn't foud a lot of informations a bout a similar problem.
I finally stepped over the AfxConnectionAdvice and the server didn't crash. but the OCX still had problems elsewhere. the list is quite long.
My questions are :
- what could make this happened ?
- What could be the good method to solve this issues ?
- What are the points to check ?
Thanks very much for your answers
Sebastien
|
|
|
|
|
Does anyone know how to convert pdf to tiff via Acrobat 5 writer automation?
I need sources.
Thanks,
Dudi
|
|
|
|
|