|
You should also use the TESTCOMMFC_i.c file, which has the data for these symbols in it. Alternatively, you could use #import on the type library, with the named_guids tag.
If you use the _i.c file, don't forget to change it's settings so that it doesn't use pre-compiled headers.
Steve S
Developer for hire
|
|
|
|
|
Hello!
I'm trying to turn on/off system restore on Windows Vista by
calling methods Enable/Disable of WMI Class SystemRestore.
My program works ok on Windows XP. But when I try to run
it on Windows Vista I don't have the desired result.
The ReturnValue of method ExecMethod equals to RPC_X_NULL_REF_POINTER
(A null reference pointer was passed to the stub).
Can anyone help me and tell what's wrong.
Here is the code of my program
<br />
<br />
HRESULT hres;<br />
<br />
hres = CoInitializeEx(0, COINIT_MULTITHREADED); <br />
if (FAILED(hres))<br />
{<br />
cout << "Failed to initialize COM library. Error code = 0x" <br />
<< hex << hres << endl;<br />
return 1;
}<br />
<br />
hres = CoInitializeSecurity(<br />
NULL, <br />
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);<br />
<br />
<br />
if (FAILED(hres))<br />
{<br />
cout << "Failed to initialize security. Error code = 0x" <br />
<< hex << hres << endl;<br />
CoUninitialize();<br />
return 1;
}<br />
<br />
IWbemLocator *pLoc = NULL;<br />
<br />
hres = CoCreateInstance(<br />
CLSID_WbemLocator, <br />
0, <br />
CLSCTX_INPROC_SERVER, <br />
IID_IWbemLocator, (LPVOID *) &pLoc);<br />
<br />
if (FAILED(hres))<br />
{<br />
cout << "Failed to create IWbemLocator object. "<br />
<< "Err code = 0x"<br />
<< hex << hres << endl;<br />
CoUninitialize();<br />
return 1;
}<br />
<br />
<br />
IWbemServices *pSvc = NULL;<br />
<br />
hres = pLoc->ConnectServer(<br />
_bstr_t(L"ROOT\\Default"), <br />
NULL,<br />
NULL, <br />
0, <br />
NULL, <br />
0, <br />
0, <br />
&pSvc<br />
);<br />
<br />
if (FAILED(hres))<br />
{<br />
cout << "Could not connect. Error code = 0x" <br />
<< hex << hres << endl;<br />
pLoc->Release(); <br />
CoUninitialize();<br />
return 1;
}<br />
<br />
cout << "Connected to ROOT\\Default WMI namespace" << endl;<br />
<br />
hres = CoSetProxyBlanket(<br />
pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);<br />
<br />
if (FAILED(hres))<br />
{<br />
cout << "Could not set proxy blanket. Error code = 0x" <br />
<< hex << hres << endl;<br />
pSvc->Release();<br />
pLoc->Release(); <br />
CoUninitialize();<br />
return 1;
}<br />
<br />
<br />
BSTR MethodName = SysAllocString(L"Disable");<br />
BSTR ClassName = SysAllocString(L"SystemRestore");<br />
<br />
IWbemClassObject* pClass = NULL;<br />
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);<br />
<br />
IWbemClassObject* pInParamsDefinition = NULL;<br />
hres = pClass->GetMethod(MethodName, 0, <br />
&pInParamsDefinition, NULL);<br />
<br />
IWbemClassObject* pClassInstance = NULL;<br />
hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);<br />
<br />
VARIANT varCommand;<br />
varCommand.vt = VT_BSTR;<br />
varCommand.bstrVal = L"C:\\";<br />
<br />
hres = pClassInstance->Put(L"Drive", 0,<br />
&varCommand, 0);<br />
wprintf(L"The command is: %s\n", V_BSTR(&varCommand));<br />
<br />
IWbemClassObject* pOutParams = NULL;<br />
hres = pSvc->ExecMethod(ClassName, MethodName, 0,<br />
NULL, pClassInstance, &pOutParams, NULL);<br />
<br />
if (FAILED(hres))<br />
{<br />
cout << "Could not execute method. Error code = 0x" <br />
<< hex << hres << endl;<br />
VariantClear(&varCommand);<br />
SysFreeString(ClassName);<br />
SysFreeString(MethodName);<br />
pClass->Release();<br />
pInParamsDefinition->Release();<br />
pOutParams->Release();<br />
pSvc->Release();<br />
pLoc->Release(); <br />
CoUninitialize();<br />
return 1;
}<br />
<br />
<br />
VARIANT varReturnValue;<br />
hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0, <br />
&varReturnValue, NULL, 0);<br />
<br />
cout << "Return Value: " << V_I4(&varReturnValue);<br />
<br />
<br />
VariantClear(&varCommand);<br />
VariantClear(&varReturnValue);<br />
SysFreeString(ClassName);<br />
SysFreeString(MethodName);<br />
pClass->Release();<br />
pInParamsDefinition->Release();<br />
pOutParams->Release();<br />
pLoc->Release();<br />
pSvc->Release();<br />
CoUninitialize();<br />
<br />
getchar();<br />
return 0;<br />
<br />
|
|
|
|
|
Hi
I am reading an article author said:
"Windows lets you share code at the binary level using DLLs. After all, that's how Windows apps function - reusing kernel32.dll, user32.dll, etc. But since the DLLs are written to a C interface, they can only be used by C or languages that understand the C calling convention. This puts the burden of sharing on the programming language implementer, instead of on the DLL itself."
[url]http://www.codeproject.com/com/comintro.asp[/url]
Are user32.dll ,kernel32.dll... COM dlls or are they only written in c interface?
I they only written c interface how can other programming languages use these system32 dlls?
|
|
|
|
|
No, they provide a 'flat' interface - no understanding of objects. Any language implementation on the Windows platform has to understand the Windows C-language Application Binary Interface (ABI), otherwise they simply could not produce working programs.
However, the C++ ABI is not standardised and therefore linking C++ programs with DLLs compiled with a different C++ compiler is unlikely to work. In practice you can normally manage to link a C++ program and DLLs with different versions of the same compiler. Otherwise you have to define a 'flat' interface on the C++ DLLs.
COM defines an ABI for calling between objects.
|
|
|
|
|
Thank you very much Mike Dimmick.
Can you plase explain what the meaning of 'flat' interface.
Can you please give me an example or your experience about c++ ABI and DLLs compiled with a different C++ compiler is unlikely to work.
I think this is perfect explanantion but i am beginner so i don't understand it totally.
Can you plase give me more details.
Thanks again...
|
|
|
|
|
sawerr wrote: Can you plase explain what the meaning of 'flat' interface.
Can you please give me an example or your experience about c++ ABI and DLLs compiled with a different C++ compiler is unlikely to work.
1. Flat interface means no C++ style classes, eg Window::Close(), instead there are just functions - CreateWindow(), CreateFile()*, CloseHandle() etc.
2. If you have a library or DLL built using VC++, it's unlikely to link correctly against code compiled using a different C++ compiler. In many cases, things like MFC extension libraries are now supplied in multiple flavours, VC6, VC.NET, VC.NET 2003, and VC 2005. A former colleague of mine struggled for ages to get a C++ class compiled with Borland to link with VC++. In the meantrime, I'd implemented a rewrite of the relevant code
* Actually, it's CreateFileA and CreateFileW on WinNT, Win2K, WinXP and Server 2003, while WinCE has only CreateFileW, but that's a different question...
Steve S
Developer for hire
|
|
|
|
|
Hi
I've got a situation where as the title of this request suggests I'm embedding an ActiveX control (IsoView) into an ActiveX control I'm writing (to simplify the interface for out JavaScript boys).
I didn't have any trouble instantiating the control but how to embed it in the ActiveX control when there's no form to set it in is a bit of a mystery to me.
So, how do I dynamically embed an ActiveX control on a window.
Thanks for any help
Tom
|
|
|
|
|
Hi Tom,
If you've added the control with ClassWizard you've got a header file as well as an implementation file for the control.
Have a look inside and you'll find that the ClassWizard created wrapper class, deriving from CWnd, has overridden the Create() function and calls CWnd::CreateControl for you.
Simply have member variable of the wrapper class type and call Create() for that instance.
You don't have to show the control, you may set the CRect argument to {0, 0, 0, 0} and set the dwStyle argument to SW_HIDE.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hi Roger,
Thanks for the advice. I'll impliment it ASAP. As a work around I had resorted to creating a dialog box I could drag the control onto and then drew the dialog box onto the control window. Effective but ugly.
Thanks for the advice
Tom
|
|
|
|
|
Worked a treat!
Thanks Roger
Tom
|
|
|
|
|
Glad I could help you.
--
Rog
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
hi all i want to know how to unregister COM through regsvr32.exe.
Tasleem Arif
|
|
|
|
|
If you used the command
regsvr32 /?
you'd discover that /u would do the trick.
Steve S
Developer for hire
|
|
|
|
|
I want to pass an Array of BSTRs in a Connection point. I am using ATL. Can anyone help ?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Either pass a SAFEARRAY that contains BSTR, or pass a variant that is of type VT_ARRAY|VT_BSTR, where the array points to a SAFEARRAY of BSTRs.
Steve S
Developer for hire
|
|
|
|
|
HI all,
I want to know that a user can create the object of an interface using CoCreateInstance as well as using new. What are the advantages of using CoCreateInstance vs new
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
One of the strengths of COM is that it is language-neutral, so a COM component can generally be used from any environment; 'new' is a C++ only thing, unless you're talking about the VB form,
set x = new object
which is, of course, a VB only thing.
By using 'new', you are creating an object instance on the local machine, whereas CoCreateInstance may (invisibly to you as a client) instantiate something remotely. Generally speaking, if you want an interface (which you should, since it provides a reference-counting mechanism, preventing you from using delete on an object which may have outstanding interface references) then use CoCreateInstance. If you need an object pointer, that isn't COM, it's C++. Of course, you may bend these rules slightly inside servers, since an interface method may create an object that it then hands back an interface to, but care should be taken with this to ensure that the normal COM rules are followed.
An interface is not a pointer to an object. It's an interface.
Steve S
Developer for hire
|
|
|
|
|
hi all i m new the ATL/COM i had made the com that checks which url user is currently visiting and save that in a file.i m checking that through the button event using vc++ another application i mean calling its method that checks and write on file.
now i want that when intenet exolorer runs it should be called automatically and do its work.how to do that.
Thank in advance.is there is any build in function or what i should do.
Tasleem Arif
|
|
|
|
|
you might need to write a BHO. Its add-in to IE.
Look for BHO on CP.You will get help to add one.
|
|
|
|
|
Hello,
I am implementing a Shell extension and it create a virtual folder to map to d:\\temp,
I create a thread use ReadDirectoryChange to watch d:\\temp have any write action,
the thread is in COM dll shell extension's EnumObject function(the create's place maybe not the root cause),
and want when user close the explorer, I'll tell the thread to exit(means no more need to watch any write action in virtual folder).
Right now the only place I can thourht is when call DllMain's process_detach,
I have following scenario,
1. when I use SetEvent(hStopEvent) to set a global event in DllMain's process_detach tell thread to stop, the thread's waitforsingleobject(hStopEvent, Infinite) to wait the global event didn't wait the event signal, it still block in waitforsingleobject(hStopEvent, Infinite),
But when I move the SetEvent(hStopEvent) to other place, not in Dllmain's process_detach, it works fine, the thread will wait htat event succes anf exit himself.
2. I can't solve the question one, Because the only place I know can stop thread is DllMain's process_detach, so I decide set a global boolean bStopThread, the thread will keep check that boolean to decide stop thread or not, and set bStopThread to TRUE in DLLMAIN's process_detach,
But after I set the bollean to TRUE, it seems thread didn't run to check bollean point, then the DLL is exit, so I don't know thread is end or not, I thought it didn't end, because I use debug mode to trace, thread didn't run to check bollean point, but the DLL already exit.
Question is,
1. In scenario two, the thread is end or not? it seems thread didn't end? but I can delete that dll afte dll exit, so it means the thread have already end?
2. how to slove Scenario one, to let thread can wait a global event and set event in DLLmains process_detach?
Thanks for your help~!!
|
|
|
|
|
I already implement ReadDirectoryChangesW in Asynchronus mode, and add OVERLAPPED event.
EX:
while(TRUE)
{
ReadDirectoryChangesW(...)
HANDLE hHandle[2];
hHandle[0] = stop thread global event;
hHandle[1] = OVERLAPPED event
ret = waitformultipleobject(2, hHandle, FALSE, INFINITE);
case(ret)
......
}
the OVERLAPPED event works fine, I can always read directory change's return result,
My question is when I use setevent to set stop global event in DLLMain's process_detach, ret = waitformultipleobject(2, hHandle, FALSE, INFINITE); didn't return~!!
but if I move setevent(stop global event) to other function,
ex:
1. in my function CreateThread() creat ReadDirectoryChange thread.
2. for test Sleep(5000) in function CreateThread();
3. SetEvent(stop thread global event).
The ret = waitformultipleobject(2, hHandle, FALSE, INFINITE); will return successfully, and do correspond stop thread action.
Why I use SetEvent(stop thread global event) in DLLMain's process_detach didn't work?
|
|
|
|
|
I was wondering if someone could give me a hint on how to access the objects in the IHTMLElementCollection returned from get_applets(). I can get to the IHTMLElement and see the innerHTML - that indeed I have the correct objects. I am was hoping for something similar to images where you get the object as a IHMTLImgElement, that gives you specific functionality based around images, except in this case for the embedded objects.
I have been tasked with extracting various parts of webpages, the missing functionality is retrieving where media players(embedded) are getting content and what flash players are using for content. I expected the embeded objects to come in from the get_embedded() call, but look at the IE DOM, they are indeed placed under the applet branch. I can get the innerHTML, and parse it myself, but if there is some object like IHTMLAppletElement(which I don't think exists from the IDL - and MS docs are vague about, other than images, links and anchors) that gives me specific funcationality, would be great. I don't want to parse the innerHTML unless it's my last resort. That will leave me in the relative vs absolute path quagmire for the media paths.
Thanks in Advance.
|
|
|
|
|
I have COM object written in C# that exposes connection points and deployed as out of process server.
I wrote VB6 application that supplies handler for the events fired by this COM object.
To do that I added reference in my VB project to type library generated for C# COM.
Next I used WithEvents statement in my VB code to declare variable of the events firing type exported from the COM.
The application works fine. I can consume the events from the C# COM in my VB6 code.
Problem arises when I stop my VB application.
The delegate that implements the event in C# remains assigned and exception is thrown when attempt is made to call it.
When you implement Event Sink say in C++ you use Advise – Unadvise paradigm to assign and clean up your handlers.
What you supposed to do in VB6?
Any help will be appreciated.
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
I would like to derive multiple interfaces from the same base interface.
In the IDL file I have the following:
<br />
interface IBase : IUnknown<br />
{<br />
HRESULT BaseFunc ();<br />
};<br />
<br />
interface IDerived1 : IBase<br />
{<br />
HRESULT Derived1Func ();<br />
};<br />
<br />
interface IDerived2 : IBase<br />
{<br />
HRESULT Derived2Func ();<br />
};<br />
This actually works, but I guess that's the wrong approach, because if I now implement the interfaces in C++ that doesn't work well.
<br />
class CBase : public IBase ...<br />
class CDerived1 : public IDerived1 ...<br />
class CDerived2 : public IDerived2 ...<br />
CDerived1 and CDerived2 would then have to re-implement the methods of CBase. This could be avoided by making CBase a template, but is this actually how it should been done?
Or is this the correct way?
class CDerived1 : public CBase, public IDerived1<br />
{<br />
};
The IBase interface should be exposed to the clients of the IDerived interfaces and the implementation is the same for all derived interfaces.
I haven't found any examples where multiple interfaces are derived from a base interface, it would be great to see same sample code.
Thanks
|
|
|
|
|