I have two questions which are very similar:
Is it possible to return an object in C++. Below is part of my code
for reference however I am more concerned about the concept. It seems
like the function below is returning a pointer to pointers who are
GUID. I am trying to write a wrapper to use in my VB code and what I
would prefer to do is be able to return an array of GUID. I remember
(not sure) that the concept of arrays does not really exist in c++ and
they are all pointers however, i do not want to pass a pointer to the
global IdsOfJobs i would like to pass the array itself. So is it
possible to return an array of objects. I would like to be able to
change the function definition to
GUID** AdminBits::GetJobIDs(int UserSelection, int& NumberOfJobs).
Thank you for your time. Also my second question is in regards to
creating COM+ components using VC++. Is there any easy to follow
tutorial? I have my classes written and working as a WIN32 Console
application. Having difficulties when I try to Create an instance of
the DLL object from VB.
Thanks a bunch.
Gent
Code below for reference
-------------------------------------------------
-------------------------------------------------
Declared inside the class AdminBits
Class AdminBits {
.....
IBackgroundCopyManager* g_XferManager;
HRESULT hr;
GUID** IdsOfJobs;
.....
};
GUID** AdminBits::GetJobIDs(int UserSelection, int& NumberOfJobs)
{
// GUID *tempIDs;
// GUID tempIDs[100];
GUID temp;
int i = 0;
// If passed in 1 than enumerates jobs for all users
// If passed in 0 than it enumerates job for current user logged on.
IEnumBackgroundCopyJobs* pJobs = NULL;
IBackgroundCopyJob* pJob = NULL;
ULONG cJobCount = 0;
ULONG idx = 0;
//Specify the appropriate COM threading model for your application.
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr))
{
//The impersonation level must be at least
RPC_C_IMP_LEVEL_IMPERSONATE.
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(__uuidof(BackgroundCopyManager), NULL,
CLSCTX_LOCAL_SERVER,
__uuidof(IBackgroundCopyManager),
(void**) &g_XferManager);
//Enumerate jobs in the queue. This example enumerates all jobs in
the transfer
//queue. This call fails if the current user does not have
administrator
//privileges. To enumerate jobs for only the current user, replace
//BG_JOB_ENUM_ALL_USERS with 0.
if(UserSelection == 1)
{
hr = g_XferManager->EnumJobs(BG_JOB_ENUM_ALL_USERS, &pJobs);
}
else
{
hr = g_XferManager->EnumJobs(0, &pJobs);
}
if (SUCCEEDED(hr))
{
//Get the count of jobs in the queue.
pJobs->GetCount(&cJobCount);
// IdsOfJobs= new GUID*[cJobCount+1];
NumberOfJobs = cJobCount;
//Enumerate the jobs in the queue.
for (idx=0; idx<cJobCount; idx++)
{
hr = pJobs->Next(1, &pJob, NULL);
if (S_OK == hr)
{
pJob->GetId(&temp);
IdsOfJobs[i] = &temp;
// tempIDs[i] = temp;
i++;
//Retrieve or set job properties.
pJob->Release();
pJob = NULL;
}
else
{
//Handle error
break;
}
}
}
}
}
if (g_XferManager)
{
g_XferManager->Release();
g_XferManager = NULL;
}
CoUninitialize();
return IdsOfJobs;
}