|
CoInitialize is to initialize the com libraries and for setting up the right apartment for the current thread where you are using the com objects.
You need to do this only once for an application. For example in the caase of an MFC application u can call CoInitialize(NULL); in the initinstace and CoUninitialize(); in the ExitInstance.
No need to call this in every class and method.
If u r in a multithreded app then u need to call CoInitialize and CoUninitialize in each thread.
hope this help...mil10
|
|
|
|
|
Thanks for the reply. That is exactly how I thought it should be done, but in my above code, if I remove it from the destructor, the program crashes on exit. I'm having a nightmare trying to debug this since the xls pointer is an AxtiveX VB coded dll. But I am pretty sure the problem is not even in the dll (it only clears some memory).
I will keep trying nonetheless.
|
|
|
|
|
|
MFC is very particular about outstanding COM references when it shuts down. If you're using a STA, you may want to call AfxOleInit() in your CxxxApp::InitInstance() and let MFC take care of uninitialisation rather than explicitly calling CoInitialize(NULL) and CoUninitialize() in your code. Obviously, if things are a little more complicated or you want to support multiple STAs or a MTA, AfxOleInit() will not suffice.
Hope that helps.
|
|
|
|
|
No matter what I do, whenever and however I remove the CoInitialize(NULL); /** 3 **/ from the destructor the program crashes on exit. I cannot for the life of me find out why. I am not using MFC, this is just a regular Win32 application. Also I should point out that this class is initalised in the global scope and no call is made to the destructor.
|
|
|
|
|
Thanks for all your effort guys, after reading my own reply to your posts I realised my error.
I should have created a global pointer to the object, initialise it on WM_INITIALISE and destroy it on WM_CLOSE. It all works perfectly and as it should do now.
|
|
|
|
|
What are the rules that must be followed while passing interface pointers as parameters of a function?
For example ..
I have declared
<br />
ICaptureGraphBuilder *pBuilder;<br />
IGraphBuilder *pGraph;<br />
They both point to NULL initially.
Can i send the above interface pointers as function parametres where they will be created using CoCreateInstance.
I tried to call the following function.
<br />
BuildGraph(pBuilder,pGraph);<br />
whose implementation is as follows
<br />
void BuildGraph(ICaptureBuilder *pCapBuilder, IGraphBuilder *pGraphBuilder){<br />
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,<br />
IID_IGraphBuilder, (void **)&pGraphBuilder);<br />
<br />
CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, <br />
IID_ICaptureGraphBuilder2, (void **)&pCapBuilder);<br />
}<br />
Now with the above function call i create the filter graph manager and capture graph builder.
But the pBuilder and the pGraph in the calling function point to NULL even though the pGraphBuilder and pCapBuilder doenst not point to NULL anymore.
How can i solve this problem?
|
|
|
|
|
Hello !
That won't get you the interface pointer. Because the parameter seems to be 'pass by value' not 'pass by reference/pass by address'. Remove '&' from 'pGraphBuilder' in CoCreateInstance(). This will get the interface pointer in 'pBuilder' address instead of local 'pGraphBuilder' variable ! For more details look into the call by reference (using Pointers to Pointer)...
Malli...
|
|
|
|
|
malli_123 wrote: Remove '&' from 'pGraphBuilder' in CoCreateInstance().
Thank you it worked
-- modified at 7:06 Wednesday 22nd February, 2006
|
|
|
|
|
Hi ,
We all know windows system supports left mouse button drag and drop operation.
And we still can let our own application to support drag and drop operation.
My issue is can we get selected folders or files names before we release the left mouse button. That is to say, can we get selceted folders or files names during Drag&Drop's mouse moving process?
I want to use shell technicology to implement it. Unfortunately, I can get these informations only when I had clicked right mouse button or use left mouse button to move them to target folder,which supports drag&drop operation.
Any advice is welcome!
Thanks,
Welli
|
|
|
|
|
Hi All
I know this is going to seem like a stupid question, but I have to ask it. I have had a look at the articles on this, but don't understand too much.
I am looking for information, as well as the simplist way to create and implement a IE Toolbar. I have looked at the ones done in WTL and don't understand too much, or maybe I just haven't had enough coffee yet. To give you a bit of background so that you can understand where I am coming from, I do development in C/C++ back end programing, ie no Front end dev in C/C++, so no understanding of MFC or WTL. The only front end programming I do is in Delphi. SO I am trying to find a simple implementation/article that will help me build a Google type tooolbar. So any and all pointers would be greatly appreciated.
Whilst we are on the subject if you could also point out some articles on Deskbands that would be great too. If you could maybe also recomend some books on the subject that would be a great help.
Thanks
Vaughan
"I once thought I saw the light at the end of the tunnel, but it was just the light from a torch of some bastard bringing me more work"
|
|
|
|
|
I'm using the IDispatch and IUnknown interface to do some simple word automation, and I need to be able to insert text at given bookmarks. I've gotten as far as gettin a handle to the Bookmarks collection, but I'm not sure where to go from there.
How do I select a given bookmark, then insert some text after it?
Thanks.
|
|
|
|
|
Hi all,
While working with print templates I got into a situation where my JavaScript loaded ActiveX control was not filling my m_spClientSite with a value other than NULL.
After wrestling with it for a while I decided to take a back door. It was necessary for me to access the COM interfaces in my instance of IE so I went to the Running Object Table. I enumerated its contents and was relaxed when I saw 3 IE entries as that was the number of IE windows I had open. Each one had been opened from the other. My problem is that all the IE objects in the ROT have the values of the first IE window opened (unfortunately not the one I wanted).
So my question is: is there a way of access the other IE COM interfaces?
Or even more helpful: what's the procedure when you control hasn't got a useful value in its m_spClientSite.
Thanks loads for any help
Tom
|
|
|
|
|
I´m working with a template using ADO inside a Windows Service to connect to an SQL Server but I´m getting an "access violation". The following is part of the code that:
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "EndOfFile")
#import "C:\Program Files\Common Files\System\ado\MSJRO.DLL" no_namespace
typedef ADODB::_RecordsetPtr RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;
....
CnnPtr m_Cnn;
HRESULT hr;
hr = m_Cnn.CreateInstance( __uuidof( ADODB::Connection ) );
m_Cnn->Open(CnnStr, UserName, Pwd, NULL); <--- I´m getting the error here
Does any one have a clue on how to solve the problem?
Thanks,
Adrian
|
|
|
|
|
Try passing adConnectUnspecified instead of NULL in the Open function. And what are you using as your connection string?
|
|
|
|
|
Hi,
I´ve tried the adConnectUnspecified but I´m still getting the same error.
I´m using the following string to connect the DB:
static char CnnStr[200]="Provider=sqloledb;Data Source=SAUCE; \
Initial Catalog=loadDB; \
User Id=admin;Password=admin;";
in the:
dbConn->Open("admin","admin",CnnStr)
I´m using the sample in http://www.codeguru.com/cpp/data/mfc_database/ado/article.php/c6729/
to build my service. In fact that example worked ok as an executable, but then when I tried to run it in a Windows Service I began to receive this "access violation" messages. Then I create it dynamicaly (dbConn=new ADOConnect()) , ´cause I thought that these was the problem, but the problem persists.
Thanks,
Dyrl
|
|
|
|
|
Hmmm.
Well, firstly, if you have the username and password in your connection string, you don't need them in the Open function, you can leave them both as "" there.
Secondly, are you initialising the Com interface? You need to run
::CoInitialize(NULL);
before running any ADO code in C++ - I had this problem for a long time when I was first learning! If you don't use this line you will get a pretty serious error - i.e. it won't work!
|
|
|
|
|
Hello,
I was wondering how to build an ActiveX control that integrates as a component "off the form" (say when using VB.net '03 or VB.NET '05). This is a component that has no user interface (except perhaps an icon) and needs never to be visible. I tried all of the various flags in the DECLARE_VIEWSTATUS macro to no avail. For example, the timer object in VB.NET is never on the form; it is shown as a component below the form.
I have experience with COM and ActiveX; I just do not know how to make my component behave like the 'timer' component.
Thanks in advance,
Dave.
|
|
|
|
|
Hi
I want to include an xml validation schema as a part of an executable. My problem is how to add the schema to the MSXML2::XMLSchemaCache40. I have a schema called 'setup.xsd', and m_schemaCache is a MSXML2::IXMLDOMSchemaCollection2 interface to XMLSchemaCache40.
The following code works ('setup' is the namespace for the schema).
<br />
hr = m_schemaCache->add(L"setup", L"Setup.xsd");<br />
Now I want to load the schema from a resource. Since IXMLDOMSchemaCollection2::add only accepts url's or MSXML2::DOMDocument's, I decided to parse the xml data using DOMDocument, and then pass the DOMDocument over to the XMLSchemaCache40.
In the following code, everything seems to be ok until I try to add the DOMDocument to the XMLSchemaCache40. The resource is loaded, The DOMDocument parses it, and no errors are found. The readyState of the DOMDocument is 4.
<br />
wchar_t sResName[10];<br />
swprintf_s(sResName, 10, L"#%d", resourceId);<br />
<br />
TCHAR sRestype[13] = _T("SCHEMA");<br />
HRSRC hres = FindResource(NULL, sResName, sRestype);<br />
if (hres == 0) { <br />
return false;<br />
}<br />
<br />
HGLOBAL hbytes = LoadResource(NULL, hres);<br />
<br />
LPVOID pdata = LockResource(hbytes);<br />
<br />
LPBYTE sData = (LPBYTE)pdata;<br />
BSTR sXml = _bstr_t((char*) sData); <br />
<br />
MSXML2::IXMLDOMDocument* doc;<br />
hr = CoCreateInstance(__uuidof(MSXML2::DOMDocument), NULL, CLSCTX_ALL,<br />
__uuidof(MSXML2::IXMLDOMDocument), (void**) &doc);<br />
if (FAILED(hr))<br />
return false;<br />
<br />
doc->put_async(VARIANT_FALSE);<br />
doc->put_validateOnParse(VARIANT_TRUE);<br />
<br />
VARIANT_BOOL succeeded;<br />
hr = doc->loadXML(sXml, &succeeded);<br />
if (succeeded != VARIANT_TRUE) {<br />
return false;<br />
} <br />
<br />
hr = m_schemaCache->add(bstrNamespace, _variant_t(doc));<br />
if ( FAILED(hr) )<br />
return false;<br />
<br />
return true;<br />
What am I doing wrong? Thanks in advance for any answers
øivind
|
|
|
|
|
how do i protect an activex not to replace?
|
|
|
|
|
<br />
ICreateDevEnun *pSysDevEnum<br />
IEnumMoniker *pEnumCat;<br />
IMoniker *pMoniker;<br />
IPropertyBag2 *pPropBag2;<br />
ULONG cFetched;<br />
hr = CoCreateInstance(CLSID_SystemDevEnum, NULL, CLSCTX_INPROC_SERVER,<br />
IID_ICreateDevEnum, (void**)(&pSysDevEnum));<br />
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,<br />
&pEnumCat, 0);<br />
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK){<br />
hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag2,(void**)pPropBag2);<br />
<br />
The above code produced FAILED(hr)== true at BindToStorage. But it succeeded if IPropertyBag was used instead
What could be the reason?
|
|
|
|
|
The moniker from a device is not a file-moniker. so you can't bind it to a storage. look at IMoniker in your SDK help.
|
|
|
|
|
hi all
iam working on WMI . iam trying to write an application for Event notification.
Iam usimg Win32_Process class, and ExecNotificationQuery for WQl query.
Iam trying to display a message when a new process is created.
my WQL query is
hres = pSvc->ExecNotificationQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_Process' And (TargetInstance.Name = 'notepad.exe' OR TargetInstance.Name = 'calc.exe' ) "),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if iam not wrong ,After executing this query TargetInstance will be Instance of WIn32_process class.
and now iam trying extract data usoing this statement
hr = pclsObj->Get(L("TargetInstance.Name"), 0, &vtProp, 0, 0);
but iam not able to get value of Name property of Win32_Process class into vtProp where vtProp is of type VARIANT.
IWbemClassObject->Get( LPCWSTR wszName,LONG lFlags, VARIANT* pVal,CIMTYPE* pvtType, LONG* plFlavor) is used to retrieves Specified property value.
but here iam using it for getting value fron an istance i.e TargetInstance.Name. Is it the correct way to do if not please help me in extracting value of Name Property.
Please help me in solving this .
Thanks in advance
abhi
|
|
|
|
|
abhiramsss wrote: hr = pclsObj->Get(L("TargetInstance.Name"), 0, &vtProp, 0, 0);
I doubt you can get the TargetInstance.Name this way. I'd Get the TargetInstance, put that into a IWbemClassObject, then call Get again to retrieve the Name property of TargetInstance.
|
|
|
|
|
I want to display a message when a process is closed can u please advice me regarding this.
Thanks in Advance
abhi
|
|
|
|
|