|
Can a object set to call a function from within a Win32 .dll be considered a COM object? What exactly are the requirements for something being termed a COM object, is it only language independence? Thanks.
Nick Parker
|
|
|
|
|
Properly supporting the IUnknown interface is basically the only requirement.
There are other requirements that make it compatible with languages like VB and VBScript, but they are not necessary in order to call your object a COM object.
If there are any other questions, or you want more detail feel free to ask.
|
|
|
|
|
A COM object implements at minimum the IUnknown interface and has the proper vtable layout in memory (as defined in the COM spec). There are also rules regarding querying interfaces, for example a QI for IUnknown must always return the same value.
--Mike--
It's hammer time!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
The program, in C++, is sending a call to a DCOM object installed on a remote NT machine, and am trying to return a Safearray of float (as SAFEARRAY **ppfloatarray), have set that parameter as [in,out], (plus other parameters before this as [in]). Client is running Windows 98. On the client end, the data is not being written back to the passed-in safearray, and HRESULT returned is 8002000D, array is locked.
How is the client and server to be set up to do this? My solution was to try various combinations for the flags in the fFeatures member of the safearray, also to try setting the array to locked or unlocked before it was sent and before it was returned from server. I have a debug text file written, so I know that the DCOM object is executing, and the correct values are written to the safearray and are there just before it returns.
David Spain, C++ Applications Programmer
|
|
|
|
|
Hi David,
Can you put parts of your code in this forum? Specially those parts where
you are accessing and unaccessing the SAFEARRAY. It will be better if you
can also give us the portion of the IDL that describes the prototype of the
interface method where you are having the problem.
With best regards,
Sayan
(sayanmukherjee@indiatimes.com)
|
|
|
|
|
Ok, here is the code in question:
I was wanting to return a safearray of BSTR, but was having trouble with that, so thought maybe it had to do with the pointers, so tried float safearray, but is having same problem. This is the code with float safearray: >>> psaFloatReturn is the safearray in question <<<
IDL code:
[
object,
uuid(13AE8E35-3726-11D6-9913-000102476F95),
dual,
helpstring("IRemoteServerDisp Interface"),
pointer_default(unique)
]
interface IRemoteServerDisp : IDispatch
{
[id(2), helpstring("method Method2")] HRESULT Method2([in] BSTR sName, [in] SAFEARRAY(float) *psafloatAr1, [in] SAFEARRAY(VARIANT_BOOL) *psaBoolAr, [in] SAFEARRAY(float) *psafloatAr2, [in] long cnt, [in] float singlefloat1, [in] float singlefloat2, [in,out] SAFEARRAY(float) *psaFloatReturn, [out,retval] long* errcode);
};
--------------------
CoClass method:
STDMETHODIMP CCoRemoteServer::Method2(BSTR sName, SAFEARRAY **psafloatAr1, SAFEARRAY **psaBoolAr, SAFEARRAY **psafloatAr2, long cnt, float float1, float float2, SAFEARRAY **psaFloatReturn, long* errcode)
{
.
.
.
float HUGEP *pfloatTemp;
long val = SafeArrayAccessData(*psaFloatReturn, (void HUGEP**)&pfloatTemp);
float sldk = 3.0f;
for(int q=0; q<count; q++)
="" {
="" sldk="" +="1.0f;" test="" values
="" pfloattemp[q]="sldk;
" }
="" safearrayunaccessdata(*psafloatreturn);
="" safearraylock(*psafloatreturn);="" ???
="" *errcode="S_OK;
" return="" s_ok;
}
---------------
client="" code:
passed="" in:="" cstring="" sname,="" int="" cnt,="" float*="" pfloatarray1,="" bool*="" pboolarray,="" pfloatarray2,="" float="" float1,="" float2,="" long*="" errcode
{
="" safearraybound="" sab;
="" sab.llbound="0;
" sab.celements="cnt;
" safearray*="" psafloatreturn="SafeArrayCreateVector(VT_R4," 0,="" cnt);
="" initialize="" other="" parameters="" here
="" **="" safearray="" **
="" safearraylock(psafloatreturn);
="" tempfloat="new" float[cnt];
="" psafloatreturn-="">pvData = tempfloat;
SafeArrayLock(psaFloatReturn);
// call to DCOM object
BSTR bstrName = sName.AllocSysString();
HRESULT hResult =
m_pRemoteServer->Method2(bstrName, &psafloatar1, &psaBoolAr, &psafloatar2, cnt, float1, float2, &psaFloatReturn, errcode);
SysFreeString(bstrName);
SafeArrayDestroy(psafloatar1);
SafeArrayDestroy(psafloatar2);
SafeArrayDestroy(psaBoolAr);
bool ret = false;
if(SUCCEEDED(hResult))
ret = true;
if(psaFloatReturn!=NULL)
SafeArrayDestroy(psaFloatReturn);
delete []tempfloat;
}
About the count in initializing and returning, I know that the count on both ends is the same and matches the cnt variable given here, so is not an issue of writing past array boundaries.
Thanks in advance for any help.
David Spain, C++ Applications Programmer
|
|
|
|
|
No need for anyone to spend any more time on this --
Sorry if anyone spent time on this, I think there is code on this website in the articles that would help me. In the COM section, "STL Compliant Class for SafeArrays", the code returns safearrays from a COM object, which was my problem. There may be other articles as well. I will look at that to find out what I am doing wrong, so no need for anyone to look at this any further, thanks for the effort.
David Spain, C++ Applications Programmer
|
|
|
|
|
I want to incoporate vbscript and jscript in my MFC application. What is the correct method of implementing IAcitveScriptSite and IActiveScriptSiteWindow with ATL form VS.NET ??
Thanks
Michael
|
|
|
|
|
I have a UART driver (Remon Spekreijse made 97(!)) and when i toggle with suspend/resume a thread created in the UART driver I get unhandled exception messages when in release mode. It works if I just toggle once (I create the thread and then suspend it) but if I suspend it again I get the "unhandled exception". Maybe the driver is missing some code...I'm not an expert on the threading part, what should I look for in my code??
And also, does someone know were to find a good working UART driver that is newer that the one I have that is from 97 heh...
Dejan.
|
|
|
|
|
Using ATL/Windows 2000 I have created an .EXE ATL (simple object) COM object named EXEServer, I then created a (client) MFC .exe to try and create the .EXE ATL COM server object on the same machine using CoCreateInstance(....,CLSCTX_LOCAL_SERVER....), shown below - no luck !!!!
I get the HRESULT return error E_NOINTERFACE when I do a simple CoCreateInstance on the ATL .EXE COM object via the client. What is going wrong ? How can I fix this...?
I've checked both the registry AND OleViewer and the ATL COM ServerEXE IS there and seems to be active....what am I missing.....? please help me I am going crazy...
// The client MFC code...
BOOL CClientEXEDlg::OnInitDialog()
{
....
CoInitialize(NULL);
IExeServer* pIHelloWorld = NULL;
HRESULT hr = CoCreateInstance (CLSID_ExeServer,
NULL, CLSCTX_LOCAL_SERVER,
CLSCTX_,
IID_IExeServer,
reinterpret_cast<void**>(&pIHelloWorld));
BSTR bstrMsg = NULL;
void *pMsgBuf;
::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT ),
(LPSTR)&pMsgBuf,
0,
NULL );
AfxMessageBox((LPSTR)pMsgBuf);
if (hr == E_NOINTERFACE)
{
AfxMessageBox("CLASS_E_NOINTERFACE"); // this error is always
// there
}
if (FAILED(hr))
{
AfxMessageBox("FAILED");
CoUninitialize();
EndDialog(TRUE);
return TRUE;
}
else
{
m_edit = bstrMsg;
::SysAllocString(bstrMsg);
}
hr = pIHelloWorld->SayHello(&bstrMsg);
pIHelloWorld->Release();
UpdateData(FALSE);
// TODO: Add extra initialization here
CoUninitialize();
return TRUE;
}
john s.
|
|
|
|
|
I just started messing around with COM and am having this same exact problem. Are there extra settings for an out-of-process .exe server that I don't know about? Anyone?
|
|
|
|
|
Thank you!
I hope you could help me.
-----Method != Objective,COM != Panda-----
|
|
|
|
|
.....SetSite(IUnknown *pUnkSite)
{
IOleWindow *pOleWindow = NULL;
m_hWndParent = NULL;
if (SUCCEEDED(pUnkSite->QueryInterface(IID_IOleWindow, (LPVOID*)&pOleWindow)))
{
pOleWindow->GetWindow(&m_hWndParent);
pOleWindow->Release();
}
}
#define MOSTLY_LEAN_AND_MEAN
|
|
|
|
|
Thank you!
|
|
|
|
|
I am developing an ATL server that will run on several remote systems. How can I pick a server to connect to at run time? I know that I can use DCOM configuration to specify the implementation location before running my application but I want to allow a user to select from a list of computers or IP address that house the server while the client is running. How do I tell ATL where the server is located at run time?
Thanks.
|
|
|
|
|
Use CoCreateInstanceEx and pass it the machine name selected.
|
|
|
|
|
Thats great!
Thanks Mark.
|
|
|
|
|
Hi all,
I have a few (possibly nieve) questions regarding the efficiency of calls to in proc COM methods vs. standard C++ function calls.
I've inherited a project which had a master computer delegating some functionality to a few clients, using DCOM. We are now implementing all functionality in one monolithic app. The way I see it I have two options; either use the original COM dll's and invoke them as INPROC_SERVERs, or rip out the non-COM parts of the dll code and put it into C++ classes in my main app.
It would be easier to just use the dll's as they are - they work just fine, but I'm concerned about the efficency aspect. My app will be invoking methods in the order of 100 calls per second.
I would like to know some opinions as to what kind of performance hit I can expect in using COM vs. standard C++ function calls.
As I said, I have very little knowledge of COM, so this could be a rather dumb question
Any advice would be really appreciated.
TIA,
Pete
|
|
|
|
|
If you already have the interface in question, then COM is just like calling any virtual function.
Well, that is unless you are talking about invoking methods via IDispatch.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
>If you already have the interface in question, then COM is just like calling any virtual function
True only if calls are made within the same com apartment, otherwise they will be marshalled
|
|
|
|
|
i am doing a visual c++ poject.the project involves 3 menus.i have the main dialog box with 2 buttons which represent selections one can make by clicking.if one option is clicked i want to know how to call another dialog box which has the operations i want to carry out.please help me i am in need of it.or you can tell me the website to go to which has the information
jinguri
|
|
|
|
|
Your question is in your COM forum,Do you use MFC or ATL?
shingai wrote:
if one option is clicked i want to know how to call another dialog box which has the operations i want to carry out
You can create two different dialog box,and in each event handler of buttons create on of them.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
So if you use MFC,with dialog editor create two different dialog and in each button handler create one like this:
CYourDialg1 adlg;
adlg.DoModal();
IN another one:
CYourDialog2 adlg;
adlg.DoModal();
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
My equipment:
Workstation:
Win2k Prof. OS
Visual C++ 6.0
Platform SDK November 2001
Server:
Win2k Server OS
Name: iras
Domain: htlpinkafeld.at
TestUser: testuser@htlpinkafeld.at
Password: none
My Problem:
Let's imagine a user at the workstation wants to set up a connection with the server. The user double clicks the server icon and he will be asked for an username and password. He enters testuser@htlpinkafeld.at and no password. He will get connected and everything is fine. Ok.
I do this whole stuff in my program with the following function:
WNetAddConnection2(...); Well it works!
The disadvantage is that only one user can be connected to the server at the
same time. I found out that every process which trys to work with the server after the connection is established has to use this connection and not a other connection else because there can only one connection at a time. But i have heard that this could be handled with COM Interfaces. I am not a beginner with programming COM Interfaces but i can't find out how this can be done!!
What i want is to get access to the server with more than user at the same time!!!! It is possible but how ?????
Please help me!
|
|
|
|
|
Can I use the OLECMDID_SAVEAS without prompting the user?
How can i submit the path to store the webpage on the disk to this function?
|
|
|
|
|