Vboost mixed language com programming (VC++ to VB -> Safearray) 
Author Message
 Vboost mixed language com programming (VC++ to VB -> Safearray)

Hi

I need help with the following;  I have a program which exports pointers to
its data arrays
( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs, ResultRec
*apResultRec)

The first two arrays contain data that should not be change, The third array
receives the result of the calculation done with data from the first two
arrays.
I would like to do the calcullations in VB and place the results in
ResultRec *apResultRec.I therefore  want to pass these  array of structures
from VC++ to VB do the apprpriate calcullations in VB and place the result
at the memory locations at ResultRec.

I know that in C++ an array is a chunk of memory.
In his book advanced Visual Basic 6 Power Techniques for everyday Programs
Matthew Curland on page 40 gives me a clue in how to do this he says: "In
C++ you can simply use a stackbased SAFEARRAY descriptor, fill in the
fields, and point your pvDatat to the appropriate block of memory, which can
be stack allocated with _alloca if you don't already have one... Simply cast
pvData to the appropriate type and use it as a normal C-style array".

The sollution as I see it is to convert the memory locations to a SAFEARRAY
and send these to VB

My questions:
How do I cast pvData  to the appropriate type?
how do I fill in the appropriate fields in VC++?
How do I pass the Safearray from VC++ to VB
How do I stack allocate using _alloca
What are the requirements at the VB side, please note that that VC++ is
calling VB.

I am not yet proficient in C/C++, your help is greatly appreciated.

Regards
Guno



Thu, 23 Sep 2004 21:33:17 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
In addition to my previous reply, the following are some KB articles that
may help you:

Q154172 How To Pass Binary Data Between an ActiveX Control and VB
http://support.microsoft.com/support/kb/articles/q154/1/72.asp

Q167668 HOWTO: Pass a SafeArray of Strings in a VARIANT*
http://support.microsoft.com/support/kb/articles/q167/6/68.asp

-Kevin

This posting is provided ?AS IS? with no warranties, and confers no
rights.

--------------------

| Subject: Vboost mixed language com programming (VC++ to VB -> Safearray)
| Date: Sun, 7 Apr 2002 15:33:17 +0200
| Lines: 42
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

| Newsgroups:
microsoft.public.vb.com,microsoft.public.vb.winapi,microsoft.public.vc.atl,m
icrosoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.vc.mfco
le,microsoft.public.vc.stl
| NNTP-Posting-Host: c11137.upc-c.chello.nl 212.187.11.137
| Path: cpmsftngxa07!cpmsftngxa09!tkmsftngp01!tkmsftngp07
| Xref: cpmsftngxa07 microsoft.public.vb.winapi:145537
microsoft.public.vc.atl:32372 microsoft.public.vc.language:160364
microsoft.public.vc.mfc:321395 microsoft.public.vc.mfcole:26388
microsoft.public.vc.stl:15134 microsoft.public.vb.com:26834
| X-Tomcat-NG: microsoft.public.vc.atl
|
| Hi
|
| I need help with the following;  I have a program which exports pointers
to
| its data arrays
| ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs, ResultRec
| *apResultRec)
|
| The first two arrays contain data that should not be change, The third
array
| receives the result of the calculation done with data from the first two
| arrays.
| I would like to do the calcullations in VB and place the results in
| ResultRec *apResultRec.I therefore  want to pass these  array of
structures
| from VC++ to VB do the apprpriate calcullations in VB and place the result
| at the memory locations at ResultRec.
|
| I know that in C++ an array is a chunk of memory.
| In his book advanced Visual Basic 6 Power Techniques for everyday Programs
| Matthew Curland on page 40 gives me a clue in how to do this he says: "In
| C++ you can simply use a stackbased SAFEARRAY descriptor, fill in the
| fields, and point your pvDatat to the appropriate block of memory, which
can
| be stack allocated with _alloca if you don't already have one... Simply
cast
| pvData to the appropriate type and use it as a normal C-style array".
|
| The sollution as I see it is to convert the memory locations to a
SAFEARRAY
| and send these to VB
|
| My questions:
| How do I cast pvData  to the appropriate type?
| how do I fill in the appropriate fields in VC++?
| How do I pass the Safearray from VC++ to VB
| How do I stack allocate using _alloca
| What are the requirements at the VB side, please note that that VC++ is
| calling VB.
|
| I am not yet proficient in C/C++, your help is greatly appreciated.
|
|
| Regards
| Guno
|
|
|
|



Sat, 25 Sep 2004 17:58:23 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
In VB, you need to create an array parameter on a COM method. For example,
MyData() As DataRec. Note that you'll have to have DataRec defined in a
typelib somewhere for VB to be able to use it. If you want to simplify the
registration requirements, then you'll want to create a GUID_NULL record. To
do this (assuming the have the updated book tools from the website):
0) Inside an ActiveX Dll project
1) Use the 'PowerVB Type Library Editor' add-in to define a typelib record
matching the type. Make sure the Guid is all zeroes, and that the packing
matches what you have in VC.
2) Define your method on a MultiUse or PublicNotCreatable class. The
parameters should look similar to 'MyData() As DataRec'.
2) (Optional, but recommended so you don't have to ship the library) Use the
'PowerVB Post-Build Type Library Modifier' add-in to pull the record
definition into your VB binary when you build (use the Internalize Types
command on the library node).

From the C++ side, use the #import to pull in the VB type library in. I
don't generally use this feature, but I believe it handles SAFEARRAYs now.
If it doesn't, there are some options on it to just pull in the interfaces
instead of generating wrapper classes (it is faster and much lighter weight
to just use the interfaces, but you have to handle the HRESULT return values
manually). See the VC docs for more info, or maybe someone else can fill in
the details here.

Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the stack (air
code, I haven't done this in a while):
MyRec* pData;
SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
(void*)pData, {elementcount, 0}};
SAFEARRAY* pSA = &MySA;

You can now pass &pSA to the function. The flags stop VB from redimming or
releasing the array. However, it doesn't stop a rogue Erase call from
zeroing your data (just the buffer). You can do this for all the parameters,
assuming you allocate the output buffers in VC instead of VB. -Matt

. The equivalent parameter type in VC is a SAFEARRAY**. So, to set up your
C++ code for the call.


Quote:
> Hi

> I need help with the following;  I have a program which exports pointers
to
> its data arrays
> ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs, ResultRec
> *apResultRec)

> The first two arrays contain data that should not be change, The third
array
> receives the result of the calculation done with data from the first two
> arrays.
> I would like to do the calcullations in VB and place the results in
> ResultRec *apResultRec.I therefore  want to pass these  array of
structures
> from VC++ to VB do the apprpriate calcullations in VB and place the result
> at the memory locations at ResultRec.

> I know that in C++ an array is a chunk of memory.
> In his book advanced Visual Basic 6 Power Techniques for everyday Programs
> Matthew Curland on page 40 gives me a clue in how to do this he says: "In
> C++ you can simply use a stackbased SAFEARRAY descriptor, fill in the
> fields, and point your pvDatat to the appropriate block of memory, which
can
> be stack allocated with _alloca if you don't already have one... Simply
cast
> pvData to the appropriate type and use it as a normal C-style array".

> The sollution as I see it is to convert the memory locations to a
SAFEARRAY
> and send these to VB

> My questions:
> How do I cast pvData  to the appropriate type?
> how do I fill in the appropriate fields in VC++?
> How do I pass the Safearray from VC++ to VB
> How do I stack allocate using _alloca
> What are the requirements at the VB side, please note that that VC++ is
> calling VB.

> I am not yet proficient in C/C++, your help is greatly appreciated.

> Regards
> Guno



Sun, 26 Sep 2004 08:59:16 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
Thanks Matt

I will try it out

Guno


Quote:
> In VB, you need to create an array parameter on a COM method. For example,
> MyData() As DataRec. Note that you'll have to have DataRec defined in a
> typelib somewhere for VB to be able to use it. If you want to simplify the
> registration requirements, then you'll want to create a GUID_NULL record.
To
> do this (assuming the have the updated book tools from the website):
> 0) Inside an ActiveX Dll project
> 1) Use the 'PowerVB Type Library Editor' add-in to define a typelib record
> matching the type. Make sure the Guid is all zeroes, and that the packing
> matches what you have in VC.
> 2) Define your method on a MultiUse or PublicNotCreatable class. The
> parameters should look similar to 'MyData() As DataRec'.
> 2) (Optional, but recommended so you don't have to ship the library) Use
the
> 'PowerVB Post-Build Type Library Modifier' add-in to pull the record
> definition into your VB binary when you build (use the Internalize Types
> command on the library node).

> From the C++ side, use the #import to pull in the VB type library in. I
> don't generally use this feature, but I believe it handles SAFEARRAYs now.
> If it doesn't, there are some options on it to just pull in the interfaces
> instead of generating wrapper classes (it is faster and much lighter
weight
> to just use the interfaces, but you have to handle the HRESULT return
values
> manually). See the VC docs for more info, or maybe someone else can fill
in
> the details here.

> Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the stack
(air
> code, I haven't done this in a while):
> MyRec* pData;
> SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
> (void*)pData, {elementcount, 0}};
> SAFEARRAY* pSA = &MySA;

> You can now pass &pSA to the function. The flags stop VB from redimming or
> releasing the array. However, it doesn't stop a rogue Erase call from
> zeroing your data (just the buffer). You can do this for all the
parameters,
> assuming you allocate the output buffers in VC instead of VB. -Matt

> . The equivalent parameter type in VC is a SAFEARRAY**. So, to set up your
> C++ code for the call.


> > Hi

> > I need help with the following;  I have a program which exports pointers
> to
> > its data arrays
> > ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs, ResultRec
> > *apResultRec)

> > The first two arrays contain data that should not be change, The third
> array
> > receives the result of the calculation done with data from the first two
> > arrays.
> > I would like to do the calcullations in VB and place the results in
> > ResultRec *apResultRec.I therefore  want to pass these  array of
> structures
> > from VC++ to VB do the apprpriate calcullations in VB and place the
result
> > at the memory locations at ResultRec.

> > I know that in C++ an array is a chunk of memory.
> > In his book advanced Visual Basic 6 Power Techniques for everyday
Programs
> > Matthew Curland on page 40 gives me a clue in how to do this he says:
"In
> > C++ you can simply use a stackbased SAFEARRAY descriptor, fill in the
> > fields, and point your pvDatat to the appropriate block of memory, which
> can
> > be stack allocated with _alloca if you don't already have one... Simply
> cast
> > pvData to the appropriate type and use it as a normal C-style array".

> > The sollution as I see it is to convert the memory locations to a
> SAFEARRAY
> > and send these to VB

> > My questions:
> > How do I cast pvData  to the appropriate type?
> > how do I fill in the appropriate fields in VC++?
> > How do I pass the Safearray from VC++ to VB
> > How do I stack allocate using _alloca
> > What are the requirements at the VB side, please note that that VC++ is
> > calling VB.

> > I am not yet proficient in C/C++, your help is greatly appreciated.

> > Regards
> > Guno



Sat, 02 Oct 2004 05:21:34 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
Hi ,

I need some hand holding, I am new to IDL, typelibraries and C++. I have
structures in C, these structures contain pointers to other structures and
pointers to arrays. These structures are filled on the C/C++ side after this
they should be made available to VB.  How do I define these structures in a
type library in such a way that VB can easily handle these structures/array
?

Thanks
Guno

typedef struct
{
 long lDate;
 long lTime;

Quote:
} DateTime;

typedef struct
{
 float *pfValue;
 int   Record;

Quote:
} DataInfoRec;

typedef struct
{
 DateTime     *psDate;
 DataInfoRec  sDat;    // Data  structure
 char              *pszName;
 int             iPeriod;

Quote:
} DataRec;

typedef struct
{
 DataInfoRec *psInfoRecs[5];  // pointers to data arrays
 int            iNRecs;

Quote:
} DataInfoArray;



Quote:
> Thanks Matt

> I will try it out

> Guno



> > In VB, you need to create an array parameter on a COM method. For
example,
> > MyData() As DataRec. Note that you'll have to have DataRec defined in a
> > typelib somewhere for VB to be able to use it. If you want to simplify
the
> > registration requirements, then you'll want to create a GUID_NULL
record.
> To
> > do this (assuming the have the updated book tools from the website):
> > 0) Inside an ActiveX Dll project
> > 1) Use the 'PowerVB Type Library Editor' add-in to define a typelib
record
> > matching the type. Make sure the Guid is all zeroes, and that the
packing
> > matches what you have in VC.
> > 2) Define your method on a MultiUse or PublicNotCreatable class. The
> > parameters should look similar to 'MyData() As DataRec'.
> > 2) (Optional, but recommended so you don't have to ship the library) Use
> the
> > 'PowerVB Post-Build Type Library Modifier' add-in to pull the record
> > definition into your VB binary when you build (use the Internalize Types
> > command on the library node).

> > From the C++ side, use the #import to pull in the VB type library in. I
> > don't generally use this feature, but I believe it handles SAFEARRAYs
now.
> > If it doesn't, there are some options on it to just pull in the
interfaces
> > instead of generating wrapper classes (it is faster and much lighter
> weight
> > to just use the interfaces, but you have to handle the HRESULT return
> values
> > manually). See the VC docs for more info, or maybe someone else can fill
> in
> > the details here.

> > Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the stack
> (air
> > code, I haven't done this in a while):
> > MyRec* pData;
> > SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
> > (void*)pData, {elementcount, 0}};
> > SAFEARRAY* pSA = &MySA;

> > You can now pass &pSA to the function. The flags stop VB from redimming
or
> > releasing the array. However, it doesn't stop a rogue Erase call from
> > zeroing your data (just the buffer). You can do this for all the
> parameters,
> > assuming you allocate the output buffers in VC instead of VB. -Matt

> > . The equivalent parameter type in VC is a SAFEARRAY**. So, to set up
your
> > C++ code for the call.


> > > Hi

> > > I need help with the following;  I have a program which exports
pointers
> > to
> > > its data arrays
> > > ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs,
ResultRec
> > > *apResultRec)

> > > The first two arrays contain data that should not be change, The third
> > array
> > > receives the result of the calculation done with data from the first
two
> > > arrays.
> > > I would like to do the calcullations in VB and place the results in
> > > ResultRec *apResultRec.I therefore  want to pass these  array of
> > structures
> > > from VC++ to VB do the apprpriate calcullations in VB and place the
> result
> > > at the memory locations at ResultRec.

> > > I know that in C++ an array is a chunk of memory.
> > > In his book advanced Visual Basic 6 Power Techniques for everyday
> Programs
> > > Matthew Curland on page 40 gives me a clue in how to do this he says:
> "In
> > > C++ you can simply use a stackbased SAFEARRAY descriptor, fill in the
> > > fields, and point your pvDatat to the appropriate block of memory,
which
> > can
> > > be stack allocated with _alloca if you don't already have one...
Simply
> > cast
> > > pvData to the appropriate type and use it as a normal C-style array".

> > > The sollution as I see it is to convert the memory locations to a
> > SAFEARRAY
> > > and send these to VB

> > > My questions:
> > > How do I cast pvData  to the appropriate type?
> > > how do I fill in the appropriate fields in VC++?
> > > How do I pass the Safearray from VC++ to VB
> > > How do I stack allocate using _alloca
> > > What are the requirements at the VB side, please note that that VC++
is
> > > calling VB.

> > > I am not yet proficient in C/C++, your help is greatly appreciated.

> > > Regards
> > > Guno



Wed, 06 Oct 2004 17:53:02 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
typedef struct
{
 long lDate;
 long lTime;

Quote:
} DateTime;

typedef struct
{
 float *pfValue;
 int   Record;

Quote:
} DataInfoRec;

typedef struct
{
 DateTime     *psDate;
 DataInfoRec  sDat;    // Data  structure
 char              *pszName;
 int             iPeriod;

Quote:
} DataRec;

typedef struct
{
 DataInfoRec *psInfoRecs[5];  // pointers to data arrays
 int            iNRecs;

Quote:
} DataInfoArray;



Quote:
> Hi ,

> I need some hand holding, I am new to IDL, typelibraries and C++. I have
> structures in C, these structures contain pointers to other structures and
> pointers to arrays. These structures are filled on the C/C++ side after
this
> they should be made available to VB.  How do I define these structures in
a
> type library in such a way that VB can easily handle these
structures/array
> ?

> Thanks
> Guno

> typedef struct
> {
>  long lDate;
>  long lTime;
> } DateTime;

> typedef struct
> {
>  float *pfValue;
>  int   Record;
> } DataInfoRec;

> typedef struct
> {
>  DateTime     *psDate;
>  DataInfoRec  sDat;    // Data  structure
>  char              *pszName;
>  int             iPeriod;
> } DataRec;

> typedef struct
> {
>  DataInfoRec *psInfoRecs[5];  // pointers to data arrays
>  int            iNRecs;
> } DataInfoArray;



> > Thanks Matt

> > I will try it out

> > Guno



> > > In VB, you need to create an array parameter on a COM method. For
> example,
> > > MyData() As DataRec. Note that you'll have to have DataRec defined in
a
> > > typelib somewhere for VB to be able to use it. If you want to simplify
> the
> > > registration requirements, then you'll want to create a GUID_NULL
> record.
> > To
> > > do this (assuming the have the updated book tools from the website):
> > > 0) Inside an ActiveX Dll project
> > > 1) Use the 'PowerVB Type Library Editor' add-in to define a typelib
> record
> > > matching the type. Make sure the Guid is all zeroes, and that the
> packing
> > > matches what you have in VC.
> > > 2) Define your method on a MultiUse or PublicNotCreatable class. The
> > > parameters should look similar to 'MyData() As DataRec'.
> > > 2) (Optional, but recommended so you don't have to ship the library)
Use
> > the
> > > 'PowerVB Post-Build Type Library Modifier' add-in to pull the record
> > > definition into your VB binary when you build (use the Internalize
Types
> > > command on the library node).

> > > From the C++ side, use the #import to pull in the VB type library in.
I
> > > don't generally use this feature, but I believe it handles SAFEARRAYs
> now.
> > > If it doesn't, there are some options on it to just pull in the
> interfaces
> > > instead of generating wrapper classes (it is faster and much lighter
> > weight
> > > to just use the interfaces, but you have to handle the HRESULT return
> > values
> > > manually). See the VC docs for more info, or maybe someone else can
fill
> > in
> > > the details here.

> > > Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the stack
> > (air
> > > code, I haven't done this in a while):
> > > MyRec* pData;
> > > SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
> > > (void*)pData, {elementcount, 0}};
> > > SAFEARRAY* pSA = &MySA;

> > > You can now pass &pSA to the function. The flags stop VB from
redimming
> or
> > > releasing the array. However, it doesn't stop a rogue Erase call from
> > > zeroing your data (just the buffer). You can do this for all the
> > parameters,
> > > assuming you allocate the output buffers in VC instead of VB. -Matt

> > > . The equivalent parameter type in VC is a SAFEARRAY**. So, to set up
> your
> > > C++ code for the call.


> > > > Hi

> > > > I need help with the following;  I have a program which exports
> pointers
> > > to
> > > > its data arrays
> > > > ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs,
> ResultRec
> > > > *apResultRec)

> > > > The first two arrays contain data that should not be change, The
third
> > > array
> > > > receives the result of the calculation done with data from the first
> two
> > > > arrays.
> > > > I would like to do the calcullations in VB and place the results in
> > > > ResultRec *apResultRec.I therefore  want to pass these  array of
> > > structures
> > > > from VC++ to VB do the apprpriate calcullations in VB and place the
> > result
> > > > at the memory locations at ResultRec.

> > > > I know that in C++ an array is a chunk of memory.
> > > > In his book advanced Visual Basic 6 Power Techniques for everyday
> > Programs
> > > > Matthew Curland on page 40 gives me a clue in how to do this he
says:
> > "In
> > > > C++ you can simply use a stackbased SAFEARRAY descriptor, fill in
the
> > > > fields, and point your pvDatat to the appropriate block of memory,
> which
> > > can
> > > > be stack allocated with _alloca if you don't already have one...
> Simply
> > > cast
> > > > pvData to the appropriate type and use it as a normal C-style
array".

> > > > The sollution as I see it is to convert the memory locations to a
> > > SAFEARRAY
> > > > and send these to VB

> > > > My questions:
> > > > How do I cast pvData  to the appropriate type?
> > > > how do I fill in the appropriate fields in VC++?
> > > > How do I pass the Safearray from VC++ to VB
> > > > How do I stack allocate using _alloca
> > > > What are the requirements at the VB side, please note that that VC++
> is
> > > > calling VB.

> > > > I am not yet proficient in C/C++, your help is greatly appreciated.

> > > > Regards
> > > > Guno



Thu, 07 Oct 2004 03:34:37 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
Hi Guno,

I hope you're using the Typelibrary Editor add-in from Matt's book to create
your typelibrary. It makes this sort of thing about as intuitive as it's
going to get.

Here's a tip: Use the external typelib editor and look at the
VBoostTypes6.olb file and you'll see all sorts of examples of how to specify
the parameters. Look at MSDN for the C++ footprint. e.g. LoadLibrary is in
there, so look it up in MSDN, then look at the parameters in his typelib
with the typelib editor.

Appleman's VB Programmer's Guide to the Win32 API is also very handy for
getting to know data type conversions between VB and C++, though it's fairly
specific to Declare statements.
http://www.desaware.com/VBPGWin32APIL2.htm

Hope that helps,
Pete



Quote:
> Hi ,

> I need some hand holding, I am new to IDL, typelibraries and C++. I have
> structures in C, these structures contain pointers to other structures and
> pointers to arrays. These structures are filled on the C/C++ side after
this
> they should be made available to VB.  How do I define these structures in
a
> type library in such a way that VB can easily handle these
structures/array
> ?

> Thanks
> Guno

> typedef struct
> {
>  long lDate;
>  long lTime;
> } DateTime;

> typedef struct
> {
>  float *pfValue;
>  int   Record;
> } DataInfoRec;

> typedef struct
> {
>  DateTime     *psDate;
>  DataInfoRec  sDat;    // Data  structure
>  char              *pszName;
>  int             iPeriod;
> } DataRec;

> typedef struct
> {
>  DataInfoRec *psInfoRecs[5];  // pointers to data arrays
>  int            iNRecs;
> } DataInfoArray;



> > Thanks Matt

> > I will try it out

> > Guno



> > > In VB, you need to create an array parameter on a COM method. For
> example,
> > > MyData() As DataRec. Note that you'll have to have DataRec defined in
a
> > > typelib somewhere for VB to be able to use it. If you want to simplify
> the
> > > registration requirements, then you'll want to create a GUID_NULL
> record.
> > To
> > > do this (assuming the have the updated book tools from the website):
> > > 0) Inside an ActiveX Dll project
> > > 1) Use the 'PowerVB Type Library Editor' add-in to define a typelib
> record
> > > matching the type. Make sure the Guid is all zeroes, and that the
> packing
> > > matches what you have in VC.
> > > 2) Define your method on a MultiUse or PublicNotCreatable class. The
> > > parameters should look similar to 'MyData() As DataRec'.
> > > 2) (Optional, but recommended so you don't have to ship the library)
Use
> > the
> > > 'PowerVB Post-Build Type Library Modifier' add-in to pull the record
> > > definition into your VB binary when you build (use the Internalize
Types
> > > command on the library node).

> > > From the C++ side, use the #import to pull in the VB type library in.
I
> > > don't generally use this feature, but I believe it handles SAFEARRAYs
> now.
> > > If it doesn't, there are some options on it to just pull in the
> interfaces
> > > instead of generating wrapper classes (it is faster and much lighter
> > weight
> > > to just use the interfaces, but you have to handle the HRESULT return
> > values
> > > manually). See the VC docs for more info, or maybe someone else can
fill
> > in
> > > the details here.

> > > Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the stack
> > (air
> > > code, I haven't done this in a while):
> > > MyRec* pData;
> > > SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
> > > (void*)pData, {elementcount, 0}};
> > > SAFEARRAY* pSA = &MySA;

> > > You can now pass &pSA to the function. The flags stop VB from
redimming
> or
> > > releasing the array. However, it doesn't stop a rogue Erase call from
> > > zeroing your data (just the buffer). You can do this for all the
> > parameters,
> > > assuming you allocate the output buffers in VC instead of VB. -Matt

> > > . The equivalent parameter type in VC is a SAFEARRAY**. So, to set up
> your
> > > C++ code for the call.


> > > > Hi

> > > > I need help with the following;  I have a program which exports
> pointers
> > > to
> > > > its data arrays
> > > > ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs,
> ResultRec
> > > > *apResultRec)

> > > > The first two arrays contain data that should not be change, The
third
> > > array
> > > > receives the result of the calculation done with data from the first
> two
> > > > arrays.
> > > > I would like to do the calcullations in VB and place the results in
> > > > ResultRec *apResultRec.I therefore  want to pass these  array of
> > > structures
> > > > from VC++ to VB do the apprpriate calcullations in VB and place the
> > result
> > > > at the memory locations at ResultRec.

> > > > I know that in C++ an array is a chunk of memory.
> > > > In his book advanced Visual Basic 6 Power Techniques for everyday
> > Programs
> > > > Matthew Curland on page 40 gives me a clue in how to do this he
says:
> > "In
> > > > C++ you can simply use a stackbased SAFEARRAY descriptor, fill in
the
> > > > fields, and point your pvDatat to the appropriate block of memory,
> which
> > > can
> > > > be stack allocated with _alloca if you don't already have one...
> Simply
> > > cast
> > > > pvData to the appropriate type and use it as a normal C-style
array".

> > > > The sollution as I see it is to convert the memory locations to a
> > > SAFEARRAY
> > > > and send these to VB

> > > > My questions:
> > > > How do I cast pvData  to the appropriate type?
> > > > how do I fill in the appropriate fields in VC++?
> > > > How do I pass the Safearray from VC++ to VB
> > > > How do I stack allocate using _alloca
> > > > What are the requirements at the VB side, please note that that VC++
> is
> > > > calling VB.

> > > > I am not yet proficient in C/C++, your help is greatly appreciated.

> > > > Regards
> > > > Guno



Fri, 08 Oct 2004 14:09:14 GMT  
 Vboost mixed language com programming (VC++ to VB -> Safearray)
Hi pete

Good to hear from you, thanks for the tip

Guno


Quote:
> Hi Guno,

> I hope you're using the Typelibrary Editor add-in from Matt's book to
create
> your typelibrary. It makes this sort of thing about as intuitive as it's
> going to get.

> Here's a tip: Use the external typelib editor and look at the
> VBoostTypes6.olb file and you'll see all sorts of examples of how to
specify
> the parameters. Look at MSDN for the C++ footprint. e.g. LoadLibrary is in
> there, so look it up in MSDN, then look at the parameters in his typelib
> with the typelib editor.

> Appleman's VB Programmer's Guide to the Win32 API is also very handy for
> getting to know data type conversions between VB and C++, though it's
fairly
> specific to Declare statements.
> http://www.desaware.com/VBPGWin32APIL2.htm

> Hope that helps,
> Pete



> > Hi ,

> > I need some hand holding, I am new to IDL, typelibraries and C++. I have
> > structures in C, these structures contain pointers to other structures
and
> > pointers to arrays. These structures are filled on the C/C++ side after
> this
> > they should be made available to VB.  How do I define these structures
in
> a
> > type library in such a way that VB can easily handle these
> structures/array
> > ?

> > Thanks
> > Guno

> > typedef struct
> > {
> >  long lDate;
> >  long lTime;
> > } DateTime;

> > typedef struct
> > {
> >  float *pfValue;
> >  int   Record;
> > } DataInfoRec;

> > typedef struct
> > {
> >  DateTime     *psDate;
> >  DataInfoRec  sDat;    // Data  structure
> >  char              *pszName;
> >  int             iPeriod;
> > } DataRec;

> > typedef struct
> > {
> >  DataInfoRec *psInfoRecs[5];  // pointers to data arrays
> >  int            iNRecs;
> > } DataInfoArray;



> > > Thanks Matt

> > > I will try it out

> > > Guno



> > > > In VB, you need to create an array parameter on a COM method. For
> > example,
> > > > MyData() As DataRec. Note that you'll have to have DataRec defined
in
> a
> > > > typelib somewhere for VB to be able to use it. If you want to
simplify
> > the
> > > > registration requirements, then you'll want to create a GUID_NULL
> > record.
> > > To
> > > > do this (assuming the have the updated book tools from the website):
> > > > 0) Inside an ActiveX Dll project
> > > > 1) Use the 'PowerVB Type Library Editor' add-in to define a typelib
> > record
> > > > matching the type. Make sure the Guid is all zeroes, and that the
> > packing
> > > > matches what you have in VC.
> > > > 2) Define your method on a MultiUse or PublicNotCreatable class. The
> > > > parameters should look similar to 'MyData() As DataRec'.
> > > > 2) (Optional, but recommended so you don't have to ship the library)
> Use
> > > the
> > > > 'PowerVB Post-Build Type Library Modifier' add-in to pull the record
> > > > definition into your VB binary when you build (use the Internalize
> Types
> > > > command on the library node).

> > > > From the C++ side, use the #import to pull in the VB type library
in.
> I
> > > > don't generally use this feature, but I believe it handles
SAFEARRAYs
> > now.
> > > > If it doesn't, there are some options on it to just pull in the
> > interfaces
> > > > instead of generating wrapper classes (it is faster and much lighter
> > > weight
> > > > to just use the interfaces, but you have to handle the HRESULT
return
> > > values
> > > > manually). See the VC docs for more info, or maybe someone else can
> fill
> > > in
> > > > the details here.

> > > > Now, for the C++ code to set up a 1-dimensional SAFEARRAY on the
stack
> > > (air
> > > > code, I haven't done this in a while):
> > > > MyRec* pData;
> > > > SAFEARRAY MySA = {1, FADF_FIXEDSIZE | FADF_STATIC, sizeof(MyRec), 0,
> > > > (void*)pData, {elementcount, 0}};
> > > > SAFEARRAY* pSA = &MySA;

> > > > You can now pass &pSA to the function. The flags stop VB from
> redimming
> > or
> > > > releasing the array. However, it doesn't stop a rogue Erase call
from
> > > > zeroing your data (just the buffer). You can do this for all the
> > > parameters,
> > > > assuming you allocate the output buffers in VC instead of VB. -Matt

> > > > . The equivalent parameter type in VC is a SAFEARRAY**. So, to set
up
> > your
> > > > C++ code for the call.


> > > > > Hi

> > > > > I need help with the following;  I have a program which exports
> > pointers
> > > > to
> > > > > its data arrays
> > > > > ( const DataRec *apDataRec, const DataInfoRec *apDataInfoArgs,
> > ResultRec
> > > > > *apResultRec)

> > > > > The first two arrays contain data that should not be change, The
> third
> > > > array
> > > > > receives the result of the calculation done with data from the
first
> > two
> > > > > arrays.
> > > > > I would like to do the calcullations in VB and place the results
in
> > > > > ResultRec *apResultRec.I therefore  want to pass these  array of
> > > > structures
> > > > > from VC++ to VB do the apprpriate calcullations in VB and place
the
> > > result
> > > > > at the memory locations at ResultRec.

> > > > > I know that in C++ an array is a chunk of memory.
> > > > > In his book advanced Visual Basic 6 Power Techniques for everyday
> > > Programs
> > > > > Matthew Curland on page 40 gives me a clue in how to do this he
> says:
> > > "In
> > > > > C++ you can simply use a stackbased SAFEARRAY descriptor, fill in
> the
> > > > > fields, and point your pvDatat to the appropriate block of memory,
> > which
> > > > can
> > > > > be stack allocated with _alloca if you don't already have one...
> > Simply
> > > > cast
> > > > > pvData to the appropriate type and use it as a normal C-style
> array".

> > > > > The sollution as I see it is to convert the memory locations to a
> > > > SAFEARRAY
> > > > > and send these to VB

> > > > > My questions:
> > > > > How do I cast pvData  to the appropriate type?
> > > > > how do I fill in the appropriate fields in VC++?
> > > > > How do I pass the Safearray from VC++ to VB
> > > > > How do I stack allocate using _alloca
> > > > > What are the requirements at the VB side, please note that that
VC++
> > is
> > > > > calling VB.

> > > > > I am not yet proficient in C/C++, your help is greatly
appreciated.

> > > > > Regards
> > > > > Guno



Sat, 09 Oct 2004 03:48:10 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Vboost mixed language com programming (VC++ to VB -> Safearray)

2. Vboost mixed language com programming (VC++ to VB -> Safearray)

3. Vboost mixed language com programming (VC++ to VB -> Safearray)

4. Mixed language programming DLL , C++, VB/VBA, Fortran

5. Mixed language programming DLL , C++, VB/VBA, Fortran

6. VC -> VB using safearrays

7. mixed-language programming (Calling Fortran routine from VC++)

8. B>C>C++>VC++(MFC)>RAW API PROGRAMMING>ATL>COM>OLE>ADO>ASP.............

9. TC++ <-> TP 6.0 Mixed Language Development

10. Passing a 2D SafeArray from VB client to ATL COM component

11. Using a VB Com object in a VC++ Program

12. URGENT: SafeArray to VARIANT or passing array between VB and COM

 

 
Powered by phpBB® Forum Software