|
I have a COM inproc dll and have written a mc file containing my own custom HResults. When my component throws the HRESULT, I am checking for its value in my MFC Client by use of FormatMessage.
The HR value returned matches with the message ID but the message string comes out to a garbage value.
Has anyone written custom HRs in component and displayed the message in the MFC client before? If yes, how does it work?
Thanks for the help!
-Mandira
|
|
|
|
|
Hi,
I am trying to use Windows Media Player library "WMSServerTypeLib.dll" as an interop. I created the "WMSServerLib.dll" type library and registered using regasm.
When I try to create the object,it throws the following com exception error:
COM object with CLSID {845FB959-4279-11D2-BF23-00805FBE84A6} is either not valid or not registered.
WMSServerClass Server = new WMSServerClass();
I am able to see all the Interfaces in the object viewer
rgds
Jaffar
-- modified at 6:22 Tuesday 27th December, 2005
|
|
|
|
|
When you create an interop Dll you do not register it with regasm. An interop Dll is not a COM Dll, it is a mapping between C# and the actual COM object. You may have replaced the media player COM object with your interop Dll.
|
|
|
|
|
Hi all,
i ahve downloaded a WMI application to get WMI data from maremote computer .
i have taken a win32 console application and included a source file an dto that source file i have included the code
#include "Windows.h"
#include "comdef.h"
//#include "Wbemidl.h"
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
int main(int argc, char **argv)
{
HRESULT hres;
// Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hres << endl;
return 1; // Program has failed.
}
// Step 2: --------------------------------------------------
// Set general COM security levels --------------------------
// Note: If you are using Windows 2000, you need to specify -
// the default authentication credentials for a user by using
// a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
// parameter of CoInitializeSecurity ------------------------
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
// Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI -------------------------
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
// Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method
IWbemServices *pSvc = NULL;
// Connect to the root\cimv2 namespace with
// the current user and obtain pointer pSvc
// to make IWbemServices calls.
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
// Step 5: --------------------------------------------------
// Set security levels on the proxy -------------------------
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----
// For example, get the name of the operating system
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_OperatingSystem"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for operating system name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
VariantInit(&vtProp);
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
wcout << " OS Name : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);
}
// Cleanup
// ========
pSvc->Release();
pLoc->Release();
pEnumerator->Release();
pclsObj->Release();
CoUninitialize();
return 0; // Program successfully completed.
}
but when iam compiling iam getting the following error
fatal error C1083: Cannot open include file: 'Wbemidl.h': No such file or directory
so can u please me regarding this
abhi
|
|
|
|
|
Hi
I gave developed the com addin for outlook 2003. I am attaching toolbar in inbox second level. If the username is in Chinese Traditional Charset then it doesn't work. I mean the toolbars does not get attached.
I have written code and on reveiewing i think something goes wrong here..
CComPtr<outlook::recipient>CurrUser;
BSTR username;
char* strName=new char[50];
mysession->get_CurrentUser(&CurrUser);
CurrUser->get_Name(&username);
strcpy(strName,"\nCreated By: ");
strName=strcat(strName,_com_util::ConvertBSTRToString(username));
strcpy(m_username,strName);
delete strName;
strName=0;
...
This is not unicode strings char* and if username is Chinese Traditional charset code is imncorrect.
this coment was given by one of my senior friend.
Looking forward for reply,
Cheers
Ganesh
hi
|
|
|
|
|
Hello,
I am trying to play video inside a panel.
The problem is that i can't get a window handle for the planel and here is the code that i am wriiting:
pWindow->put_Owner (this->panel1->Handle);
[Error C2664]: 'IVideoWindow::put_Owner' : cannot convert parameter 1 from 'System::IntPtr' to 'OAHWND'
How can i fix this problem. My end goal is just to play the file in the panel not in a pop up window!!
Thanks
|
|
|
|
|
Hi,
I have to build a dll which doesn't get loaded into the process space of the client. It has to own its process space. I figured out that Out-of-proc exe is suitable option for me. But now I am bit confused about win nt services and out of proc exe.
My question is:
are both of these types compatible with all Win versions? 9x, 2k and XP?
Whats the basic difference between out of proc exe and winnt server?
Are there any address mapping issues with winnt service exes? or any other issues involved with winnt services?
Thanks a ton in advance.
Misha
|
|
|
|
|
I have written a component code ,server code and client code using c#.all the three were built successfully.but when i run the client code it throws a remoting exception "requested service cannot be found"
the server code and the client code r on the same computer.
i am new to this!!!!!! SOS
santosh
|
|
|
|
|
Dear all,
I am using EVC4 to try a ATL COM program. Some source codes are as following. I got a first-chance exception problem. Can anyone help to tell me the reason? Can we test the .dll using some tools like the ActiveX Control Test Container?
ConnectionCom.cpp
#include "stdafx.h"
#include "resource.h"
#include "initguid.h"
#include "ConnectionCom.h"
#include "ConnectionCom_i.c"
#include "Add.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Add, CAdd)
END_OBJECT_MAP()
class CConnectionComApp : public CWinApp
{
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
};
CConnectionComApp theApp;
BOOL CConnectionComApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance);
return CWinApp::InitInstance();
}
int CConnectionComApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
_Module.UnregisterServer();
return S_OK;
}
ConnectionCom.idl:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(4B15EACE-A33D-4E53-B815-5486B457AEDF),
dual,
helpstring("IAdd Interface"),
pointer_default(unique)
]
interface IAdd : IDispatch
{
[id(1), helpstring("method Add")] HRESULT Add(int a, int b);
};
[
uuid(7D8286AC-AA29-48B1-A3A9-9394D54EBE22),
version(1.0),
helpstring("ConnectionCom 1.0 Type Library")
]
library CONNECTIONCOMLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(1B58E8FD-6D14-45BB-88F1-1DF5CBC05932),
helpstring("_IAddEvents Interface")
]
// dispinterface _IAddEvents
// interface _IAddEvents : IUnknown
interface _IAddEvents : IUnknown
{
[id(1), helpstring("method ExecutionOver")] HRESULT
ExecutionOver(int Result);
};
[
uuid(C0B7BD5D-B23E-4B9A-9DAE-C32B3CCEF193),
helpstring("Add Class")
]
coclass Add
{
[default] interface IAdd;
//[default, source] dispinterface _IAddEvents; take this line
//out and put the line below in
[default, source] interface _IAddEvents ;
};
};
Add.h:
#ifndef __ADD_H_
#define __ADD_H_
#include "resource.h" // main symbols
#include "ConnectionComCP.h"
/////////////////////////////////////////////////////////////////////////////
// CAdd
class ATL_NO_VTABLE CAdd :
public CComObjectRootEx<ccommultithreadmodel>,
public CComCoClass<cadd, &clsid_add="">,
public IConnectionPointContainerImpl<cadd>,
public IDispatchImpl<iadd, &iid_iadd,="" &libid_connectioncomlib="">,
public CProxy_IAddEvents< CAdd >
{
public:
CAdd()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ADD)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CAdd)
COM_INTERFACE_ENTRY(IAdd)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CAdd)
CONNECTION_POINT_ENTRY(IID__IAddEvents)
END_CONNECTION_POINT_MAP()
// IAdd
public:
STDMETHOD(Add)(int a, int b);
};
#endif //__ADD_H_
Add.cpp
#include "stdafx.h"
#include "ConnectionCom.h"
#include "Add.h"
/////////////////////////////////////////////////////////////////////////////
// CAdd
STDMETHODIMP CAdd::Add(int a, int b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
Sleep(1000);
Fire_ExecutionOver(a+b);
return S_OK;
}
When I call the Add method from the client program, I got the problem.
Please help!
Best Wishes,
HWB
|
|
|
|
|
What kind of exception was it? A first chance exception just means that the debugger is being notified before the application itself has a chance to handle the exception (the second chance) - It doesn't describe the exception itself.
Steve
|
|
|
|
|
I have an OCX Control, created with Visual C++ 6.0
I created another new OCX control, similar to the first one with very little changes. I registered the new one and it replaced the old one.
My problem is that I want both. Renaming the OCX and registering did not help me. How do i do this? Any help is highly appreciated.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
I dont know much about COM. Just an idea. I guess the clsid's of both are same. Try generating new CLSIDs with GUIDGEN.exe and putting them in one of the OCX. The re-build and re-register. Hope it will help
|
|
|
|
|
Exactlly, the CLSID for both the activex controls are same thats why you were
not able to use both OCX. Change the CLSID for modified OCX and register the
activex component, this would certainly solve the problem.
Cheers,
Vishal
|
|
|
|
|
You'll also want to create a new ProgID for the second component, or CreateObject()/new ActiveXObject() won't work.
Kev
|
|
|
|
|
I have a software which puts all the data in a dll....I want to access this data from MATLAB and I want it to be event driven. For this(event driven operations in MATLAB) I have to create a COM. I have no experience in creating COM. I googled but couldn;t find any good material on COM basics and hwo to create one. :(could anyone tell me how to proceed?
thanks
-- modified at 16:27 Tuesday 20th December, 2005
|
|
|
|
|
Hi Vidyarani,
I am currently working on a similar problem it seems. See the message “out-of-process DLL”. If you are trying to transfer data to MATLAB and if you are trying to let your DLL tell MATLAB what to do with the data, then you can/should use the MATLAB engine. I suppose you are writing the DLL not the application, right? There are MATLAB engine library files, which you can link with your DLL project. The MATLAB engine library basically sets up a COM connection with MATLAB with the advantage that you do not have to worry about COM.
The MATLAB engine library lets you transfer data to and from MATLAB. Your DLL should transfer data by creating MATLAB data-types (matrixes) using mx-functions, also included in the MATLAB engine library files. To create event driven operation you can first transfer data to MATLAB, and then you can execute .m-functions by letting the MATLAB engine, within your DLL, tell MATLAB which .m-function to execute. In this way, the .m-functions act as a kind of callback-functions.
I hope this is the kind of event driven operation you are after. If you also want MATLAB to call back to your DLL in an event driven manner, then you should be looking at COM as well. But to do this from within a DLL is not straightforward.
Things to look at in MATLAB help:
MATLAB \ External Interfaces/API \ Calling MATLAB from C and Fortran Programs
MATLAB \ External Interfaces/API Reference \ C Engine Functions
MATLAB \ External Interfaces/API Reference \ C MX-Functions
Things to look at in MATLAB root:
..\ MATLAB \ extern “MATLAB engine library files”
I hope this will get you going. If it doesn’t and you really want to create COM functions in your DLL and you want MATLAB to call these functions, then you are facing the same problem I have. In that case we can discuss further.
Kind regards,
Marcel Dijkstra
|
|
|
|
|
Hi Marcel,
Thanks for the reply. Let me explain as to what exactly.
---------------------------------
| Have Software which sends data |
---------------------------------
|
|
---------------------------------- --------------------------
| DLL where the data is stored | -------------|other apps accessing data|
---------------------------------- ---------------------------
whenever the DLL gets fresh data it can send a notification(or event) . I need to access this data from the DLL i.e want MATLAB to call these functions
I really dont want to make any changes to the DLL as there are a lot of other applications which use the DLL. So I will have to build a COM isn't it?
Regards,
Vidya
|
|
|
|
|
Hi Vidya,
I actually misunderstood your problem. So you are not programming the DLL, but you are thinking about making something in COM for MATLAB. Am I right in assuming that the DLL has already got a COM interface with which other programs can access its data? I assume this is the case because otherwise there would be no use in writing anything in COM if you do not want to change the DLL. How is this event/notification done? Also through COM?
Lets assume the DLL exports COM(ActiveX) automation objects then MATLAB can directly connect to these COM server objects in your DLL. Open you registry “Start-Run-regedit ” then goto ”My Computer \ HKEY_CLASSES_ROOT \ CLSID ”. Select CLSID and search for your DLL or application name. As an example search for “Microsoft Office Excel Application ”. If I do this, regedit finds the key “My Computer \ HKEY_CLASSES_ROOT \ CLSID \ {00024500-0000-0000-C000-000000000046} ”. Now you can find the subkey “ProgID ” with value “Excel.Application.11 ” or something similar.
Now you can connect to this COM server object by using its ProgID in MATLAB.
Type in the command window:
e = actxserver('Excel.Application.11');<br />
methodsview(e);<br />
e.Help();
If actxserver() succeeds you can use methodsview() to see the functions you can access. As an example we can ask the Excel COM object to display help information by calling e.Help() ;
I hope this is what you are looking for.
Regards,
Marcel
|
|
|
|
|
Hi Marcel,
The DLL has not got a COM interface. I need a COM which can speak to the DLL and MATLAB. So the COM gets the information from the DLL and sends it to MATLAB. I have an example but not able to figure out how to do it myself? So wanted to know if there are more examples?
Thanks
Vidya
|
|
|
|
|
Hi Vidya,
Correct me if m wrong !!!
Whenever the dll gets fresh data its sends some notification/events, its done?
Okay so you need to access this data, right ?
One possible way to do so is capture the notificaion/events sent by the dll.
Another way of doing such thing is use the interfaces exposed by your dll, I
mean your dll sends a notification/events, so there must exists some exposed
interfaces...
To check that your dll has exposed interfaces or not, you can design the
sample using ATL...
Steps to genertate the sample
1. Select ATL component project
2. Add simple object to project
3. Go to class view tab
3. Right click on class and select implements interface, it will pop up
a dialog
4. Click on "AddTypeLib", select your dll's typelib and click "ok"
5. It will show you the list of interfaces exposed by your dll
5. Select the appropriate interface and click ok
6. IDE will generate the source code for interface implementation
Ah, I think you should try this... this might ease the difficulty you are
facing....
Let me know if I can do ne thing?
Cheers,
Vishal
|
|
|
|
|
Perhaps more information on the nuts and bolts of how one actually *writes* this software may be helpful.. I have a step-by-step DCOM tutorial, where I build a simple server which says "Hello, world!" back to the client, may help put some of this in practical perspective...
The tutorials are written as a series of separate articles, called Steps, which cover the major breakpoints in the development of the system.
Step 1 of the tutorial for VC 6 is at
http://www.codeproject.com/com/HelloTutorial1.asp[^]
And Step 1 of the turtorial for Visual C++.NET 2003 is at
http://www.codeproject.com/useritems/HelloTutorial1NET.asp[^]
I tried to write the tutorials in Microsoft-ese, so you can follow along as if you were reading the Scribble tutorial. The VS.NET version is still a work in progress; that's why it's still in "Unedited User Constributions."
Not all the Steps have been written for the VS.NET version yet. But I am working on it!
Stay tuned!
Sincerely Yours,
Brian Hart
Department of Physics and Astronomy
University of California, Irvine
|
|
|
|
|
Hi everybody,
I need to implement Doc/View/Frame in an ActiveX control. I have tried to copy the code from a standart MFC Wizard generated SDI application in a standart Wizard generated ActiveX control, but it didnt work - all I could get was a bunch of crashes (for the document, I derived my class from COleDocument). Can anybody point me in the right direction. Any information is appreciated.
Thanks in advance,
Dennis.
|
|
|
|
|
|
|
I just wanted to day that I stopped finding a way to send this copydatastruct to load a new file.
I find it rather difficult to debug because I can't really see what going on in the bsplayer. And I found out that when I start BSPlayer with parameter file or playlist it also work, and that is sufficient for the moment.
Winspector is a nice tool to see the windows messages flying around, and I could see the pointer arriving in the bsplayer process, but it's unclear why it still does not work. I have tried converting the datapath string to a char[] array and ended it with \0 but nothing worked.
Next project will be a little C# movie player with DirectShow.
greetings, Bart
|
|
|
|
|