|
A COM DLL is a regular DLL with some restrictions on it: It must export the 5 functions DllMain , DllCanUnloadNow , DllGetClassObject , DllRegisterServer and DllUnregisterServer . Technically, the last function isn't really needed to run COM stuff, but if you want to uninstall the COM DLL, it's nice to be able to remove references to it in the registry.
To load a DLL:
HMODULE hDLL = LoadLibrary(_T("the.dll"));
if(!hDLL) exit(-1); To acquire a function pointer to a function inside the DLL:
void (*function)();
function = (void (*)())GetProcAddress(hDLL, "TheNameOfFunction");
if(!function) exit(-1);
function(); And finally, if you are done with the DLL, and you wish to unload it, call
FreeLibrary(hDLL); There's also LoadLibraryEx which might be interesting to have a look at.
Did I answer your question? The MSDN Library has all the information you need to manuall load and use DLLs.
--
My name in Katakana is ヨルゲン.
My name in German is Jörgen.
My name in Mandarin/Kanji is 乔尔根 西格瓦德森.
My name in Korean is 요르겐.
I blog too now[^]
|
|
|
|
|
yes by using the above stuff i can create an object
how will i call the interface methods and all the vtbl stuff
thanks for such a neat reply very well explained thanks
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Ah, you meant COM object methods, and not functions exported by the DLL. I see. In that case: what Mike said.
--
My name in Katakana is ヨルゲン.
My name in German is Jörgen.
My name in Mandarin/Kanji is 乔尔根 西格瓦德森.
My name in Korean is 요르겐.
I blog too now[^]
|
|
|
|
|
You use CoCreateInstance as before. To call an instance method, you need the header file generated from the source IDL by midl . Instead of writing, for example
p->GoForward() you would write
IWebBrowser_GoForward(p) That is, you prefix the call with the name of the interface and pass the object as the first parameter of the call. IWebBrowser_GoForward is actually a macro that masks the explicit dereference:
p->lpVtbl->GoForward(p) I'd seriously query why you're using it from C, though - it's perfectly possible to make a hybrid C/C++ app where some modules are compiled as C and others as C++.
[EDIT:] On re-reading the ExDisp.h header file (just an example, it contains the IWebBrowser interface I referred to earlier) it looks like you only get the interface_method macros if you define COBJMACROS . [/EDIT]
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
thanks that's a good insight
i agree the c/c++ hybrid application is the best way to go about it, i just want to have enough info on the subject before i start convincing them
that it is a bad and time consuming idea
thanks for reply
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Hi!
I have observed that when a COM object is created its QI method is called for the following interfaces:
1. IUnknown
2. IMarshal x2
3. {0000001B-0000-0000-C000-000000000046} (IdentityUnmarshal ??)
4. IUnknown
5. ISdtMarshalInfo
6. IExternalConnection
7. {4C1E39E1-E3E3-4296-AA86-3C938D896E92}
8. IManagedObject
9. IConnectionPointContainer x2
10.{1C73A30-2A1C-11CE-ADE5-00AA0044773D}
11. IFeed (this is my interface)
12. {1C73A30-2A1C-11CE-ADE5-00AA0044773D}
13. IFeed
Could any of you explain where these calls come from?
Could be SCM doing his things? Proxy/Stub related?
Thanks in advance
Gizzo
|
|
|
|
|
Simple OOPS concept of Construction and Destruction
Ifeed Derived From IConnectionPointContainer which from IManagedObject from IExternalConnection from iSdtMarshalInfo with Super One IUnknown
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Hi again,
IFeed is my interface and it is derived from IDispatch. The class that implements IFeed is CFeedCOM... i think i'm going to post it...
class CFeedCOM : public CReferenceCountedObject, <br />
public IFeed,<br />
public ISupportErrorInfo,<br />
public IConnectionPointContainerImpl<CFeedCOM>,<br />
public CProxy_IFeedEvents<CFeedCOM>
CReferenceCountedObject is taken from Lim Bio Liong (this guy have saved my life with his articles).
The reason I wanted to know what happens under the hood of an object creation is:
When a client fails (sometimes, not always) the next client trying to connect to the server doesn't follow the same steps that the previous one. Instead of querying all the interfaces posted in my previous message, my object is asked for:
1. IUnknown
2. IMarshal x2
3. {0000001B-0000-0000-C000-000000000046}
4. IID_IUnknown
And now, something happens, and my object is released until m_cRef goes to zero. Then, QI is called for IManagedObject, m_cRef is incremented to 2, and again released until zero. This causes the destruction of my object of course what I'm trying to avoid.
I don't know if I explained the problem. I only want to know what is happening there.
Thanks for answering.
Best regards,
Gizzo.
|
|
|
|
|
Hi,
I have made a DOCOM Server which is running as service in different machine and i want to use that server it in other machine within a service.how it can be possible plz help me out..
ajay
|
|
|
|
|
I have written an ActiveX control, which can display static and dynamic image. So I can use it in an IM app like MSN to show some interesting expression. To test the control, I have written a subclass of richedit control, I can insert my control into the richedit now, and I have implemented some methods of IRichEditOleCallback so that can copy and paste the controls inserted in the richedit, it can save/load the controls and text in the richedit into/from a RTF file, too. But the test result made me sad, I can copy and paste a standard OLE object like a POWERPOINT file in the richedit, if I copy the control written by me, it failed, it seems my control had been copied and pasted successfully, because the richedit control remained a blank rectangle for my control in the position where it should be pasted to, but only a blank rect, no image was display.
From the test result, my conclusion is, my richedit is a good one, what should I modify is my ActiveX control, but I don't know what to do exactly to achieve my goal. I hope someone can help me, anyone who has the experience can contact me with MSN, my MSN ID is:gxulg@hotmail.com Thanks.
learn to be still.
|
|
|
|
|
How can i write a program can get text on screen at position of mouse cursor.
le van giang
|
|
|
|
|
I am writing a program which does not let the user copy a specific folder in windows explorer. The way to do this is to implement ICopyHook interface.
The dll has been registered at:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\CopyHookHandlers\MyHook
I have tried code like this:
class ATL_NO_VTABLE CMyHook :
public ICopyHook
{
BEGIN_COM_MAP(CMyHook)
COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook , CMyHook)
END_COM_MAP()
STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs);
};
This function never gets called. Instead when I try to copy a folder, I get the following message:
Cannot copy (foldername): Invalid MS-DOS function.
What to do?
Please F1 !
|
|
|
|
|
I understood my own code finally.
Create a ATLCom Appwizard.
Insert a simple atl object.
Then add one line: public ICopyHook to the parent list.
Comment the other as shown.
To the COM_MAP, add one line, comment the others:
COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook)
class ATL_NO_VTABLE CMyHook :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CMyHook, &CLSID_MyHook>,
public ICopyHook
// public IDispatchImpl<IMyHook, &IID_IMyHook, &LIBID_MYHOOKLib>
{
public:
CMyHook()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_MYHOOK)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CMyHook)
// COM_INTERFACE_ENTRY(IMyHook)
// COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook)
END_COM_MAP()
STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs,
LPCSTR pszDestFile, DWORD dwDestAttribs);
// IMyHook
public:
};
The above code works and in the function CopyCallback, you can handle the folder copy event. Of course the registry key also has to be set.
Thanks for reading. Hope it works for all.
|
|
|
|
|
khan++ wrote:
I understood my own code finally.
That's probably a good thing
--
My name in Katakana is ヨルゲン.
My name in German is Jörgen.
My name in Mandarin/Kanji is 乔尔根 西格瓦德森.
My name in Korean is 요르겐.
I blog too now[^]
|
|
|
|
|
I do not know English well, therefore use machine translation...
I created ActiveX component by means of MFC ActiveX wizard.
By means of ClassWizard I created event. Like this:
FireNetConnectOne() - NetConnectOne() event
BOOL CEasyCtrl::GoOnline() // this is just property...
{
FireNetConnectOne(); // All ok.
return GoOnlineB();
}
BOOL a()
{
FireNetConnectOne(); // error!!!
return TRUE;
}
I know FireNetConnectOne() is a member of CEasyCtrl and i can not call it from my code...but..i must...
Question: how to call FireNetConnectOne() event from simple function?
note: FireNetConnectOne() is a protect member of the CEasyCtrl.
|
|
|
|
|
I have been trying to use the Microsoft ServerXMLHTTP object to connect to a remote server. I have also tried using WinHTTP. When I connect to a remote server over HTTPS, I would like to be able to parse the remote server's certificate and validate it against my own list of Certificate Authorities (CA's), make sure the URL in the certificate is correct, and also make sure it hasn't expired. With WinHTTP and XMLHTTP, it doesn't seem that I can do that. Is there another COM object I can use (hopefully it's free or low-cost) or is there a way to write my own COM object that will do that?
Thanks.
|
|
|
|
|
I have written a COM add-in for Word, Excel and PowerPoint. It adds a new menu with three items to each of these applications. The menu items simply add a certain phrase to the header of the active document.
In Excel and PowerPoint it works perfectly. In Word it also works perfectly, but only on the first instance of Word. I.e. if I open Word for the first time it works, but if I then click the “New” button (which pretty much starts another instance of Word) my menu items do nothing. If I Alt-Tab back to the first document, it works again.
If I go to Tools-Options and uncheck the “Windows in Taskbar” option on the “View” tab, the problem is gone and my add-in works perfectly regardless of which document is active. In Excel and PowerPoint it is not necessary to change this option.
This confuses me terribly, because it is the exact same code that executes for all the applications. I even changed my click event to simply show a message box (no reference to the application objects) and it still doesn’t work!
I don’t want to force my client to disable the “Windows in Taskbar” option in order to use this add-in. What must I do differently in Word to make it behave like the other two applications?
Any advise or suggestion will be GREATLY appreciated!
Johannes Ackermann
|
|
|
|
|
OK, so let's do our duty and inform everyone that I've found a solution to the problem. After posting the question on countless forums, sending e-mails to everybody I could find and even contacting Microsoft's support desk, I waited a week and a half with not so much as a "sorry, dude... you're on your own"!
Well, for the benifit of other poor souls who might run into the same problem and who can obviously not rely on the "gurus" on the forums: I have found the solution. It is a silly little quirk in Word which, according to Microsoft, is there by design. The fact that it is NOT there by design in all the other Office applications is beyond me, but there you have it.
For each CommandBarControl you HAVE to specify a unique value in its Tag property. Simple, heh?
Read all about it here: http://support.microsoft.com/kb/826931/EN-US/
Thanks for nothing, guys.
Johannes Ackermann
|
|
|
|
|
hi,
I want to simulate a new com server object on installation with the same binary. this means I have a com server as service e.g. MyServer.exe with interface IMyInterface. so I can access it with ProgID "MyServer.IMyInterface".
but I have to start up more instances and for this I want to rename the MyServer.exe to SecondServer.exe, register as service and now access it through ProgID "SecondServer.IMyInterface".
e.g.
MyServer.exe in c:\MyServer\MyServer.exe
SecondServer.exe in c:\SecondServer\SecondServer.exe
and calling
*CreateObject("MyServer.IMyInterface") should start up instance of MyServer
*CreateObject("SecondServer.IMyInterface") should start up instance of SecondServer
Now I need the registry entries com uses to create the object and I will give the SecondServer new uuid.
So in other words: which registry entries I have to change to redirect com to my new com server "SecondServer"?
greets&thx
|
|
|
|
|
Hello this question was raised by Bilal and i am also interested in getting its answer but no answer was posted before so putting it again.
"I am new to COM,OLE,AUTOMATION,ActiveX in Vc
so please provide me the difference among each as well as their purpose
Thanks "
or you can also provide me a link or document where i can find the diference
regards
Muhammad Azam
|
|
|
|
|
hi!
I want to capture the right mouse button event on MS Word document.
is it possible? if so then please help me.
Thanks
Ahmad Jalil Qarshi
|
|
|
|
|
Hi,
Yes you can, there r numerious ways to do this -
1. Write a plgin for word - for more info. search how to write plugin for
word
2. OLE Automation - If you r doing OLE embedding then get IDispatch, and
utilize the methods exposed by word. For more info. abt methods
expose by word, take the help from "OLE Object Viewer" to peep inside word
object
Cheers,
Vishal
|
|
|
|
|
hi!
I have Added a new CommandBarControl of type msoControlButton in the Menu "Inline Picture" (which is displayed when you right click on some picture or some OleObject in MS Word Document). I have also run some VBA macros on click event at this new inserted menu Item by specifying them into PutOnAction function. But now i want to call some functions of my ActiveX control's class when the user right click on my control and then select the newly inserted menu item. Is it possible if so then please help me.
Thanks
Ahmad Jalil Qarshi
|
|
|
|
|
Hello.
I am doing a research on DCOM, COM+ and .Net Remoting.
We are about to develop a license server which should communicate with all of our products (written in various languages)
I'd like to know what would be the best way to do this.
Should I use .Net Remoting? But i dont want the user to install .Net Framework if the product is written in C++.
Or would DCOM be a better solution? I heard that DCOM is a good choice in a situaltion like that?
And whats about COM+?
Maybe someone can give me some pres and cons just to get the right direction.
Thanx in advance
|
|
|
|
|
hi!
i have made a control for MS Word. Now when i insert the Control into the Word. InitNew methods is called, and when i save the document Save method of IPersistXXX is called but when i open my document the Load method of IPersistXXX is not called.
Furthermore, on reopening the document when i double click my control it displays the following message.
"This object was created in Properties.
This application is not availabe to open this object.
Make sure the application is properly installed and that it has not been deleted, moved, or renamed."
Please help me.
Thanks in advance.
Ahamd Jalil qarshi
|
|
|
|
|