Using VB Ole Server methods from VC
Shilpa Vyapari -- shini@highway.or.jp
Sunday, March 30, 1997
Environment: VC++ 4.0, Windows 95
I have a VB OLE Server object which is to be invoked both from VB as
well as VC. With VB applization it works fine. But when I try to call a
method of that object from VC, it fails. I can't get the dispid. I use
following function to convert name to dispid.
DISPID CLayoutView::NameToID( COleDispatchDriver &pDisp, TCHAR *pszName
)
{
DISPID dispid = 0;
HRESULT hr;
TCHAR szMsg[80];
hr = pDisp.m_lpDispatch->GetIDsOfNames( IID_NULL, (OLECHAR FAR*
FAR*)&pszName, 1,
m_lcid, &dispid );
if ( FAILED( hr ) )
{
wsprintf( szMsg,TEXT( "GetIDsOfNames on '%s' failed with 0x%lX"
), pszName, hr );
AfxMessageBox( szMsg );
}
return dispid;
}
and call it through COleDispatchDriver interface :
COleDispatchDriver dispDriver;
dispDriver.CreateDispatch( "OLEServer.Screen2" );
DISPID dispID = NameToID( dispDriver, "Display" ); // always falis and
displays error box
if ( dispID != -1 )
{
int iret;
dispDriver.InvokeHelper( dispID, DISPATCH_METHOD, VT_BOOL, &iret,
NULL, NULL );
}
Can anyone figure out what's going wrong?
- Shilpa
---------------------------------
Shilpa Vyapari
Phone/Fax : 81 (0)3-3745-0040
mailto:shini@highway.or.jp
---------------------------------
Alberto Massari -- alby@belva.infomus.dist.unige.it
Tuesday, April 01, 1997
At 07:06 PM 30/3/97 +0900, you wrote:
>Environment: VC++ 4.0, Windows 95
>
>I have a VB OLE Server object which is to be invoked both from VB as
>well as VC. With VB applization it works fine. But when I try to call a
>method of that object from VC, it fails. I can't get the dispid. I use
>following function to convert name to dispid.
>
>DISPID CLayoutView::NameToID( COleDispatchDriver &pDisp, TCHAR *pszName
>)
>{
> DISPID dispid = 0;
> HRESULT hr;
> TCHAR szMsg[80];
>
> hr = pDisp.m_lpDispatch->GetIDsOfNames( IID_NULL, (OLECHAR FAR*
>FAR*)&pszName, 1,
> m_lcid, &dispid );
>
> if ( FAILED( hr ) )
> {
> wsprintf( szMsg,TEXT( "GetIDsOfNames on '%s' failed with 0x%lX"
>), pszName, hr );
> AfxMessageBox( szMsg );
> }
> return dispid;
>}
>
>and call it through COleDispatchDriver interface :
>
> COleDispatchDriver dispDriver;
>
> dispDriver.CreateDispatch( "OLEServer.Screen2" );
>
> DISPID dispID = NameToID( dispDriver, "Display" ); // always falis and
>displays error box
>
> if ( dispID != -1 )
> {
> int iret;
> dispDriver.InvokeHelper( dispID, DISPATCH_METHOD, VT_BOOL, &iret,
> NULL, NULL );
> }
>
>
>Can anyone figure out what's going wrong?
Last year I wrote a piece of code like your, and it worked.
One week ago I recompiled it, and I found that GetIDsOfNames failed in
looking for an exported method.
I found out that GetIDsOfNames wants OLECHAR, and the only way to make it
works is:
#include
DISPID CLayoutView::NameToID( COleDispatchDriver &pDisp, const char*pszName)
{
>>>>>>>>>>>>>>>>>>>>>>>>>>>> begin modified
USES_CONVERSION;
>>>>>>>>>>>>>>>>>>>>>>>>>>>> end modified
DISPID dispid = 0;
HRESULT hr;
TCHAR szMsg[80];
>>>>>>>>>>>>>>>>>>>>>>>>>>>> begin modified
OLECHAR* unicodeName=T2OLE(pszName);
hr = pDisp.m_lpDispatch->GetIDsOfNames( IID_NULL, &unnicodeName, 1,
m_lcid, &dispid );
>>>>>>>>>>>>>>>>>>>>>>>>>>>> end modified
if ( FAILED( hr ) )
{
wsprintf( szMsg,TEXT( "GetIDsOfNames on '%s' failed with 0x%lX"),
pszName, hr );
AfxMessageBox( szMsg );
}
return dispid;
}
Ciao,
Alberto
----------------------------
|\ _,,,--,,_
/,`.-'`' ._ \-;;,_
|,4- ) )_ .;.( `'-'
'---''(_/._)-'(_\_)
------------------------------------------------------------------
alby@musart.dist.unige.it is: Alberto Massari
Universita' di Genova
Facolta' di Ingegneria Elettronica
Laboratorio di Informatica Musicale
Viale F. Causa 13
I-16100 Genova, Italia http://musart.dist.unige.it/alby
------------------------------------------------------------------
Become an MFC-L member
| Вернуться в корень Архива
|