Click here to Skip to main content
16,008,469 members
Home / Discussions / COM
   

COM

 
GeneralProblem with CComEnum Pin
Sunny_leung19-Mar-02 12:50
Sunny_leung19-Mar-02 12:50 
GeneralProblem with CComEnum Pin
Sunny_leung19-Mar-02 12:53
Sunny_leung19-Mar-02 12:53 
QuestionWhy does it do that? Pin
#realJSOP19-Mar-02 7:43
professional#realJSOP19-Mar-02 7:43 
AnswerRe: Why does it do that? Pin
Carlos Antollini19-Mar-02 8:13
Carlos Antollini19-Mar-02 8:13 
GeneralRe: Why does it do that? Pin
#realJSOP19-Mar-02 8:48
professional#realJSOP19-Mar-02 8:48 
AnswerRe: Why does it do that? Pin
David Salter19-Mar-02 10:56
David Salter19-Mar-02 10:56 
GeneralRe: Why does it do that? Pin
Sunny_leung19-Mar-02 12:49
Sunny_leung19-Mar-02 12:49 
GeneralTrying to get an element from SAFEARRAY Pin
Sunny_leung18-Mar-02 14:07
Sunny_leung18-Mar-02 14:07 
Hi,

I have stumbled across a problem again, and this time, it is on retrieving an element from a SAFEARRAY. The following code shows what I am trying to achieve:

// Creates a user
IUser* pUser4 = NULL;
CoCreateInstance( __uuidof( User ), NULL, CLSCTX_INPROC_SERVER,
IID_IUser, (void**)&pUser4 );

// Store my first name into it
pUser4->put_FirstName( L"Sunny" );

// Creates a variant that contains an array of type IUnknown pointers
_variant_t* userArray = new _variant_t;
userArray->vt = VT_ARRAY | VT_UNKNOWN;

// Create the array
SAFEARRAY* pSA;
SAFEARRAYBOUND bounds = { 1, 0 };
pSA = SafeArrayCreate( VT_UNKNOWN, 1, &bounds );

// Turn my pUser4 pointer into the IUnknown pointer
IUnknown* pUnk = NULL;
pUser4->QueryInterface( IID_IUnknown, (void**)&pUnk );

// put the IUnknown pointer into the array, and store the array
// into the variant
long a = 0;
SafeArrayPutElement( pSA, &a, pUnk );
userArray->parray = pSA;

// Retrieve the element
SAFEARRAY* ans = userArray->parray;
IUnknown* pUnk2 = NULL;
SafeArrayGetElement( ans, &a, pUnk2 ); // problem occurs
IUser* pUser5 = NULL;
pUnk2->QueryInterface( IID_IUser, (void**)&pUser5 );

BSTR first;
pUser5->get_FirstName( &first );

//======================== END

The problem arises when I tried to get the IUnknown pointer from the array by calling SafeArrayGetElement. I looked at the debugger, and it showed that the address of pUnk2 is 0x00000000.

I am wondering if anybody known what I have done wrong?
Help is apprepriated Smile | :)

Sunny
GeneralRe: Trying to get an element from SAFEARRAY Pin
Mazdak18-Mar-02 20:58
Mazdak18-Mar-02 20:58 
GeneralIn-place activation of Excel Pin
18-Mar-02 2:17
suss18-Mar-02 2:17 
GeneralActiveX instanciation in VB Pin
Jerome Conus18-Mar-02 0:40
Jerome Conus18-Mar-02 0:40 
GeneralRe: ActiveX instanciation in VB Pin
Joao Vaz18-Mar-02 1:16
Joao Vaz18-Mar-02 1:16 
GeneralSTG_E_MEDIUMFULL When Saving an Image to Stream Pin
Serge Baltic17-Mar-02 23:26
Serge Baltic17-Mar-02 23:26 
QuestionCan I control the IE browser by using a COM? Pin
wabc17-Mar-02 18:47
wabc17-Mar-02 18:47 
AnswerRe: Can I control the IE browser by using a COM? Pin
pba_18-Mar-02 4:17
pba_18-Mar-02 4:17 
AnswerRe: Can I control the IE browser by using a COM? Pin
David Salter19-Mar-02 10:53
David Salter19-Mar-02 10:53 
GeneralRe: Can I control the IE browser by using a COM? Pin
wabc19-Mar-02 15:10
wabc19-Mar-02 15:10 
GeneralRe: Can I control the IE browser by using a COM? Pin
David Salter20-Mar-02 2:40
David Salter20-Mar-02 2:40 
GeneralNetmeeting Pin
17-Mar-02 8:28
suss17-Mar-02 8:28 
GeneralRe: Netmeeting Pin
pba_18-Mar-02 4:13
pba_18-Mar-02 4:13 
GeneralPreview Outlook Exress style Pin
16-Mar-02 23:45
suss16-Mar-02 23:45 
GeneralRe: Preview Outlook Exress style Pin
Serge Baltic20-Mar-02 0:48
Serge Baltic20-Mar-02 0:48 
GeneralMultiple import Pin
Sunny_leung16-Mar-02 9:07
Sunny_leung16-Mar-02 9:07 
GeneralRe: Multiple import Pin
Joao Vaz18-Mar-02 0:51
Joao Vaz18-Mar-02 0:51 
GeneralActiveX Pin
Leesen16-Mar-02 3:43
Leesen16-Mar-02 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.