|
Hi,
I Have a custom com object which I want to use as a class member for an implemantation of another COM interface.
This is what I have done and the trouble I am having:
I place the COM object (my own one) as a class member in my class that Implements IExtension. (since all my other objects get a reference to the IExtension to see if it is active or not). I have created two functions which preform operations on the Custom COM object.
This is where I come unstuck. I figured I had to QueryInterface to my own implementation of IExtension which has the methods defined. I don't know how to call my custom functions as I get compilation errors saying:
error C2039: 'GetTargetName' : is not a member of '_NoAddRefReleaseOnCComPtr<struct IMyExtension>'
Error executing cl.exe.
I have no idea why this is happening and cannot work out why. If I have defined my extensions and objects as follows....
The only thing I can think of is that I am breaking one of the RULES of COM. I cannot see which one.
Do I have to explicitly define the QI, AddRef, Release methods in my class? From all the example on here... I didn't think I did... here is a reference to an example: http://www.codeproject.com/com/hellocom.asp[^]
your help would be greatly appreciated.
cheers
Bryce
<br />
class ATL_NO_VTABLE CMyExtension : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CMyExtension, &CLSID_MyExtension>,<br />
public ISupportErrorInfo,<br />
public IMyExtension,<br />
public IExtension,<br />
public IExtensionConfig<br />
{<br />
public:<br />
CMyExtension()<br />
{<br />
const CLSID CLSID_TargetLayer = {0x2CEBA738,0x0533,0x4F68,{0xB1,0xC5,0x88,0xB3,0xD9,0x5B,0xA3,0xE3}};<br />
const IID IID_ITargetLayer = {0xD149DEA4,0xBB32,0x4D9A,{0x88,0xC7,0xA2,0x61,0x43,0x7D,0xC8,0xBA}};<br />
<br />
HRESULT hr = CoCreateInstance(CLSID_TargetLayer, NULL, <br />
CLSCTX_INPROC_SERVER,IID_ITargetLayer,<br />
(LPVOID*) &m_ipTargetLayer);<br />
if (SUCCEEDED(hr))<br />
{<br />
}<br />
}<br />
<br />
DECLARE_REGISTRY_RESOURCEID(IDR_MYEXTENSION)<br />
<br />
DECLARE_PROTECT_FINAL_CONSTRUCT()<br />
<br />
BEGIN_COM_MAP(CMyExtension)<br />
COM_INTERFACE_ENTRY(IHistoryExtension)<br />
COM_INTERFACE_ENTRY(ISupportErrorInfo)<br />
COM_INTERFACE_ENTRY(IExtension)<br />
COM_INTERFACE_ENTRY(IExtensionConfig)<br />
END_COM_MAP()<br />
<br />
BEGIN_CATEGORY_MAP(CMyExtension)<br />
IMPLEMENTED_CATEGORY( __uuidof(CATID_MxExtension))<br />
END_CATEGORY_MAP()<br />
<br />
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);<br />
<br />
public:<br />
STDMETHOD(get_Name)(BSTR * extensionName);<br />
<br />
STDMETHOD(Startup)(VARIANT * initializationData);<br />
<br />
STDMETHOD(Shutdown)();<br />
<br />
STDMETHOD(get_ProductName)(BSTR * Name);<br />
STDMETHOD(get_Description)(BSTR * Description);<br />
STDMETHOD(get_State)(esriExtensionState * State);<br />
STDMETHOD(put_State)(esriExtensionState State);<br />
<br />
<br />
HRESULT SetTargetName(BSTR Name);<br />
HRESULT GetTargetName(BSTR *Name);<br />
<br />
private:<br />
esriExtensionState m_ExtensionState;<br />
IApplicationPtr m_ipApp;<br />
BSTR m_szTargetLayer;<br />
ITargetLayer *m_ipTargetLayer;
};<br />
<br />
<br />
<br />
<br />
<br />
HRESULT CMyExtension::SetTargetName(BSTR Name)<br />
{<br />
return this->m_ipTargetLayer->PutTargetLayerName(Name);<br />
}<br />
<br />
HRESULT CMyExtension::GetTargetName(BSTR *Name)<br />
{<br />
BSTR tmp;<br />
HRESULT hr = this->m_ipTargetLayer->GetTargetLayerName(&tmp);<br />
if(SUCCEEDED(hr)){<br />
*Name = tmp;<br />
return S_OK;<br />
}<br />
<br />
return E_FAIL;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
STDMETHODIMP CMyCommand::get_Enabled(VARIANT_BOOL * Enabled)<br />
{<br />
if (Enabled == NULL)<br />
return E_POINTER;<br />
<br />
HRESULT hr;<br />
long selectionCount;<br />
IExtensionPtr pExtension;<br />
IExtensionConfigPtr pExtConfig;<br />
esriExtensionState state;<br />
<br />
hr =this->m_ipMxDoc->get_FocusMap(&(this->m_ipMap));<br />
if(FAILED(hr)){return hr;}<br />
hr = this->m_ipMap->get_SelectionCount(&selectionCount);<br />
if(FAILED(hr)){return hr;}<br />
<br />
hr = this->m_ipApp->FindExtensionByName(::SysAllocString(L"My Extension"), &pExtension);<br />
if(FAILED(hr)){return hr;}<br />
<br />
pExtConfig = pExtension;<br />
pExtConfig->get_State(&state);<br />
if(FAILED(hr)){return hr;}<br />
<br />
<br />
CComPtr<IMyExtension> pHistExt;<br />
const CLSID CLISID_MyExtension = {0x442A8EAF,0x8723,0x4FED,{0xA8,0xA9,0x6D,0x2B,0x65,0x77,0x26,0x61}};<br />
hr = pExtension->QueryInterface(CLISID_MyExtension, (void **)&pHistExt);<br />
<br />
CComBSTR szTName;<br />
<br />
hr = pHistExt->GetTargetName(&szTName);
if(FAILED(hr)){return hr;}<br />
<br />
<br />
<br />
esriEditState pState;<br />
hr = this->m_ipEditor->get_EditState(&pState);<br />
if(FAILED(hr)){return hr;}<br />
<br />
if(selectionCount>0 && (state == esriESEnabled) && (pState == esriStateEditing) ){<br />
*Enabled = VARIANT_TRUE;<br />
}else{<br />
*Enabled = VARIANT_FALSE;<br />
}<br />
<br />
return S_OK;<br />
}<br />
|
|
|
|
|
I am attempting to pass in an empty collection object (MerchandiseCol) defined in VB to a C++ dll. Once C++ recieves the object, I want to fill it with records from a database, and then return it to the VB executable.
Here is what I have...
<br />
extern "C" void __stdcall GetMerchandiseCol(IDispatch* pMerchandiseCol)<br />
{<br />
HRESULT hr = CoInitialize(0);<br />
if (SUCCEEDED(hr))<br />
{<br />
dbMerch dbM;
_clsMerchandise* pMerch;
_colMerchs* pMerchCol;
<br />
hr = pMerchandiseCol->QueryInterface(__uuidof(_colMerchs), (void **) &pMerchCol);<br />
<br />
if(SUCCEEDED(hr))<br />
{<br />
if(dbM.Open())<br />
{<br />
VARIANT varItem;<br />
CComPtr<IUnknown> pUnk;<br />
CComPtr<IUnknown> pMerchandise;<br />
CComQIPtr<IEnumVARIANT, &IID_IEnumVARIANT> pNewEnum;<br />
if (SUCCEEDED(pMerchCol->get_NewEnum(&pUnk)) && pUnk != NULL)<br />
{<br />
pNewEnum = pUnk;<br />
hr = pNewEnum->QueryInterface(__uuidof(_clsMerchandise), (void **) &pMerch); <br />
<br />
_NoAddRefReleaseOnCComPtr<T>* operator->() const<br />
{<br />
ATLASSERT(p!=NULL);<br />
return (_NoAddRefReleaseOnCComPtr<T>*)p;<br />
}<br />
<br />
|
|
|
|
|
Hi all,
I am facing a strange situation where I am supposed to use an idl which has constants and import it into multiple files. The scenario is like this:
// AAA.idl
module XXXX
{
const DWORD JUNK_1 = 0x20;
...............................................
}
// My1.idl
import AAA.idl;
...........
// My2.idl
import AAA.idl;
As shown above, I need to import the AAA.idl into multiple IDL files and since constants cannot be defined in multiple cpp files within the same project, I am getting "already defined" linker errors (LNK 2001). I cannot avoid importing the AAA.idl into multiple files since I need other interfaces defined within the AAA.idl in several places, how can I overcome this error of redefinitions?
Another point to note is that the AAA.idl file is supplied by someone else, so I cannot modify before using it since it will be a continuous maintenance nightmare. I am mainly looking for options such as ignoring the module XXXX while importing the AAA.idl.
Any help to solve this problem is very much appreciated.
Thanks in advance,
Srikanth
|
|
|
|
|
Hi
I'm creating COM addin for MS Word. I would like to create Option Window for my application, so I used template class CAxDialogImpl(sugested on this message board)
class CDial : public CAxDialogImpl<cdial>
I would also like to set(insert) some properties from Edit Box.
From MFC I found that Edit Box is attached to CEdit class and value can be read into CString class.
Unfortunately when I include CEdit class (or CString) in my declaration of CDial class I get next error:
error C2146: syntax error : missing ';' before identifier 'm_edi'
error C2501: 'CEdit' : missing storage-class or type specifiers
error C2501: 'm_edi' : missing storage-class or type specifiers
so I added: #include <afxwin.h>
but then I get
VC98\MFC\INCLUDE\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
I tried also with settings->General: Use MFC in shared dll
but no success.
Please help
Tomaz Rotovnik
|
|
|
|
|
Hi again
I move #include <afxwin.h>
in file StdAfx.h
but now I get linking error
link: executing 'C:\PROGRA~1\MICROS~4\VC98\Bin\link.exe'
nafxcw.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in RecToR.obj
nafxcw.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in RecToR.obj; second definition ignored
Creating library ReleaseMinDependency/RecToR.lib and object ReleaseMinDependency/RecToR.exp
ReleaseMinDependency/RecToR.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
How can I solve that?
Tomaz Rotovnik
|
|
|
|
|
I think I found the problem.
I write down steps for those who will have the same problem
1. Because dll which I build is Extension DLL I shouldn't have definition _USRDLL in preprocessor definitions
2. I include CEdit, CString classes which need afxwin.h header
so I put #include <afxwin.h> as first include statement in StdAfx.h header file before all other #include statements. (solved C1189 error)
3. I think CDialog class is MFC so I also set option:
Use MFC in a Shared Dll
Tomaz Rotovnik
|
|
|
|
|
Hi, I am having an issue trying to post data using the serverxmlhttp interface. Here is a brief overview:
I am collecting data and automatically sending this data back to central repository. Currently, ftp and smtp protocols perform as expected. HTTP is another story. I have a microsoft service running that kicks of the 'transmitter' when there is enough data to send. That service is running with an administrator account (not THE administrator, but a created user with administrative privaledges.) Anyway, when this service kicks off and creates the COM component that actually does the transmissions, my http transmission portion returns a "Access denied" error. If I run the COM component from an executable, however, the transmission succeeds.
I thought that this was an inheritable rights type problem dealing with the service, however, I have redesigned the system and am now having a server component create and launch the COM transmitter. I still am having the same issue.
Any help would be greatly appreciated. Thanks
|
|
|
|
|
:(Well, sorry to disturb for what surely is an easy thing, but...
Which function must i call if the COM library i want to use defines an interface but no class ?
IID_TheClass is defined, but there is no
CLSID_TheClass, that any tutorial/example/help file i read is using ?
I just can't call CoCreateInstance(Ex)...
Note: i'm trying to use within C++ the Microsoft Euro Converter, that is
----------------------------------------
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: MSOEURO.DLL
[
uuid(76F6F3F5-9937-11D2-93BB-00105A994D2C),
version(1.0),
helpstring("Microsoft Office Euro Converter Object Library")
]
library MsoEuro
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface Converter;
[
odl,
uuid(76F6F3F4-9937-11D2-93BB-00105A994D2C),
dual,
oleautomation
]
interface Converter : IDispatch {
[id(0x00000001), propget]
HRESULT Convert(
[in] double Value,
[in] BSTR CurrencyFrom,
[in] BSTR CurrencyTo,
[in, optional] VARIANT FullPrecision,
[in, optional] VARIANT TriangulationPrecision,
[out, retval] double* retval);
[id(0x00000002), propget]
HRESULT Version([out, retval] BSTR* retval);
};
};
am i lost ?
... yeah
|
|
|
|
|
You can look it up in the registry
Searching for msoeuro.dll under HKEY_CLASSES_ROOT gives us the CLSID {30A095E2-9A0C-11D2-93BB-00105A994D2C} and the ProgID MsoEuro.Converter.1 (data from Office 2000 SP3).
|
|
|
|
|
Woah !
Tricky.
But it works. Thanks !
(just need to find WHAT are the args, now)
-----------
"Always give me a new challenge to take up!"
|
|
|
|
|
Hello everyone. I need some help in writing a very simple OutProc multithreaded server in windows API only (not using any ATL wizard or sth.). I just finished normal singlethreaded component and figured out that I need multithreading support. I have no idea how to "enable" multihreading using my code written before. Does anyone know where can I find any materials or sample projects on this topic? Thanks in advance for your help!!
Greetings - TroLoo
|
|
|
|
|
Check out MSDN for examples. Also Search Google. I recommend these books on COM.
Inside COM (Programming Series) by Dale Rogerson
Developer's Workshop to COM and ATL 3.0 by Andrew Troelsen
Kuphryn
|
|
|
|
|
Does anyone know if neutral threading model doesn't work in in XP?
I seem to be getting different results depending on if I am in XP or windows 2000.
any hints?
|
|
|
|
|
Hi all, how can i change the dllhost appbase to look for assemblies in more directories than %system%\system32 and COM+ root directory.
Thanks.
|
|
|
|
|
I want to change a program id for a com project, so it will be different with the previous version.
Just change the .rgs file? or I need to change the uuid in idl files?
thanks
woody
|
|
|
|
|
Do you mean the prog ID string (eg MyServer.MyObject.1) or the CLSID ? If the latter, then you need to edit both. If the former, I think just the RGS, but I would change both anyway to avoid confusion.
Steve S
|
|
|
|
|
How do you configure a COM method and property so they have the same name? Specifically, we're building a browser application that extends the scripting world and needs to support the syntax:
window.external.Foo.setValue1("fred")
AND
window.external.Foo().setValue1("fred")
NOTE: For the record, if we controlled the JScript and could change it to conform to a single syntax we would.
The client has a bunch of JScript pages they don't control and an existing browser based application that needs to be replaced new application. They don't have access to the original developers or source code.
Thank you.
|
|
|
|
|
Looks like the JScript use the different flags of IDispatch::Invoke function in your cases.
/* Flags for IDispatch::Invoke */
#define DISPATCH_METHOD 0x1
#define DISPATCH_PROPERTYGET 0x2
#define DISPATCH_PROPERTYPUT 0x4
#define DISPATCH_PROPERTYPUTREF 0x8
The JScript uses the DISPATCH_PROPERTYGET flag in first case (window.external.Foo), and the DISPATCH_METHOD in second one (window.external.Foo()). For example, VBScript doesn't separate these cases and uses the DISPATCH_METHOD | DISPATCH_PROPERTYGET flag (which is valid).
As a rule, the default implementation of IDispatch will launch the existing function (either method or propget) in case of DISPATCH_METHOD|DISPATCH_PROPERTYGET. But it call only required function in case of DISPATCH_METHOD or DISPATCH_PROPERTYGET.
So the solution is the changing the passed flags from DISPATCH_METHOD or DISPATCH_PROPERTYGET into DISPATCH_METHOD | DISPATCH_PROPERTYGET and the calling of default Invoke-handler. Because the [propget] member and the [method] member with [retval] parameter are very similar.
HTH
With best wishes,
Vita
|
|
|
|
|
Hey, I've created an activeX Control which shows a modeless dialog. Now my Control should notify the containerapp when there a changes in dialogs items. I tried to send a message from my dialogclass to the parent (ControlClass) but nothing happend. How can I notify my ControlClass from within my DialogClass?
|
|
|
|
|
Use events (or Connection Point). You will find good article on Code Project or on the Net.
|
|
|
|
|
I am trying to query if a system has applications instantiated DirectShow video rendering objects.
Is there a way to query how many instances of any particular COM class is currently created on a system? (the instances may be owned by other applications).
If so, is there a way to interface with these created COM objects of another application?
Thanking in advance for a reply.
|
|
|
|
|
Not really. Over at sysinternalls, there are some tools with code, to show you how to view how processes have a loaded copy of a DLL. To get at a COM object of a DLL you need to be in the process to see them, in which case you can then hazard a guess at how many times the DLL has been locked, but then each COM object created adds a lock, so you can't be sure which.
I don't think COM was designed with these kind of metrics in mind.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
I know there have been numerous threads and articles regaring CString to BSTR conversion, but I can't seem to get the solutions given to work.
Here is what I have.
IN VB:
<br />
Private Declare Function GetNextCustomerID Lib "C:\Debug\DataAccess.dll" (CustomerID As String) As Long<br />
THEN:
<br />
Private Sub Form_Load()<br />
Dim TestStr As String<br />
Dim ret As Long<br />
<br />
ret = GetNextCustomerID(TestStr)<br />
If ret = 1 Then<br />
Label1.Caption = TestStr<br />
End If<br />
End Sub<br />
THEN, IN C++
<br />
extern "C" long __stdcall GetNextCustomerID(BSTR& CustomerID)<br />
{<br />
HRESULT hr = CoInitialize(0);<br />
long ret = 0;<br />
CString tmp;<br />
<br />
if(SUCCEEDED(hr))<br />
{<br />
dbReferenceNums dbR;
if(dbR.Open())<br />
{<br />
if(!dbR.IsEOF())<br />
{<br />
tmp.Format("%s%d", "CX", dbR.m_NextAvailCustID);<br />
CustomerID = tmp.AllocSysString();<br />
ret = 1;<br />
}<br />
dbR.Close();<br />
}<br />
CoUninitialize();<br />
}<br />
return ret;<br />
}<br />
if the string is "CX1504", then the result that is printed in VB is "C" and that is all. I assume it is because a null character is encountered, because there is a null character between each character of the string. But, I can't figure out how to prevent this. I thought BSTRs were WCHAR-based strings and this behavior (nulls between each char) would be expected, but it is not interpretted correctly by VB.
Thanks in advance for any help you can provide.
raj.
|
|
|
|
|
Your issue is not connected with COM.
It's a way to call the DLL's function. VB simulate the parameter for you depending on its ANSI or UNICODE version.
ByVal xxx As String => TCHAR* xxx
ByRef xxx As String => TCHAR* *xxx as SysAllocStringByteLen does
You should use the VARIANT parameter instead.
With best wishes,
Vita
|
|
|
|
|
When calling a Declare d Sub or Function, VB6 ALWAYS translates a String into a null-terminated 8-bit char array (i.e. a normal C-style string of char ) - even if running on a Unicode-capable platform. If the string is passed ByRef it will be converted back on return.
What you should probably do is something like:
extern "C" long __stdcall GetNextCustomerID(char* CustomerID, long lSize)
{
long ret = 0;
dbReferenceNums dbR;
if(dbR.Open())
{
if(!dbR.IsEOF())
{
tmp.Format("%s%d", "CX", dbR.m_NextAvailCustID);
strncpy(CustomerID, tmp, lSize);
CustomerID[lSize] = '\0';
ret = 1;
}
dbR.Close();
}
return ret;
}
' VB code
Private Declare Function GetNextCustomerID _
Lib "C:\Debug\DataAccess.dll" _
(ByRef CustomerID As String, ByVal lSize As Long) As Long
Private Sub Form_Load()
Dim TestStr As String
Dim ret As Long
' Reserve space for string
TestStr = String(100, " ")
ret = GetNextCustomerID(TestStr, Len(TestStr))
If ret = 1 Then
Label1.Caption = TestStr
End If
End Sub VB does this because it has no knowledge of the parameters to the DLL function. If your C++ code was exposed as a COM object, VB would be able to obtain type information from the type library, and marshal data appropriately.
VB.NET users: the Declare statement functions as above, unless you specify the Unicode or Auto modifiers. For more control over marshalling, use the DllImportAttribute attribute.
|
|
|
|
|