This blog is only to remind myself of what I've learned (from others or by myself) and only for knowledge sharing. External sources will be clearly stated in [Reference] of each article. I hope this blog won't infringe any copyrights and that it can be useful for interested blog readers.

2008年4月15日 星期二

COM related info

 

(1) CodeGuru: Step by Step COM Tutorial

(2) Passing parameters in COM's method

String -- Use BSTR

  (a) How to convert BSTR to WCHAR

    Case I :
      WCHAR *wszTemp = NULL;
      BSTR b_Temp = NULL;
      b_Temp = SysAllocString(L"Convert");
     wszTemp = b_Temp;


    Case II :
      WCHAR wszTemp[10];
      BSTR b_Temp = NULL;
      memset((void*)wszTemp,'\0',sizeof(wszTemp));
      b_Temp = SysAllocString(L"Convert");
      wcscpy(wszTemp,b_Temp);

  (b) How to convert BSTR to LPCTSTR

  -- convert BSTR to WCHAR *

  -- Use wcstombs()

  

Structure -- pointer to structure

!!NOTE:

1) every member variable of a structure had better be 4-byte aligned.

2) there should not be any pointers to any type. It's better to assign necessary memory size in advance.

For example:

typedef struct
{
    unsigned int xProgramId;
    TPslContext  pslContext; // 4-byte aligned structure
    unsigned int networkId; 
    unsigned int platformId; 
    unsigned int uriLength;
    unsigned char ESGProviderURI[128];
}Dvbh_Fun_PSL_Add_Args;

Class -- pointer to class or class reference

Memory buffer -- use "structure" with allocated buffer inside

 

etc.

(3) callback in COM

-- COM Server (DLL) -- refer here

-- COM Server (Service EXE) -- refer here

沒有留言: