|
can you guide me that on which event i should call this function i mean on DISPID_NAVIGATECOMPLETE2 OR behind some other thanks
|
|
|
|
|
hi all,
I am new to ATL|COM .
I have created a COM dll with a sinple function returning a string .
Now i want to access that function from my C++ Application.
Can anyone please help me to create an instance for this dll so that i can call that dll method.
A piece of sample code will be of great help.
Thanks in advance,
Veena.
|
|
|
|
|
Hope this helps you,
HRESULT hr = CoInitialize(NULL);
IMyInterface *pIMy;
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CMyIterface,
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMyInterface ),
(void **) &pIMy);
if (FAILED(hr))
{
CoUninitialize();
}
else
{
pIMy->MyFunction();
}
}
CoUninitialize();
|
|
|
|
|
do following steps
1. #import .tlb file in your client application. you will find this file in the folder of your com project.
2. Following code should solve your problem.I haven't done any error checking in following
code.
BSTR name;
CoInitialize( NULL );
IExpressionData* pOutputData = NULL;
hResult = CoCreateInstance(CLSID_CExpressionData //replace with your CLSID
, NULL
, CLSCTX_INPROC_SERVER
, IID_IExpressionData /replace with your IID_
, (void**)&pOutputData);
hResult = pOutputData->your_method( &name );
CoUninitialize( );
satindar
|
|
|
|
|
How can i run dos command using dotnet
for example: I want to run following command
Dir D:\*.*
now not only want to run that but the which ever result comes that i want to take in the dotnet windows form, i mean i want to print that result in the textbox OR if it should display directories in the listbox or some thing like that.
So is there any way to do that coz this is very urgent, please help me friends, u have helped me before this as well so please help me now as well
Harshad Pednekar
|
|
|
|
|
Post this question to appropriate forum to get fast reply.
|
|
|
|
|
Hi Prasad
Please tell me what more info u want i will give u that also so u can help
Thankx for replying
Harshad Pednekar
|
|
|
|
|
Hi All,
Am new to COM and i tried creating a COM server and COM client
COM Server is created by inservting ATL COM object in to MFC Dialog based application project
I hav build the Server application successfully then i tried to CoCreateInstance() from the client app. i hav imported the .tlb file and TestCOMMFC_i.h files. But am getting the following link errors
Compiling...
TestClientDlg.cpp
Linking...
TestClientDlg.obj : error LNK2001: unresolved external symbol _CLSID_TestServer
TestClientDlg.obj : error LNK2001: unresolved external symbol _IID_ITestServer
Release/TestClient.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
TestClient.exe - 3 error(s), 0 warning(s)
pls reply asap
thnx in advance
|
|
|
|
|
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
|
|
|
|
|