Click here to Skip to main content
15,920,468 members
Home / Discussions / COM
   

COM

 
GeneralRe: Timer with Windowless Control Pin
Jörgen Sigvardsson26-Jun-05 6:04
Jörgen Sigvardsson26-Jun-05 6:04 
GeneralRe: Timer with Windowless Control Pin
Shraddhan26-Jun-05 12:57
Shraddhan26-Jun-05 12:57 
GeneralRe: Timer with Windowless Control Pin
Jörgen Sigvardsson27-Jun-05 10:18
Jörgen Sigvardsson27-Jun-05 10:18 
Generalchar** to VARIANT Pin
bvais23-Jun-05 11:01
sussbvais23-Jun-05 11:01 
GeneralRe: char** to VARIANT Pin
Lim Bio Liong23-Jun-05 15:12
Lim Bio Liong23-Jun-05 15:12 
GeneralRe: char** to VARIANT Pin
bvais23-Jun-05 18:23
sussbvais23-Jun-05 18:23 
GeneralRe: char** to VARIANT Pin
GuimaSun24-Jun-05 9:26
GuimaSun24-Jun-05 9:26 
GeneralRe: char** to VARIANT Pin
Lim Bio Liong24-Jun-05 23:54
Lim Bio Liong24-Jun-05 23:54 
Hello bvais,

Yes, as mentioned by GuimaSun (in an earlier reply), the way to do this is to use a SAFEARRAY of BSTRs.

I have a sample function below that can help you to achieve this :

// CreateSafeArrayFromBSTRArray()
// This function will create a SafeArray of BSTRs using the BSTR elements
// found inside
// the first parameter "pBSTRArray".
//
// Note well that the output SafeArray will contain COPIES of the original
// BSTRs
// inside the input parameter "pBSTRArray".
//
long CreateSafeArrayFromBSTRArray
(
BSTR* pBSTRArray,
ULONG ulArraySize,
SAFEARRAY** ppSafeArrayReceiver
)
{
HRESULT hrRetTemp = S_OK;
SAFEARRAY* pSAFEARRAYRet = NULL;
SAFEARRAYBOUND rgsabound[1];
ULONG ulIndex = 0;
long lRet = 0;

// Initialise receiver.
if (ppSafeArrayReceiver)
{
*ppSafeArrayReceiver = NULL;
}

if (pBSTRArray)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = ulArraySize;

pSAFEARRAYRet = (SAFEARRAY*)SafeArrayCreate
(
(VARTYPE)VT_BSTR,
(unsigned int)1,
(SAFEARRAYBOUND*)rgsabound
);
}

for (ulIndex = 0; ulIndex < ulArraySize; ulIndex++)
{
long lIndexVector[1];

lIndexVector[0] = ulIndex;

// Since pSAFEARRAYRet is created as a SafeArray of VT_BSTR,
// SafeArrayPutElement() will create a copy of each BSTR
// inserted into the SafeArray.
SafeArrayPutElement
(
(SAFEARRAY*)pSAFEARRAYRet,
(long*)lIndexVector,
(void*)(pBSTRArray[ulIndex])
);
}

if (pSAFEARRAYRet)
{
*ppSafeArrayReceiver = pSAFEARRAYRet;
}

return lRet;
}

Then, you can use the above function in your code as demonstrated below :

#include <comdef.h>

int main()
{
// Define an array of BSTRs which are initialized via _bstr_t.
BSTR bstrArray[] =
{
_bstr_t(L"BSTR 01").copy(),
_bstr_t(L"BSTR 02").copy(),
_bstr_t(L"BSTR 03").copy(),
_bstr_t(L"BSTR 04").copy(),
_bstr_t(L"BSTR 05").copy()
};
SAFEARRAY* pSAFEARRAY = NULL;

// Create a Safe Array of BSTRs which are copies of the elements
// of bstrArray.
CreateSafeArrayFromBSTRArray
(
bstrArray,
sizeof(bstrArray)/sizeof(BSTR),
&pSAFEARRAY
);

// Destroy the safe array object pSAFEARRAY.
// SafeArrayDestroy() will also destroy the
// BSTRs created via CreateSafeArrayFromBSTRArray().
// pSAFEARRAY.
SafeArrayDestroy(pSAFEARRAY);
pSAFEARRAY = NULL;

return 0;
}

Best Regards,
Bio.



GeneralRe: char** to VARIANT Pin
Jörgen Sigvardsson25-Jun-05 13:44
Jörgen Sigvardsson25-Jun-05 13:44 
GeneralRe: char** to VARIANT Pin
Lim Bio Liong25-Jun-05 19:39
Lim Bio Liong25-Jun-05 19:39 
GeneralVARIANT in VC 6.0 and Objects in C# Pin
btanveer23-Jun-05 6:09
btanveer23-Jun-05 6:09 
QuestionHow I can debug a dll file Pin
Anonymous22-Jun-05 23:37
Anonymous22-Jun-05 23:37 
AnswerRe: How I can debug a dll file Pin
ameysp23-Jun-05 23:56
ameysp23-Jun-05 23:56 
Generalcreating instance of an object Pin
pardis21-Jun-05 21:22
pardis21-Jun-05 21:22 
GeneralObtaining currently active IE window using IShellWindows Pin
VV114420-Jun-05 11:15
VV114420-Jun-05 11:15 
GeneralRe: Obtaining currently active IE window using IShellWindows Pin
GuimaSun23-Jun-05 10:30
GuimaSun23-Jun-05 10:30 
Generalsending data to dialog Pin
pardis17-Jun-05 20:19
pardis17-Jun-05 20:19 
GeneralRe: sending data to dialog Pin
GuimaSun23-Jun-05 10:02
GuimaSun23-Jun-05 10:02 
GeneralUsing FoxPro COM in Asp.Net Pin
BCKY17-Jun-05 13:41
BCKY17-Jun-05 13:41 
Generalget IE caret position (x,y) Pin
17-Jun-05 4:58
suss17-Jun-05 4:58 
GeneralAccess Violation in Release of COM+ object in Release Version Pin
ameysp16-Jun-05 20:01
ameysp16-Jun-05 20:01 
GeneralRe: Access Violation in Release of COM+ object in Release Version Pin
GuimaSun23-Jun-05 9:53
GuimaSun23-Jun-05 9:53 
GeneralRe: Access Violation in Release of COM+ object in Release Version Pin
ameysp23-Jun-05 23:27
ameysp23-Jun-05 23:27 
GeneralAdd RTP filter Pin
mausot16-Jun-05 0:43
mausot16-Jun-05 0:43 
GeneralHelp with IDropTarget Interface really needed Pin
Jim Parsells15-Jun-05 17:29
Jim Parsells15-Jun-05 17:29 

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.