|
STDMETHODIMP CTeacher::get_OneStudent(IStudent* *pVal)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
*pVal = m_aStudent;<br />
if( m_aStudent != NULL )<br />
m_aStudent->AddRef();<br />
return S_OK;<br />
}<br />
<br />
STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
if( m_aStudent != NULL )<br />
m_aStudent->Release();<br />
m_aStudent = newVal ;<br />
if( m_aStudent != NULL )<br />
m_aStudent->AddRef();<br />
return S_OK;<br />
}<br />
In VB you should use the "Set" operator to assign one object to another.
Set s = t.OneStudent<br />
With best wishes,
Vita
|
|
|
|
|
I have a COM interface and would like the CLSID for the underlying implementing object. The interface I have decends from IDispatch, and I have played with ITypeInfo. I am able to get the IID of the interface, but not the CLSID of the object. Is there an easy way to do this?
Thanks,
cagey
|
|
|
|
|
In order to get CLSID of running COM instance that object must have at least IPersist to be implemented.
--or--
To read CLSID from TypeLib (If you TypeLib has more then one coclass and some of those coclasses have implemented the same interface you can not say which coclass is instantiated):
#include <stdio.h>
#include <windows.h>
#include "comdef.h"
#include "atlbase.h"
void main()
{
CoInitialize(0);
{
CComPtr<IDispatch> p;
HRESULT hr;
hr = p.CoCreateInstance(L"TestObj.Test");
if(S_OK == hr)
{
::ITypeInfo *pti;
::ITypeLib *ptl;
UINT ui;
hr = p->GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT,&pti);
if(S_OK == hr)
{
hr = pti->GetContainingTypeLib( &ptl, &ui);
pti->Release();
if(S_OK == hr)
{
ui = ptl->GetTypeInfoCount();
for(UINT i = 0; i < ui; ++i)
{
hr = ptl->GetTypeInfo(i, &pti);
if(S_OK == hr)
{
::TYPEATTR *patr = 0;
hr = pti->GetTypeAttr( &patr);
if(patr->typekind == TKIND_COCLASS)
{
printf("OK - TKIND_COCLASS\n");
OLECHAR *wsz;
hr = ::StringFromCLSID(patr->guid, &wsz);
if(S_OK == hr)
{
printf("CLSID = %s\n",(char*) _bstr_t(wsz));
::CoTaskMemFree(wsz);
}
}
pti->Release();
}
}
ptl->Release();
}
}
}
}
CoUninitialize();
}
soptest
|
|
|
|
|
soptest's code should be working in most cases, but first check if the object supports IPersist, IProvideClassInfo or IProvideClassInfo2. You can then obtain the class ID in a very simple way through:
IPersist::GetClassID()
IProvideClassInfo2::GetGUID()
gertjan
|
|
|
|
|
I have written a C++ application that uses the COM+ event system. It consists of a publisher that creates log strings and
a subscriber client that creates a transient event subscription to get notifications every time a log string is sent. Everything
works fine when I run the publisher and subscriber on the same host, but if I try to subscribe from another host it fails.
The setup code looks like this:
BOOL RegisterTransientSubscription(LPCOLESTR SubscriptionName,
LPCOLESTR pszEventID,
IUnknown *pUnknown,
LPOLESTR* ppszSubscriptionID)
{
ICOMAdminCatalog* pac;
HRESULT hr = E_FAIL;
// Get an ICOMAdminCatalog interface pointer.
hr = ::CoCreateInstance (CLSID_COMAdminCatalog, NULL,
CLSCTX_SERVER,
IID_ICOMAdminCatalog,
(void**) &pac);
if (SUCCEEDED (hr))
{
ICatalogCollection* pcc = NULL;
BSTR bstr = ::SysAllocString(OLESTR \
("TransientSubscriptions"));
// host name edit empty <=> local publisher,
// otherwise remote host...
if (m_sHostName.IsEmpty())
{
// Get an ICatalogCollection pointer for the
// TransientSubscriptions collection (local).
hr = pac->GetCollection(bstr, (IDispatch**)&pcc);
::SysFreeString (bstr);
} else {
ICatalogCollection* tmp;
hr = pac->Connect(m_sHostName.AllocSysString(),
(IDispatch**)&tmp);
if (SUCCEEDED(hr))
{
VARIANT v;
VariantInit(&v);
hr = tmp->get_Name(&v);
hr = tmp->GetCollection(bstr, v,
(IDispatch**)&pcc);
tmp->Release();
}
}
if (SUCCEEDED (hr))
{
// Add an item to the TransientSubscriptions
// collection.
ICatalogObject* pco;
hr = pcc->Add((IDispatch**) &pco);
if (SUCCEEDED (hr))
{
// Register a transient subscription.
hr = SetStringProperty(pco, OLESTR("Name"),
pszSubscriptionName);
hr = SetStringProperty(pco,
OLESTR("EventCLSID"),
pszEventID);
hr = SetBoolProperty(pco, OLESTR("Enabled"),
TRUE);
hr = SetIUnknownProperty(pco, OLESTR\
("SubscriberInterface"),
pUnknown);
// Copy the subscription ID to the address
// specified by the caller.
VARIANT var;
::VariantInit (&var);
bstr = ::SysAllocString (OLESTR ("ID"));
pco->get_Value (bstr, &var);
::SysFreeString (bstr);
int nSize = (::SysStringLen(var.bstrVal) + 1) *
sizeof (OLECHAR);
BYTE* pBuffer = new BYTE[nSize];
::CopyMemory (pBuffer, var.bstrVal, nSize);
*ppszSubscriptionID = (LPOLESTR) pBuffer;
::VariantClear (&var);
pco->Release();
}
// Write the changes to the catalog.
long lResult;
hr = pcc->SaveChanges(&lResult);
pcc->Release();
}
pac->Release();
}
return (SUCCEEDED(hr)) ? TRUE : FALSE;
}
Any help would be much appreciated (2 weeks of debugging/testing/experimenting and I still don´t know what's wrong).
Regards,
Stefan
|
|
|
|
|
Hi everybody,
I've implemented QueryStatus of the IOleCommandTarget interface. It looks like this:
interface IOleCommandTarget : IUnknown
{
[helpstring("method Exec")]
HRESULT Exec(
[in] const GUID *pguidCmdGroup,
[in] DWORD nCmdID, [in] DWORD nCmdExecOpt,
[in] VARIANTARG *pvaIn,
[in,out] VARIANTARG *pvaOut);
[helpstring("method QueryStatus")]
HRESULT QueryStatus(
[in] const GUID *pguidCmdGroup,
[in] ULONG cCmds,
[in,out] OLECMD *prgCmds,
[in,out] OLECMDTEXT *pCmdText);
};
But, when I try to compile the idl file I receive this error;
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
Processing E:\development\COM experiments\ProxyObj\ProxyObj.idl
ProxyObj.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oaidl.idl
oaidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\objidl.idl
objidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ocidl.idl
ocidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oleidl.idl
oleidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\servprov.idl
servprov.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\urlmon.idl
urlmon.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\msxml.idl
msxml.idl
E:\development\COM experiments\ProxyObj\ProxyObj.idl(59) : error MIDL2025 : syntax error : expecting a type specification near "OLECMD"
E:\development\COM experiments\ProxyObj\ProxyObj.idl(59) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation
Error executing midl.exe.
ProxyObj.tlb - 2 error(s), 0 warning(s)
Any idea why? Should I include something special?
Thx,
/Tommy
|
|
|
|
|
In IDL file:
import "oaidl.idl";
import "ocidl.idl";
import "docobj.idl";
With best wishes,
Vita
|
|
|
|
|
I have a C++ DLL that I created with a whole bunch of typedefs for structs and enums (as well as some exportable functions and classes). The DLL's work fine when being called by a C++ project. However, we would like to add support for Visual Basic so that it can use the user defined types and enums. I looked through MSDN and found an article that states if you want to pass UDT's from VB to a C++ DLL, you have to create a type library. Having never used COM before (let alone typelibs), how do I go about defining these items to export? I wold prefer to not have to rewrite the code to create a COM interface.
Any help would be greatly appreciated.
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
import "oaidl.idl";
import "ocidl.idl";
[
uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX), // GUID of your Type Library. Use GUIDGEN.EXE from MS Common\Tools
version(n.m), // Version of your Type Library, e.g. 1.0
helpstring("XXXXXXXX") // Description of your Type Library
]
library XXXXLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
typedef [
uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX),
version(n.m),
helpstring("XXXXXXXX")
]
enum tagXXXX
{
[helpstring("XXXXXXXX")]
XXXX = YYYY,
} XXXX;
typedef [
uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX),
version(n.m),
helpstring("XXXXXXXX")
]
struct tagXXXX
{
} XXXX;
};
It's a template. Rename the XXXX placeholder with your Names and Values.
You can include this IDL-file into your project and create the TLB file. This TLB file can included into DLL (or EXE) as the resource, named "TYPELIB".
This TLB file (both alone or included into other module) must be registered with REGTLIB.EXE or VB itself if you will add this TLB into project's References (Browse button).
With best wishes,
Vita
|
|
|
|
|
Getting value from stuff you don't own is a compelling
idea. Just think, someone else has created something
that has value, and has made it available to you. You
can now leverage its value in ways that makes all
parties richer. That's the promise of web services.
You need to know about web services. The advent of
standards-based web services marks a new era of
system development. First mainframe, then client-server,
the Web, now web services makes it possible to leverage
every legacy system of the past and do so much more
with your information assets.
Architag Press, a division of Architag International
Corporation, announces the publication of Web Services
Implementation Guide, Volume 1: Getting Started, by
Brian E. Travis and Mae Ozkan.
Sample chapters of the book is available at
http://www.architag.com/press/wsig.
This book will show you what a web service is, and
how you can align your internal systems and external
trading partner interactions to take advantage of this
new concept in system integration.
You will learn about the "Three Steps to Web Services":
* Automate internal systems
* Determine integration points
* Expose integration points as web services
This book is for systems architects, developers,
and I.T. decision makers.
Highlights in this book:
* Written in a light, entertaining style.
* Emphasis on architectural design for web services.
* A tutorial on the state of web services standards.
* Plenty of real-life examples of web service use.
* Tutorials on the key technologies: XML, SOAP,
WSDL and UDDI.
* Code samples of key XML-based web services
technologies and extensions.
* Companion Web site with all code samples and
late-breaking information.
----
Download sample chapters of Web Services Implementation
Guide at http://www.architag.com/press/wsig/.
Stanford Powers, Publisher Architag International Corp
Phone: 866-898-0001 Outside US: +1-303-426-3126
Email: spowers@architag.com Fax: 720-294-1396
|
|
|
|
|
|
Hi,
I've been staring at this problem for hours and hours... what is wrong?!
This is what I do:
...snip...
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Lex, CLex)
END_OBJECT_MAP()
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID )
{
if (dwReason == DLL_PROCESS_ATTACH)
{
TCHAR pszLoader[MAX_PATH];
GetModuleFileName(NULL, pszLoader, MAX_PATH);
_tcslwr(pszLoader);
if (_tcsstr(pszLoader, _T("explorer.exe")))
return FALSE;
_Module.Init(ObjectMap, hInstance, &LIBID_LEXBHOLib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE;
}
...snap...
I get this error:
---Configuration: LexBHO - Win32 Unicode Release MinDependency--------
Linking...
Creating library ReleaseUMinDependency/LexBHO.lib and object ReleaseUMinDependency/LexBHO.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseUMinDependency/LexBHO.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
LexBHO.dll - 2 error(s), 0 warning(s)
But when I comment these lines out...
...things are working just fine. What is wrong with _tcslwr? Because that's where the problems start...
Help is much appreciated,
/Tommy
|
|
|
|
|
go ot project setting and remove _ATL_MIN_CRT macro
soptest
|
|
|
|
|
Hello everyone...
I'm very much new to the COM world and I was wondering if some guru here could lead me to websites/ articles that can get me really started in COM and ATL.. I have been working with MFC for the last one year and I am already pretty realise the need for ATL and more robust prog tech..
anyway, that apart I'm also looking for a few project ideas in ATL.. this is ofcourse to add to my personal project list..
thks
yeeeeeeeeeeoooooooooooooowwwwwwwwwwwwwww
One more addition to the addiction of coding!
If you want a helping hand, you'll find one at the end of your arm.
|
|
|
|
|
before invoking the IDispacth::invoke I do the following:
BOOL CLASSNAME ::InvokeGetValue(
IDispatch *InDispatch,
DISPID& InDispId,
LCID& InLcid,
long InUserComId,
CString& OutValue, BOOL bAdhocCom, int NumToReserve, CString& Name1, CString& Name2)
{
CString strReturn;
VARIANTARG va;
EXCEPINFO exInfo;
UINT uErr;
DISPPARAMS dp;
HRESULT hr;
BSTR argConversion;
BSTR sName1= Name1.AllocSysString();
BSTR sName2= Name2.AllocSysString();
Num=32;
int nArgs = 3;
dp.cArgs = nArgs;
dp.cNamedArgs = 0;
//////???AT RUN TIME IT CRASHES ON THE NEXT INSTRUCTION
///// COMPLAINIG ABOUT UNHANDLED EXCEPTION- ACCESS VIOLATION
dp.rgvarg[0].vt = VT_I2;
dp.rgvarg[0].iVal = NumToReserve;
ANY HELP IS HIGHLY APPRECIATED.
Paradise is where I am.
Voltaire
|
|
|
|
|
did you initialize :
VariantInit(va);//your variant and
dp.rgvarg = va;//your dispparam with you variant?
access violation is often null pointer...!
|
|
|
|
|
The problem was solved by a codeguru member:
CComVariant dpv[3];
dp.rgvarg = dpv;
I was not allocating space for the dp array structure.
Thank you very much for you reply. I believe your
dp.rgvarg = va;//your dispparam with you variant?
statement was in the same general direction too.
Thanks again.
Paradise is where I am.
Voltaire
|
|
|
|
|
I'm working on a c# application and i'd like to get it launchable from Microsoft Word using a new icon. The problem is I don't know how to do, I've been searching throw articles but they often explain how to launch and control Word from an application and not the contrary.
Could someone explain me how to do such a thing, or at least give me a few steps ?
Thank you.
---------
Or not ?
|
|
|
|
|
try http://www.codeproject.com/com/outlookaddin.asp for a C++/COM article on how to write a plugin for any office application. For sample C# project, checkout MSDN for an article that got published a couple of months back.To launch your own application, you can use ShellExec in OnClick of a toolbar button in your plugin.
|
|
|
|
|
Hi everybody,
I have added a toolbar button in Internet Explorer. This button should toggle the checkbox (and write/load some values from reg) in IE->Tools->Internet Options->Connections->LAN Settings called 'Use a proxy server'.
Q1: How can I design a COM object to receive the clicks of this button and keep track of the toggle state (button pushed/not pushed) and make the button look like a toggle button?
Q2: How can design my COM object to talk with the settings mentioned above? Is it possible?
Q3: I know how to change the reg settings that IE uses each time it starts. But I need to reflect this reg settings to IE at runtime. Does any one know how to do this if Q2 can't be achieved?
Thx a lot! I have a deadline in two days and I really need to get this working by then! So please all you COM pros out there, help me if you can!
I've just started out with COM...
Thx!!!
/Tommy
|
|
|
|
|
How can I define packed structure in IDL?
Most of compilers align structure in 4/8 bytes.
IN VC++ 6.0, we can control this by using '#pragma pack' directive.
But, how can we do the same thing in IDL?
I tried to using '#pragma pack' directive in IDL like we do in c++.
It looks successful only in COM-Server Project.
Compiler-made Header file in server project has '#pragma pack' directives enclosing structure-definition.
But, client project using '#import My.tlb' has failed.
My.tlh file defines this (I expect to be packed) as unpacked structure(maybe 8byte-align).
How can I define structure as packed?
I want structure to be packed in Header files made by MIDL(includes tlh).
And, Proxy/Stub code made automatically refelcts this.
How can I solve it?
thanks~
|
|
|
|
|
Hi, I'm not completely positive as I haven't tried this, but try using the #pragma pack directive like:
#pragma pack(push, 1)
#import ...
#pragma pack(pop)
Let me know if this works for you.
Mark
|
|
|
|
|
what is the value of this and why isn't it defined anywhere?? i have the latest platform SDK...
it is referenced in the Platform SDK file: "IActiveScriptParse::ParseScriptText"
- Roman -
|
|
|
|
|
Hi, all
In Atl project ,how can I return the user define type?
For example , I have define a Struct ,and I want to return the Struct type in a function, and I plan to utilize the return Struct type in VB through the com. What should I do ? I have try some ways ,but failed.
Another similar problem. I have two ATL Object in my Atl
project , Teacher and Student . And student is a private property of Teacher ,now I want to construct a function in Teacher to return the Student property .How should I do ?
Sincerely ask for help. Who can tell me how to do , or give me some similar source code which resovle the above problems .
I'll appreciate it .
Regards.
|
|
|
|
|
Q2. You can pass the IStudent interface as well as any other data from ITeacher interface.
Q1.
In IDL-file
typedef [uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX), helpstring("Help")]
struct _SomeStruct
{
int i;
BSTR str;
...
} SomeStruct;
[...,dual,...]
interface IO : IDispatch
{
[id(1)] HRESULT M1([in] SomeStruct ss);
[id(2)] HRESULT M2([in,out] SomeStruct *ss);
[id(3)] HRESULT M3([out,retval] SomeStruct* *ss);
[id(4)] HRESULT M4([in,out] SAFEARRAY(SomeStruct) * ssbs);
};
With best wishes,
Vita
|
|
|
|
|