|
Hi Friends,
I am using VC++ 6.0 I careated an exe server using ATL. It has one interface mdethod "ComputerName". Prototype of method is :
[id(1), helpstring("ComputerName")] HRESULT ComputerName([out] short *pnSize, [out, size_is(1, *pnSize)] unsigned char **ppszComputerName);
Server implementation of this function is :
STDMETHODIMP CTestServer::ComputerName(short *pnSize, unsigned char **ppszComputerName)
{
TCHAR szBuffer[100] = {0};
DWORD dwSize = 0;
int iLength = 0;
dwSize = sizeof(szBuffer);
GetComputerName(szBuffer, &dwSize);
iLength = ::lstrlen(szBuffer);
*pnSize = iLength;
*ppszComputerName = (unsigned char *) CoTaskMemAlloc(iLength + 1);
::lstrcpy((char *) *ppszComputerName, szBuffer);
return(S_OK);
}
Client Side Implementation is :
ITestServer *pITestServer = NULL;
HRESULT hResult = NULL;
short int nSize = 0;
unsigned char *pszComputerName = NULL;
CoInitialize(NULL);
hResult = CoCreateInstance(....);
if(SUCCEEDED(hResult))
{
pITestServer->ComputerName(&nSize, &pszComputerName);
// Here is problem only pszComputerName[0] contains valid data. other contains invalid data. nSize contains valid length.
pITestServer->Release();
}
CoUninitialize();
I am unable to get the reason. Anyone can help me please.
Manish Rastogi
|
|
|
|
|
Hi Manish,
If you want to pass string, use BSTR. COM marshalling works a bit different.
If you plan to transfer 'byte*', use Safearray of byte.
God bless,
Ernest Laurentin
|
|
|
|
|
Thanks Ernest Laurentin
BSTR is working.
|
|
|
|
|
Hi All,
I have an ActiveX control. And the event map is defined in the control's implementation (.CPP) file.
Say the event map has a function
EVENT_CUSTOM("SomeEvent", FireSomeEvent, VTS_BOOL)
defined in it...
Now I can very easily call the function 'FireSomeEvent' from the control's implementation cpp file.
Can I call 'FireSomeEvent' from some other cpp file....means some other's class's code ??
If yes then how??
Urgent help needed...
Thanks and Regards
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
//Main.h
__interface IFileIO : IDispatch
{
[id(1), helpstring("method GetFile")] HRESULT GetFile();
[id(2), helpstring("method getDirectory")] HRESULT GetDirectory();
};
class ATL_NO_VTABLE EDCService :public IFileIO
{
public:
EDCService()
{
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
STDMETHOD(GetFile);
STDMETHOD(GetDirectory);
}
Hi friends ...
STDMETHOD(GetFile);
STDMETHOD(GetDirectory); these two methods definitions are written main.cpp
i doing so many try's to solve this prob..first i create instance of EDCService.like
EDCService edcobj;
then i create instance of EDCService like
edcobj.CreateInstance(); but showing..
When i compile this code i get the follwing errors i dont know how was solve it
error C2039: 'CreateInstance' : is not a member of 'EDCService'
error C2259: 'EDCService' : cannot instantiate abstract class
Please tell me how to solve this problem ..
|
|
|
|
|
Sakthi_Vel wrote: then i create instance of EDCService like
edcobj.CreateInstance(); but showing..
When i compile this code i get the follwing errors i dont know how was solve it
error C2039: 'CreateInstance' : is not a member of 'EDCService'
You aren't supposed to create an instance that way. If you are inside your program, you could use CComObject<edcservice>::CreateInstance. To create it from a client, you would normally assign a class ID to EDCService and the use CoCreateInstance.
Sakthi_Vel wrote: error C2259: 'EDCService' : cannot instantiate abstract class
IDispatch has four pure virtual methods that you can implement by deriving EDCService from IDispatchImpl. IDispatch derives from IUnknown which has three more methods, which are implemented in CComObject. Also you need an interface map for EDCService so that CComObject::QueryInterface can work correctly.
Sakthi_Vel wrote: //Main.h
__interface IFileIO : IDispatch
{
[id(1), helpstring("method GetFile")] HRESULT GetFile();
[id(2), helpstring("method getDirectory")] HRESULT GetDirectory();
};
This looks like attributed ATL. You really don't want to use it. Attribute support for standard C++ is much weaker than for .net, and I've found that (at least with VS2003) that it has an extreme problem with interface dependancies, because the generated .idl file neither forward declares types, nor attempts to put them in an order which wouldn't need it. To do anything significant with ATL, you'll need to learn IDL.
Nathan
|
|
|
|
|
I don't know where to report this bug, so may be this is the right place...
If you set an IDocHostUIHandlerDispatch -interface the FilterDataObject -Method of CAxHostWindow does NOT query the IDataObject -interface from the returned IUnknown , instead it calls QueryInterface on it self:
if (m_spIDocHostUIHandlerDispatch != NULL)
{
CComPtr<iunknown> spUnk;
hr = m_spIDocHostUIHandlerDispatch->FilterDataObject(pDO, &spUnk);
if (spUnk)
hr = QueryInterface(__uuidof(IDataObject), (void**)ppDORet);
if (FAILED(hr) || *ppDORet == NULL)
hr = S_FALSE;
}
</iunknown>
So the line
hr = QueryInterface(__uuidof(IDataObject), (void**)ppDORet);
should be more like:
hr = spUnk->QueryInterface(__uuidof(IDataObject), (void**)ppDORet);
Does anyone know where to report this bug?
Greetings,
imagiro
|
|
|
|
|
|
Thanks Mike. Looks like reporting bugs is sometimes harder than finding them
|
|
|
|
|
Hi All,
I have developed the project in ATL in which I am getting events from the browser window through Invoke() function of the IDispatch interface.
And my question is that I want to get Mouse Click event with the element id on which event has been fired.How can I do that?
I tried below code to do the same but I m not getting success.
<br />
<br />
STDMETHODIMP CSimpleTab::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,<br />
DISPPARAMS* pDispParams, VARIANT* pVarResult,<br />
EXCEPINFO* pExcepInfo, UINT* puArgErr)<br />
{<br />
switch (dispIdMember)<br />
{<br />
case DISPID_HTMLELEMENTEVENTS2_ONMOUSEDOWN:<br />
{<br />
CComVariant dis_event;<br />
dis_event = (CSimpleTab *)(this);<br />
<br />
IDispatch *lpDispatch = pVarResult->pdispVal;<br />
IHTMLEventObj * eventObj;<br />
HRESULT hr = lpDispatch->QueryInterface(IID_IHTMLEventObj,(void **)&eventObj);<br />
<br />
IHTMLElement * element;<br />
eventObj->get_srcElement(&element);<br />
}<br />
}<br />
}<br />
in above code I m getting null in to the pVarResult->pdispVal parameter.
Do you have any idea why does this happen?
Thanks in Advance.
Ashish Bhatt,
Indianic,Ahmedabad.
|
|
|
|
|
I am new to ATL. How to display a message box in ATL projects?
|
|
|
|
|
Sakthi_Vel wrote: I am new to ATL. How to display a message box in ATL projects?
::MessageBox(NULL,_T(""),_T(""),MB_OK); same like any win32 project
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
|
Another WinApi wrapper function AtlMessageBox
|
|
|
|
|
Thanks to all.
Indeed more than i need
|
|
|
|
|
|
How to declare/handle strings in ATL?
|
|
|
|
|
Simple As you do in C++
char szBuffer[100];
Or
TCHAR szBuffer[100];
|
|
|
|
|
Sakthi_Vel wrote: How to declare/handle strings in ATL?
include atlstr.h , it provide you CString class!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
|
Sakthi_Vel wrote: Thanks.
my pleasure
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Another option is to use ATL's CComBSTR[^] class.
|
|
|
|
|
Nemanja Trifunovic wrote: Another option is to use ATL's CComBSTR[^] class.
yeap you are right but, i will prefer _bstr_t
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
"If it were machines, the pair_programming seem to work, but for humans it is pair_crackdown that seems to work! " - Nisamudheen
Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
If I use WTL::CHyperLink of HLINK_UNDERLINEHOVER style and handle the WM_CTLCOLORSTATIC message at the parent dialog, underlined text font is not reset to not underlined when the cursor is removed from the control. Does anyone know how this can be fixed?
|
|
|
|
|
Dear friend,
I am new in ATL world. I want to implement IEnumString in ATL 3.0. I searched in google, but did not get appropriate example. Can anybody help me and give some example.
|
|
|
|