15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Passing variable length in OLE Automation.

K.Parthipan@blr.sni.de
Sunday, December 22, 1996

Hello

	Environment : VC++ 4.0, Win NT 3.51


	I want communication between two OCX controls through OLE automation. I
coule implement everything except that I want to pass variable length
data between them. The data is a list of names. And no. of names in list
I do not know. Is is possilble to communicate through IUnknown
interface. What I would like to do is in one of the methods I will have
IUnknown interface and when that function is being called I will pass
IDataObject datamember which has list of my names in global data. In the
receiving end I will type cast IUnknown to IDataObject and will retrieve
data. Is it possible to do that. 

	Or is there any other way can two OCX controls can communicate with
each other.


Parthipan Kanakasabhapathi



Mike Blaszczak -- mikeblas@nwlink.com
Sunday, December 22, 1996

[Mini-digest: 2 responses]

At 14:55 12/22/96 +0530, K.Parthipan@blr.sni.de wrote:
>	Environment : VC++ 4.0, Win NT 3.51

>I want communication between two OCX controls through OLE automation. I
>coule implement everything except that I want to pass variable length
>data between them. The data is a list of names. And no. of names in list
>I do not know. Is is possilble to communicate through IUnknown
>interface.

You could use a safe array of BSTRs.  MFC provides _some_ help for this
in the COleSafeArray class.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.

-----From: steve.rogers@octel.com

  If the OCX controls are part of an OCX set that work together 
  then they can have a common DLL. A DLL can share data between 
  processes in various ways (which are well documented and have 
  been mentioned in the past in this group). 
  
  Steve Rogers
______________________________ Reply Separator _________________________________
Subject: Passing variable length in OLE Automation.
Author:  mfc-l@netcom.com at P_Internet_Mail
Date:    12/22/96 2:55 PM


Hello
  
        Environment : VC++ 4.0, Win NT 3.51
  
  
        I want communication between two OCX controls through OLE automation. I
coule implement everything except that I want to pass variable length 
data between them. The data is a list of names. And no. of names in list 
I do not know. Is is possilble to communicate through IUnknown 
interface. What I would like to do is in one of the methods I will have 
IUnknown interface and when that function is being called I will pass 
IDataObject datamember which has list of my names in global data. In the 
receiving end I will type cast IUnknown to IDataObject and will retrieve 
data. Is it possible to do that. 
  
        Or is there any other way can two OCX controls can communicate with
each other.
  
  
Parthipan Kanakasabhapathi



Scott Colestock -- scolestock@wavefront.com
Wednesday, January 01, 1997

At 14:55 12/22/96 +0530, K.Parthipan@blr.sni.de wrote:
>	Environment : VC++ 4.0, Win NT 3.51
> 
> >I want communication between two OCX controls through OLE automation. I
> >coule implement everything except that I want to pass variable length
> >data between them. The data is a list of names. And no. of names in list
> >I do not know. Is is possilble to communicate through IUnknown
> >interface.
> 
> You could use a safe array of BSTRs.  MFC provides _some_ help for this
> in the COleSafeArray class.
>.B ekiM
>http://www.nwlink.com/~mikeblas/
 

If you are looking for additional help in using safe arrays, you might want
to check out www.vcdj.com.  I wrote an article for their November issue (of
Visual C++ Developer's Journal) that describes a class derived from CArray
that facilitates working with safe arrays.  Without going into too much
detail, the class does the "efficient" thing for intrinsic types, and the
"right" thing for LPDISPATCH, LPUNKNOWN, and BSTRs.  Because it knows what
data type you are working with (based on the template argument) it can do a
lot for you "automatically" -- so it's a pretty useful & fun class. 

Using the class (COleSmartArray) in the context of a simple automation
method that sorts an array of doubles and returns the sorted array (i.e. it
doesn't sort it in place) would look like this:

VARIANT CMyServer::SortArray(const VARIANT FAR& ArrayToSort) 
{
   VARIANT vaResult;
   VariantInit(&vaResult);

   COleSmartArray arToSort;

   // Copy OLE safearray in VARIANT to our array.
   // A dispatch exception is thrown if ArrayToSort 
   // doesn't contain the expected type,
   // although we're not watching for that case here.
   arToSort.FillArrayWithVariant(ArrayToSort);
   
   // Call a sorting routine.  
   ::SortCArray(arToSort);

   // Move our array back into VARIANT.
   // vaResult is set up for us (creation of safe array
   // of proper type, etc.) by the COleSmartArray::
   // FillVariantWithArray method.
   arToSort.FillVariantWithArray(&vaResult);

   return vaResult;
}

(The class also supports changing arrays in place.)

- Scott Colestock
(scolestock@usa.net)




Scott Daniels -- scottdfl@sprynet.com
Tuesday, January 14, 1997

Hi,

There is another way that may be simpler. I have a situation in which I
must pass a lot of data and the IDispatch mechanism is too slow. Here is
what I do. I create a BSTR and put my data in binary format into it and
pass it off as a normal string. The recieving control must then extract the
data. It works very well and is quite simple to implement. Best of all, it
is very fast.

Here is the code for the control sending the data:

BSTR MyDoc::GetData() 
{
	// create some block of memory pointed to by "data"
	BSTR bstr = SysAllocStringByteLen(data, dataSize);
	return bstr;
}


Scott

----------
> From: K.Parthipan@blr.sni.de
> To: mfc-l@netcom.com
> Subject: Passing variable length in OLE Automation.
> Date: Sunday, December 22, 1996 4:25 AM
> 
> Hello
> 
> 	Environment : VC++ 4.0, Win NT 3.51
> 
> 
> 	I want communication between two OCX controls through OLE automation. I
> coule implement everything except that I want to pass variable length
> data between them. The data is a list of names. And no. of names in list
> I do not know. Is is possilble to communicate through IUnknown
> interface. What I would like to do is in one of the methods I will have
> IUnknown interface and when that function is being called I will pass
> IDataObject datamember which has list of my names in global data. In the
> receiving end I will type cast IUnknown to IDataObject and will retrieve
> data. Is it possible to do that. 
> 
> 	Or is there any other way can two OCX controls can communicate with
> each other.
> 
> 
> Parthipan Kanakasabhapathi



kvasilak@cyberoptics.com
Friday, January 17, 1997

Sorry this reply took so long I just saw a response but I dont remember seeing 
the origional message.

We do this all the time, passing variable length images around, currently we use
VARIANTS in which you can store just about anything even arrays of arrays. We 
have a  class to translate to and from VARIANTS, unfortunately I can't give away
the code since someone else wrote it and the company owns it, The class idea 
works quite well.

Another idea that we are looking at is discussed in "Advanceed Windows" by 
Jeffery Richter. His idea is to use memory mapped files and to just pass a 
handle in the controll. It looks like a better solution but we havent tried it 
yet and dont know how VB would handle it.

Keith V


______________________________ Reply Separator _________________________________
Subject: Passing variable length in OLE Automation.
Author:  K.Parthipan@blr.sni.de at INTERNET
Date:    12/22/96 2:55 PM


Hello

        Environment : VC++ 4.0, Win NT 3.51


        I want communication between two OCX controls through OLE automation. I
coule implement everything except that I want to pass variable length
data between them. The data is a list of names. And no. of names in list
I do not know. Is is possilble to communicate through IUnknown
interface. What I would like to do is in one of the methods I will have
IUnknown interface and when that function is being called I will pass
IDataObject datamember which has list of my names in global data. In the
receiving end I will type cast IUnknown to IDataObject and will retrieve
data. Is it possible to do that. 

        Or is there any other way can two OCX controls can communicate with
each other.


Parthipan Kanakasabhapathi




| Вернуться в корень Архива |