Passing user defined type var between VB and VC 
Author Message
 Passing user defined type var between VB and VC

Hi,all:

   I use one user-defined type var in one atl com,and a method to seting
it's value.
when i use it in vb,compiler tell me user-defined var may not passed by var
   How to deal with this?



Sun, 25 Jan 2004 17:05:21 GMT  
 Passing user defined type var between VB and VC
This doesn't make much sense to me. Please post the IDL declaration
of the method and your VB code.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi,all:

>    I use one user-defined type var in one atl com,and a method to seting
> it's value.
> when i use it in vb,compiler tell me user-defined var may not passed by
var
>    How to deal with this?



Mon, 26 Jan 2004 06:47:19 GMT  
 Passing user defined type var between VB and VC
Hi,the IDL file:

import "oaidl.idl";
import "ocidl.idl";
  typedef struct
  {
     int myID;
     BSTR   name;
  } Info;

 [
  object,
  uuid(6497C034-CF10-11D2-91AE-0008C7FE9130),
  dual,
  helpstring("IAccessControl Interface"),
  pointer_default(unique)
 ]
 interface IAccessControl : IDispatch
 {

  [propget, id(1), helpstring("Sets or retrieves UserName")] HRESULT
UserName([out, retval] BSTR *pVal);
  [propput, id(1), helpstring("Sets or retrieves UserName")] HRESULT
UserName([in] BSTR newVal);
  [id(2), helpstring("method StructIn")] HRESULT StructIn([in] Info one);
  [id(3), helpstring("method StructOut")] HRESULT StructOut([out,retval]
Info*  ptOne);

Quote:
};

[
 uuid(63098966-CEA5-11D2-91AD-0008C7FE9130),
 version(1.0),
 helpstring("SecurityMgr 1.0 Type Library")
]
library SECURITYMGRLib
{
 importlib("stdole32.tlb");
 importlib("stdole2.tlb");

 [
  uuid(6497C035-CF10-11D2-91AE-0008C7FE9130),
  helpstring("AccessControl Class")
 ]
 coclass AccessControl
 {
  [default] interface IAccessControl;
 };

Quote:
};

and VB code:
Dim objAccessControl As SECURITYMGRLib.AccessControl
Dim MyRecord As Info  ' Declare variable.

'create the object
Set objAccessControl = CreateObject("SecurityMgr.AccessControl")

MyRecord = objAccessControl.StructOut()
' That's Ok
MyRecord.MyID=2001001
MyRecord.name="boy"
objAccessControl.StructIn (MyRecord)
'                            ^^^^  Compile error:user-defined type may not
be passed byval
'call pIDispatch->release
Set MyRecord = Nothing
Set objAccessControl = Nothing

Thank you in advance

Quote:
> This doesn't make much sense to me. Please post the IDL declaration
> of the method and your VB code.

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Hi,all:

> >    I use one user-defined type var in one atl com,and a method to seting
> > it's value.
> > when i use it in vb,compiler tell me user-defined var may not passed by
> var
> >    How to deal with this?



Mon, 26 Jan 2004 09:08:00 GMT  
 Passing user defined type var between VB and VC
You must use another indirection - you cannot pass the struct
on the stack. Change it to:

  [id(2), helpstring("method StructIn")] HRESULT StructIn([in] Info *pOne);

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi,the IDL file:

> import "oaidl.idl";
> import "ocidl.idl";
>   typedef struct
>   {
>      int myID;
>      BSTR   name;
>   } Info;

>  [
>   object,
>   uuid(6497C034-CF10-11D2-91AE-0008C7FE9130),
>   dual,
>   helpstring("IAccessControl Interface"),
>   pointer_default(unique)
>  ]
>  interface IAccessControl : IDispatch
>  {

>   [propget, id(1), helpstring("Sets or retrieves UserName")] HRESULT
> UserName([out, retval] BSTR *pVal);
>   [propput, id(1), helpstring("Sets or retrieves UserName")] HRESULT
> UserName([in] BSTR newVal);
>   [id(2), helpstring("method StructIn")] HRESULT StructIn([in] Info one);
>   [id(3), helpstring("method StructOut")] HRESULT StructOut([out,retval]
> Info*  ptOne);
> };

> [
>  uuid(63098966-CEA5-11D2-91AD-0008C7FE9130),
>  version(1.0),
>  helpstring("SecurityMgr 1.0 Type Library")
> ]
> library SECURITYMGRLib
> {
>  importlib("stdole32.tlb");
>  importlib("stdole2.tlb");

>  [
>   uuid(6497C035-CF10-11D2-91AE-0008C7FE9130),
>   helpstring("AccessControl Class")
>  ]
>  coclass AccessControl
>  {
>   [default] interface IAccessControl;
>  };
> };

> and VB code:
> Dim objAccessControl As SECURITYMGRLib.AccessControl
> Dim MyRecord As Info  ' Declare variable.

> 'create the object
> Set objAccessControl = CreateObject("SecurityMgr.AccessControl")

> MyRecord = objAccessControl.StructOut()
> ' That's Ok
> MyRecord.MyID=2001001
> MyRecord.name="boy"
> objAccessControl.StructIn (MyRecord)
> '                            ^^^^  Compile error:user-defined type may not
> be passed byval
> 'call pIDispatch->release
> Set MyRecord = Nothing
> Set objAccessControl = Nothing

> Thank you in advance


> > This doesn't make much sense to me. Please post the IDL declaration
> > of the method and your VB code.

> > --
> > =====================================
> > Alexander Nickolov
> > Microsoft MVP [VC], MCSD

> > MVP VC FAQ: http://www.mvps.org/vcfaq
> > =====================================



> > > Hi,all:

> > >    I use one user-defined type var in one atl com,and a method to
seting
> > > it's value.
> > > when i use it in vb,compiler tell me user-defined var may not passed
by
> > var
> > >    How to deal with this?



Tue, 27 Jan 2004 01:59:42 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing user defined structures from VB to C++ DLL

2. How to pass UDTs(User Defined Type Array)

3. Passing User defined data Type in ATL

4. passing user defined type

5. Passing a user defined type to a DLL

6. How to pass UDTs(User Defined Type Array)

7. Passing a user defined type to a DLL

8. type *var -- vs. -- type* var

9. How can I pass a UDT(User Defined Type) defined in IDL file of an ATL DLL to VB client?

10. ASP.NET Newbie - pass a Var from Code Behind to User Control file

11. How to pass var length array of string to event in VB

12. Args: var number & var types

 

 
Powered by phpBB® Forum Software