|
I have created Arthematic simple object.
in Client program i write like this.
CoInitialize(NULL);
IArthematic *art;
CoCreateInstance(CLSID_Arthematic,NULL,CLSCTX_INPROC_SERVER,IID_Arthematic,reinterpret_cast<void**>&iu);
And when compiling, compiler shows atlwin.h require atlbase to be included first.
I have included Arthematic.h and MyCom_i.c files in my client program.
how can I get out of this and plz tell me how to write client program for a simple object.
|
|
|
|
|
Include the .h file that ATL's MIDL generated and the .h file from of the coclass.
Kuphryn
|
|
|
|
|
Here I have given a sample working code for a COM client
// COMClientDlg.cpp : implementation file
#include "stdafx.h"
#include "COMClient.h"
#include "COMClientDlg.h"
#include "COMServer.h"
#include "COMServer_i.c"
............................
............................
............................
HRESULT hr;
IMessage *msg;
hr = CoInitialize(0);
//initialize COM
if( SUCCEEDED(hr) )
{
hr = CoCreateInstance(
CLSID_Message,
NULL,
CLSCTX_INPROC_SERVER,
IID_IMessage,
(void **)&msg
);
if( SUCCEEDED(hr) )
{
msg->Show();
msg->Release();
}
else
{
AfxMessageBox("Cannot create COM object");
}
CoUninitialize();
//uninitialize COM
}
else
{
AfxMessageBox("Cannot initialize COM");
}
This code worked fine when I tested under an MFC dialog project.
The server was created as a DLL by the ATL wizard. While creating a simple object
the following options were selected.
Threading Model - apartment
Interface - dual
Aggregation - yes
If you still have trouble you can mail your code to me
R.BALACHANDRAN
|
|
|
|
|
You should use #import directive and smart pointers.
It makes everything simple for developing COM client.
For example, if you have COM object named Message then do the following:
#import "Message.tlb" no_namespace
void main()
{
CoInitialize(NULL);
try
{
IMessagePtr pMessage = IMessagePtr(__uuidof(Message));
pMessage->Method();
}
catch(_com_error &e)
{
HRESULT hr = e.Error();
}
CoUninitialize();
}
|
|
|
|
|
the MainFrame Menus of Active Document Server Application is dynamic created ;
so how can i make the container' embed Menu as same as the menu of active document server application ? What can i do it?
please help me ,thanks
|
|
|
|
|
Hello,
Can somebody point me out the differences between the webbrowser control and the internetexplorer object ?
What are the purpose of each one ?
Can you build the same applications with both ? Can they be embedded the same way ?
Is one control offering more features than the other, including non-visual features (like more cookies stuff...) ?
Thanks,
R. LOPES
Just programmer.
|
|
|
|
|
Hi,
I'm a novice in COM so my question is very easy.
I want to crete the COM server (INPROC_SERVER) with method like:
virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE GetStr(
/* [out][in] */ LPSTR lpcszStr) = 0;
STDMETHODIMP CAbc::GetStr(LPSTR lpcszStr)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
char *mystr="string from COM";
lpcszStr=mystr;
return S_OK;
}
So, is it possible to return the string pointer from COM server?
Yours sincerely,
Alex Bash
|
|
|
|
|
Hi,
I'm a novice too. But I have had the same problem. So maybe I can give you a hint.
As far as I know the best solution is to use the BSTR data type. This is not very complicated. There are only some special functions that you have to use: SysAllocString, SysFreeString, SysStringLen and some other ones. You could do it like this:
IDL:
GetStr([out] BSTR* str)
Method implementation:
STDMETHODIMP CAbc::GetStr(BSTR* str)
{
//Allocate memory for the BSTR
str = SysAllocString("string for COM");
//Check wether allocation was successful
if(str) return S_OK;
else return E_FAIL;
}
And the caller:
...
BSTR myBStr;
HRESULT hr = Abc->GetStr(myBStr);
if(FAILED(hr)) damned();
else
{
//Now you've got the string
//Do with it what ever you want (but don't get rude...)
//You can use it like a LPSTR as far as I know
printf("My String: %s", myBStr); //example
SetDlgItemText(IDC_EDIT, myBStr); //example
//But now it is your responsability to free the memory!
SysFreeString(myBStr);
//That's it
}
...
I hope this was all correct. Try it. It should work.
But maybe someone else can tell you more or correct my posting.
|
|
|
|
|
Remember to pass in the COM interface function an address of BSTR and to dereference the pointer to a BSTR before assignment.
*str = SysAllocString("string for COM");
HRESULT hr = Abc->GetStr(&myBStr);
Kuphryn
|
|
|
|
|
what he says and what u answer..?? oooooooops..
[ It is possible to represent everything in this universe by using 0 and 1 ]
|
|
|
|
|
in an ocx how do i get the hinstance of the container? specifically, if a vb project is using the ocx, how would i get the parent (vb project) hinstance so i may access the resource file in th vb project?
shotgun
|
|
|
|
|
Hi,
I have a sample code in VB that I need to "translate" to VC++.
But I don't know how tu use safearrays.
Here is the VB code :
<br />
Dim pSafeArray As Variant<br />
pSafeArray = pBlock.SafeArray(0)<br />
' Loop through the SafeArray and set value to each pixel<br />
Dim I, J As Integer<br />
For I = 0 To pSize.X - 1<br />
For J = 0 To pSize.Y - 1<br />
pSafeArray(I, J) = I + J<br />
Next J<br />
Next I
pBlock is an object provided by the API I'm using
Could you help me ?
Thx,
Stephane
www.exotk.org
|
|
|
|
|
I'm trying to enumerate OLE and VB Controls of a other process. I've already found the Microsoft article (Q141414) about how to do this by using the IOLEClientSite Interface.
I've already sucessfully "entered" the process using dll injection methods, now I face the problem how to get a pointer to IOLeClientSite without using COleControl::GetClientSite() as described in the mentioned article.
Perhaps there is another method to enumerate controls I'm not aware of?
Thanks
Georg
|
|
|
|
|
The interface IShellDispatch,has an updated interface named IShellDispatch2.
How to invoke IShellDispatch2 and all the members method.
Swarup
|
|
|
|
|
hello,
i have a problem passing objects in a event function.
i created a com object which listens for incoming tcp/ip connections in the background. the listening can be started by an method which returns immediatly. then a thread is created by the com object, waiting for incoming connections, and executing an event, to inform the client.
because the event is fired from a different thread, i marshalled the event source objects in the advise function and unmarshal when firing the event. this works fine as long as i pass only simple parameters like a long.
but i want to pass an com object which i created in the receiving thread to the client. for example an object which holds information about the established connection.
but when i fire the event, the object pointer is passed to the event function. if i call methods on this event in the client, i get an error, that the esp was not saved properly across a function call. why is that? and what can i do about this? maybe i have to marshal the transmitted objects pointer in some way, but i do not know how. do i have to marshal the object in a stream, transmit the stream, and unmarshal on the other side? but would make no difference, i think, because then i have to transmit the stream object, should cause the same error.
all is running inproc and the event source interface has the oleautomation attribute for standard marshalling.
then i changed the event to a dispinterface. fired the event by the invoke method passing the object as an variant parameter. the test with vbscript host was successful. there i can access the transmitted object. i think the invoke method does something with the object.
how can i get this working with an IUnknown derieved event source interface?
many thanks for help
enrico
|
|
|
|
|
The usual mistake is a declaration of _cdecl-eventfunction instead of the _stdcall one.
SINK_ENTRY_EX(1, IID__IXXXXEvents, 1, voidGotEvent)<br />
...<br />
END_SINK_MAP()<br />
...<br />
HRESULT voidGotEvent(long Message)<br />
{<br />
...<br />
}
With best wishes,
Vita
|
|
|
|
|
I am designing OPC Server(ole for process control) custom interface using VC++6.0
com/dcom.i have to design a EXE server component.
My requirement is to implement as many as 8 interfaces in a single class.i am
using ATL COM APPwizard-exe server.in it when i am trying to implement interfaces
through insertmenu->NEW ATLobject it is allowing only one interface at a timeto a
class, but when i am repeating the same process again it is creating separate class &
not allowing to give the same class name.
Here my doubt is can i give more than one interface to a class going through ATL
COM APPwizard,if possible HOW ?
I too tried through Insert->New Class &inserted a new Atlclass,there i was able to
give at best 3 interfaces but it won't satisfied my requirement.
satish kumar silla
Larsen& Tubro Ltd
mumbai
|
|
|
|
|
Add new interfaces to the coclass via IDL. Compile the IDL file.
Kuphryn
|
|
|
|
|
I am designing OPC Server(ole for process control) custom interface using VC++6.0
com/dcom.i have to design a EXE server component.
My requirement is to implement as many as 8 interfaces in a single class.i am
using ATL COM APPwizard-exe server.in it when i am trying to implement interfaces
through insertmenu->NEW ATLobject it is allowing only one interface at a timeto a
class, but when i am repeating the same process again it is creating separate class &
not allowing to give the same class name.
Here my doubt is can i give more than one interface to a class going through ATL
COM APPwizard,if possible HOW ?
I too tried through Insert->New Class &inserted a new Atlclass,there i was able to
give at best 3 interfaces but it won't satisfied my requirement.
satish kumar silla
Larsen& Tubro
mumbai
|
|
|
|
|
Hi,
I want to load HTML code from file to MSHTML :
<br />
HGLOBAL hMemLoad = GlobalAlloc(GPTR,(strlen(pBuffer)+1)*2);<br />
WCHAR* pwBuff = (WCHAR*) GlobalLock(hMemLoad);<br />
MultiByteToWideChar(CP_ACP,MB_COMPOSITE,pBuffer,-1,pwBuff,strlen(pBuffer));<br />
GlobalUnlock(hMemLoad);<br />
<br />
HRESULT hRes = 0;<br />
IStream *pStreamLoad; <br />
CreateStreamOnHGlobal(hMemLoad,FALSE,&pStreamLoad);<br />
<br />
IPersistStreamInit *pStreamInitLoad;<br />
hRes = pHtmlDoc2->QueryInterface(IID_IPersistStreamInit,(LPVOID*) &pStreamInitLoad);<br />
<br />
pStreamInitLoad->InitNew(); <br />
pStreamInitLoad->Load(pStreamLoad);<br />
pStreamInitLoad->Release();<br />
<br />
pStreamLoad->Release();<br />
<br />
GlobalFree(hMemLoad);<br />
But, when I try :
<br />
IHTMLDocument3 *pIHD3;<br />
hRes = pHtmlDoc2->QueryInterface(IID_IHTMLDocument3,(LPVOID*) &pIHD3);<br />
IHTMLElementCollection *pColl;<br />
pIHD3->getElementsByTagName(L"a",&pColl);<br />
long l;<br />
pColl->get_length(&l);<br />
<code><br />
<br />
to get number of items, I getting 0. ;-(.<br />
<br />
Can somebody tell me what I do wrong ?<br />
Thanks, <br />
Luda
|
|
|
|
|
If you replace L"a" with L"*", does it still return an empty collection ?
|
|
|
|
|
I have a component written with VC++ 6.0. Works perfectly with VB 6.0 by just adding the ATL component to the project and slapping it onto a form. Very easy.
However, How do I do the same think in VC++ 6.0 MFC CDialog-based form? I know I have to add the component's *.h file and *_i.c to the dialog's *.cpp file, then call CoCreateInstance(), but how do I add this visual component to the dialog?
|
|
|
|
|
What "visual component" are you referring to? Is the COM object an ActiveX?
Kuphryn
|
|
|
|
|
I created a custom C# property page for Outlook XP, and add it to the Tools | Options.. dialog using the following code in my OnStartupComplete() handler:
m_outlookApp.OptionsPagesAdd +=<br />
new ApplicationEvents_10_OptionsPagesAddEventHandler(<br />
this.OnOptionsPagesAdd );
public void OnOptionsPagesAdd( PropertyPages pages )<br />
{<br />
if ( m_rxPropPage == null )<br />
m_rxPropPage = new Rx5UI.RxPropPage( this.m_nameSpace );<br />
<br />
pages.Add( m_rxPropPage, "Rhythmyx" );<br />
}
The problem is that the property page tab text is set to "Untitled" instead of the expected string ("Rhythmyx") passed to the Add() method (see attached illustration) -- why is that?
Another issue I'm struggling with is how to get a reference for the PropertyPageSite interface -- in VB6 (based on http://www.cdolive.com/prool2k.htm), the code looks like:
Private Sub UserControl_InitProperties()<br />
'Init the PropertyPageSite variable<br />
Set oSite = Parent<br />
...<br />
End Sub
However, unlike ActiveX controls, neither System.Windows.Forms.UserControl or its parent implement the PropertyPageSite interface. Does anyone know what the C# equivalent to this code is?
Thanks,
--
Roy
|
|
|
|
|
Hi!
I need to serialize some GDI+ stuff and for that it seems I need to use the
IStream COM interface.
For the rest of the serialization I use CFile. I tried this but it throws a
memory exception:
<br />
void CViewCoverPage::Serialize(CArchive& ar)<br />
{<br />
...<br />
<br />
COleStreamFile* pOleStream = (COleStreamFile*)ar.GetFile();<br />
IStream* pIStream = pOleStream->GetStream();<br />
m_pLogo->Save(pIStream,...);
...<br />
}<br />
It seems any operation I try with the IStream object results in an access
violation.
Do I need to initialize it in some way??
What am I missing here??
Thanks
/Anders
|
|
|
|