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

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


OCX: Passing by reference

Kartikeya G. Rindani -- kartik@corus.com
Tuesday, May 28, 1996

Platform: Windows 95
MSVC 4.0

I've made an OCX which has a method in which I pass a string paramter using 
the data type BSTR*, which appears in the wizard for creating methods for 
an OCX.  I chose BSTR* because that method modifies the data and I wanted 
the modified string back.
  Now, when I run this OCX in the test container it works like charm and I 
get the modified string properly.  My problem is how do I make this method 
usable is VB 4.0?  When I pass a string to this method it gives me a type 
mismatch error.  I even tried using the Variant data type, but to no avail.

Can anyone help me out with this problem of mine?

Thanks

Kartik




Shankara Narayana Giri -- giri@ndrgw.ndr.co.jp
Monday, June 03, 1996

>Platform: Windows 95
>MSVC 4.0
>
>I've made an OCX which has a method in which I pass a string paramter using 
>the data type BSTR*, which appears in the wizard for creating methods for 
>an OCX.  I chose BSTR* because that method modifies the data and I wanted 
>the modified string back.
>  Now, when I run this OCX in the test container it works like charm and I 
>get the modified string properly.  My problem is how do I make this method 
>usable is VB 4.0?  When I pass a string to this method it gives me a type 
>mismatch error.  I even tried using the Variant data type, but to no avail.
>
>Can anyone help me out with this problem of mine?
>
>Thanks
>
>Kartik

   Dear Kartik,

       I also had the same problem in the earlier days. Here is my solution for
       the problem. You need to use set Sys... functions to manipulate strings
       in OLE Automation.

       short CMyCtrl::seekStringData(BSTR FAR* tstString)
       {
            BOOL mok;

            mok = SysReAllocString(tststring,T2OLE("Modified data"));
            if(mok == FALSE)
                return 0;
            else
                return 1;
       }

       Code in VB:

       Dim ts as string
       dim retval as boolean

       retval = my1.seekstringdata(ts)


       One more information,

       When you need to return a string from your method,

       BSTR CMyCtrl::getString()
       {
            BSTR s;

            s = SysAllocString(T2OLE("Allocated String"));

            return s;
       }

       Code on VB side will be,

       Dim ts as string

       ts = my1.getString

       I hope this information helps you. 

       -giri


----------------------------------------------------------------
 
                        SHANKARA NARAYANA  GIRI
 
                                        Residential Address:
Design Division                         606, SUNSHINE MKM IMAZATO
Development & Engineering Dept.         10-5,O IMAZATO-NISHI 3-CHOME
NDR Co. Ltd.                            HIGASHI NARI-KU
OSAKA, JAPAN                            OSAKA   537, JAPAN
e-mail: giri@ndrgw.ndr.co.jp
 
Tel : 81-6-539-5511 (OFF)               Tel : 81-6-977-1517(RES)
      81-6-539-5512 (OFF)
 
Fax : 81-6-539-2111 (OFF)
---------------------------------------------------------------- 




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