problem with parameter 2 of GetIDsOfNames 
Author Message
 problem with parameter 2 of GetIDsOfNames

I am a little confused with my pointers.
The following code has a run time fatal
error. If I comment out the function call,
then the message box does not display
"Next" as expected. Can someone fix my
code?
TIA

DISPID dispid;
TCHAR  szMember[5] ;
lstrcpy( szMember,TEXT("Next"));
HRESULT     hr;

/*hr = spDispatch->GetIDsOfNames(
IID_NULL,
(unsigned short **)&szMember, // is this casting correct?
1,
 LOCALE_SYSTEM_DEFAULT,
&dispid);*/

MessageBox(szMember,TEXT(""),0);



Sun, 09 Feb 2003 10:31:55 GMT  
 problem with parameter 2 of GetIDsOfNames

The GetIDsOfNames method expects a OLECHAR** (i.e. unsigned short**)
argument. You are using TCHAR when you declare szMember.
Unless you are building for UNICODE it will translate into char (1 byte)
and not unsigned short (2 byte), and casting a char** to unsigned short**
is a very bad idea

Declare szMember as OLECHAR instead and use lstrcpyW to fill it
(Or even better, do it like this: OLECHAR* szMember = L"Next";)
Then remove your cast. It is not needed.

There is a good example in the documentation for GetIDsOfNames.

HTH

  /Claes

Quote:

> I am a little confused with my pointers.
> The following code has a run time fatal
> error. If I comment out the function call,
> then the message box does not display
> "Next" as expected. Can someone fix my
> code?
> TIA

> DISPID dispid;
> TCHAR  szMember[5] ;
> lstrcpy( szMember,TEXT("Next"));
> HRESULT     hr;

> /*hr = spDispatch->GetIDsOfNames(
> IID_NULL,
> (unsigned short **)&szMember, // is this casting correct?
> 1,
>  LOCALE_SYSTEM_DEFAULT,
> &dispid);*/

> MessageBox(szMember,TEXT(""),0);



Sun, 09 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. GetIDsOfNames help

2. GetActiveObject / GetIDsOfNames returns E_NOIMPL

3. DISP_E_UNKNOWNNAME from GetIDsOfNames

4. IDispatch::GetIDsOfNames (newbie)

5. DISP_E_UNKNOWNNAME from GetIDsOfNames

6. DISP_E_UNKNOWNNAME from GetIDsOfNames

7. IDispatch::GetIDsOfNames (newbie)

8. Question on GetIDsOfNames

9. Use of GetIDsOfNames for methods

10. ActiveX Collections, Containers, GetIdsOfNames, LPDISPATCH

11. GetIDsOfNames Halts

12. VC7 does NOT support template-template parameters involving non-type parameters

 

 
Powered by phpBB® Forum Software