EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of COM/DCOM Questions #Next question

Fixed size array

C/C++ functions can pass array as pointer. There should be some common logic between client and server to access the elements based.

Either it would be a constant size array or the length is provided by Client to be used by server. Server should set the array size for Output or return variables and client should access based on that.

size_is() in IDL

DCOM client and servers are not in same process space. So it is very necessary to know the size of the array. Array of a known size is always handled with an extra variable and array size is calculated with size_is(size variable).

Client allocates the required length of buffer and sets the size variable. Marshalling process copies the size of the array to LPC buffer or network buffer based on the length given in size_is(variable).

size_is() interface example

Here is one example of fixed array returned by server.

[
  object,
  uuid(014EA17F-66F0-43A9-AC45-5796F0113291),
  dual,
  helpstring("IDaysArray Interface"),
  pointer_default(unique)
]
interface IDaysArray : IDispatch
{
  [id(1), helpstring("method GetDaysString")]
  HRESULT GetDaysString([in] long cDays, [out, size_is(cDays)] BSTR * pDays);
};

BSTR fixed array server

STDMETHODIMP CDaysArray::GetDaysString(long cDays, BSTR *pDays)
{
  unsigned short *days[7] = {
    L"Monday",
    L"Tuesday",
    L"Wednesday",
    L"Thursday",
    L"Friday",
    L"Saturday",
    L"Sunday"
  };
  long nLbound;
  BSTR strDay;
  if ((cDays <= 0) || (cDays > 7))
  {
    return E_INVALIDARG;
  }
  for(nLbound = 0; nLbound < cDays; nLbound++) {
    strDay = SysAllocString(days[nLbound]);
    pDays[nLbound] = strDay;
  }
  return S_OK;
}

BSTR fixed array client

#import "CWeekDaysEnumXXX.dll"

int main(int argc, char* argv[])
{
  HRESULT hr;
  BSTR Days[7];
  CWEEKDAYSENUMXXXLib::IDaysArrayPtr  DaysArrayPtr;
  CoInitialize(NULL);
  hr =DaysArrayPtr.CreateInstance("CWeekDaysEnumXXX.DaysArray");
  if(hr != S_OK)
  {
    wprintf(L"CreateInstance(\"CWeekDaysEnumXXX.DaysArray\") error %x\n",hr);
    CoUninitialize();
    return hr;
  }
  hr = DaysArrayPtr->GetDaysString(7, Days);
  if(hr == S_OK)
  {
    for (int i = 0; i < 7; i++)
    {
      wprintf(L"Day %d : %s \n", (i + 1), Days[i]);
      SysFreeString(Days[i]);
    }
  } else {
    wprintf(L"GetDaysString error %x\n",hr);
  }
  DaysArrayPtr.Release();
  CoUninitialize();
  return 0;
}

BSTR fixed array output

Day 1 : Monday
Day 2 : Tuesday
Day 3 : Wednesday
Day 4 : Thursday
Day 5 : Friday
Day 6 : Saturday
Day 7 : Sunday

You have viewed 1 page out of 66. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

# COM DCOM Interview Questions and Answers :: ALL Interview .com
# COM DCOM - COM DCOM Interview Questions
# COM interview questions | TechInterviews
# COM Interview Questions - CodeProject
# Com Dcom Interview Questions - Com and Dcom in Asp Net
# ATL Interview Questions and Answers :: ALL Interview .com
# ActiveX Interview Questions and Answers :: ALL Interview .com

* #1 webmaster Mon 28 Apr/2014 01:08:08(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.