Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Comment/ou declarer un UDT pour que le Tableau d'UDT soit utilisable comme Variant? (Hormis .DLL)

5 réponses
Avatar
xx
Bonsoir

J'ai un UDT dont la structure est e.g.
Public Type myUDT
a As String
b As String
c As Long
d As Integer
End Type
et une variable tableau
Dim testArray() As myUDT

J'ai d'autre part une fonction (fournie par un tiers)
Private Declare Function XYZArrayD Lib "zzzzzz" _
(ByRef Vari As Variant) _
As Long

QUESTION
Comment/ou declarer mon UDT pour que l'instruction
r = XYZArrayD(testArray)
soit valide?

__________
J'ai essaye un certain nombre de combinaisons:
(dans le Form, dans un module .bas, dans un module .cls) ...
rien ne fonctionne.
Le seul moyen que j'aie trouve est de declarer mon UDT dans le module de classe d'une .DLL, ce qui m'ennuie un peu.

Y a-t'il un autre moyen
(module .cls avec une combinaison particuliere de parametres)
???


Merci

5 réponses

Avatar
Axel Guerrier [MS]
Bonjour,

Je crois que ce n'est pas possible:

The reason why it did not work above is that you declared the UDT type in a

Standard EXE project. In order for Visual Basic to add UDT to a collection
or to

convert a UDT type to a Variant type, the UDT type has to be declared as
"Public

type" in a public class module, which means the class module has to be in an

ActiveX Dll project or an Active EXE project and its "Instancing Property"
has to

be "MultiUse" or "GlobalMultiUse". The reason behind the scene is that if
you

declare the UDT type in a "MultiUse" Class in an ActiveX Dll project, then
the UDT

type can be seen in the Type Library which is embedded in the ActiveX Dll.
So OLE

Automation Dll (oleaut32.dll) can read this information from the Type
Library and

then could go ahead to process it. Please also pay attention to the fact
that the

feature to convert a UDT type to a Variant type is a new feature of OLE
Automation

and it is only supported in Visual Basic 6.0 (the oleaut32.dll must be
2.30.4261.1

or higher).


--
Axel GUERRIER
Microsoft France
--------------------
Merci de bien vouloir répondre à ce message dans le newsgroup où il a été
posté. Je le consulte régulièrement.

"xx" wrote in message
news:
Bonsoir

J'ai un UDT dont la structure est e.g.
Public Type myUDT
a As String
b As String
c As Long
d As Integer
End Type
et une variable tableau
Dim testArray() As myUDT

J'ai d'autre part une fonction (fournie par un tiers)
Private Declare Function XYZArrayD Lib "zzzzzz" _
(ByRef Vari As Variant) _
As Long

QUESTION
Comment/ou declarer mon UDT pour que l'instruction
r = XYZArrayD(testArray)
soit valide?

__________
J'ai essaye un certain nombre de combinaisons:
(dans le Form, dans un module .bas, dans un module .cls) ...
rien ne fonctionne.
Le seul moyen que j'aie trouve est de declarer mon UDT dans le module de


classe d'une .DLL, ce qui m'ennuie un peu.

Y a-t'il un autre moyen
(module .cls avec une combinaison particuliere de parametres)
???


Merci




Avatar
xx
"Axel Guerrier [MS]" a écrit dans le message de news:
Bonjour,

Je crois que ce n'est pas possible:



A part un parametre habile dans des .bas ou des .cls, j'avais pense a creer mon propre .TLB.
J'avais compris que , contrairement a .DLL qui doit etre present a la compilation ET a l'execution, .TLB n'est necessaire qu'a la
compilation.
Si c'est le cas, quelqu'un pourrait-il poster le pas a pas pour creer le .TLB pour mon exemple?

Dans mon exemple [ByRef Vari as Variant], je n'ai en fait besoin que du pointeur au variant, et je pourrais le remplacer par [Byval
ptrVari as Long]
Je n'ai trouve aucune instruction (VB ou API) pour obtenir ce pointeur???


The reason why it did not work above is that you declared the UDT type in a

Standard EXE project. In order for Visual Basic to add UDT to a collection
or to

convert a UDT type to a Variant type, the UDT type has to be declared as
"Public

type" in a public class module, which means the class module has to be in an

ActiveX Dll project or an Active EXE project and its "Instancing Property"
has to

be "MultiUse" or "GlobalMultiUse". The reason behind the scene is that if
you

declare the UDT type in a "MultiUse" Class in an ActiveX Dll project, then
the UDT

type can be seen in the Type Library which is embedded in the ActiveX Dll.
So OLE

Automation Dll (oleaut32.dll) can read this information from the Type
Library and

then could go ahead to process it. Please also pay attention to the fact
that the

feature to convert a UDT type to a Variant type is a new feature of OLE
Automation

and it is only supported in Visual Basic 6.0 (the oleaut32.dll must be
2.30.4261.1

or higher).


--
Axel GUERRIER
Microsoft France
--------------------
Merci de bien vouloir répondre à ce message dans le newsgroup où il a été
posté. Je le consulte régulièrement.

"xx" wrote in message
news:
> Bonsoir
>
> J'ai un UDT dont la structure est e.g.
> Public Type myUDT
> a As String
> b As String
> c As Long
> d As Integer
> End Type
> et une variable tableau
> Dim testArray() As myUDT
>
> J'ai d'autre part une fonction (fournie par un tiers)
> Private Declare Function XYZArrayD Lib "zzzzzz" _
> (ByRef Vari As Variant) _
> As Long
>
> QUESTION
> Comment/ou declarer mon UDT pour que l'instruction
> r = XYZArrayD(testArray)
> soit valide?
>
> __________
> J'ai essaye un certain nombre de combinaisons:
> (dans le Form, dans un module .bas, dans un module .cls) ...
> rien ne fonctionne.
> Le seul moyen que j'aie trouve est de declarer mon UDT dans le module de
classe d'une .DLL, ce qui m'ennuie un peu.
>
> Y a-t'il un autre moyen
> (module .cls avec une combinaison particuliere de parametres)
> ???
>
>
> Merci
>
>




Avatar
xx
"Axel Guerrier [MS]" a écrit dans le message de news:
Bonjour,

Je crois que ce n'est pas possible:

The reason why it did not work above is that you declared the UDT type in a

Standard EXE project. In order for Visual Basic to add UDT to a collection
or to

convert a UDT type to a Variant type, the UDT type has to be declared as
"Public

type" in a public class module, which means the class module has to be in an

ActiveX Dll project or an Active EXE project and its "Instancing Property"
has to

be "MultiUse" or "GlobalMultiUse".



Je viens de faire tourner mon programme en l'ayant transforme de ".EXE standard" en "ActiveX .EXE"
(avec adjonction d'un module.bas
Sub Main()
Load Form
End Sub

Ca marche, mais je ne me sens pas tres a l'aise avec cette solution.
(sentiment tout a fait irrationel, j'en conviens)
Si j'avais une reponse favorable a news:3f868670$ , (.TLB ou acces direct au pointeur) je pense que cela
me conviendrait mieux.

The reason behind the scene is that if
you

declare the UDT type in a "MultiUse" Class in an ActiveX Dll project, then
the UDT

type can be seen in the Type Library which is embedded in the ActiveX Dll.
So OLE

Automation Dll (oleaut32.dll) can read this information from the Type
Library and

then could go ahead to process it. Please also pay attention to the fact
that the

feature to convert a UDT type to a Variant type is a new feature of OLE
Automation

and it is only supported in Visual Basic 6.0 (the oleaut32.dll must be
2.30.4261.1

or higher).


--
Axel GUERRIER
Microsoft France
--------------------
Merci de bien vouloir répondre à ce message dans le newsgroup où il a été
posté. Je le consulte régulièrement.

"xx" wrote in message
news:
> Bonsoir
>
> J'ai un UDT dont la structure est e.g.
> Public Type myUDT
> a As String
> b As String
> c As Long
> d As Integer
> End Type
> et une variable tableau
> Dim testArray() As myUDT
>
> J'ai d'autre part une fonction (fournie par un tiers)
> Private Declare Function XYZArrayD Lib "zzzzzz" _
> (ByRef Vari As Variant) _
> As Long
>
> QUESTION
> Comment/ou declarer mon UDT pour que l'instruction
> r = XYZArrayD(testArray)
> soit valide?
>
> __________
> J'ai essaye un certain nombre de combinaisons:
> (dans le Form, dans un module .bas, dans un module .cls) ...
> rien ne fonctionne.
> Le seul moyen que j'aie trouve est de declarer mon UDT dans le module de
classe d'une .DLL, ce qui m'ennuie un peu.
>
> Y a-t'il un autre moyen
> (module .cls avec une combinaison particuliere de parametres)
> ???
>
>
> Merci
>
>




Avatar
Zoury
Quel est la déclaration de la fonction en c/c++? Tu devrais pouvoir lui
passé ton UDT directement..

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

Merci de poster les réponses au groupe afin d'en faire profiter à tous
"xx" wrote in message
news:3f868670$
"Axel Guerrier [MS]" a écrit dans le message


de news:
> Bonjour,
>
> Je crois que ce n'est pas possible:

A part un parametre habile dans des .bas ou des .cls, j'avais pense a


creer mon propre .TLB.
J'avais compris que , contrairement a .DLL qui doit etre present a la


compilation ET a l'execution, .TLB n'est necessaire qu'a la
compilation.
Si c'est le cas, quelqu'un pourrait-il poster le pas a pas pour creer le


.TLB pour mon exemple?

Dans mon exemple [ByRef Vari as Variant], je n'ai en fait besoin que du


pointeur au variant, et je pourrais le remplacer par [Byval
ptrVari as Long]
Je n'ai trouve aucune instruction (VB ou API) pour obtenir ce pointeur???


> The reason why it did not work above is that you declared the UDT type


in a
>
> Standard EXE project. In order for Visual Basic to add UDT to a


collection
> or to
>
> convert a UDT type to a Variant type, the UDT type has to be declared as
> "Public
>
> type" in a public class module, which means the class module has to be


in an
>
> ActiveX Dll project or an Active EXE project and its "Instancing


Property"
> has to
>
> be "MultiUse" or "GlobalMultiUse". The reason behind the scene is that


if
> you
>
> declare the UDT type in a "MultiUse" Class in an ActiveX Dll project,


then
> the UDT
>
> type can be seen in the Type Library which is embedded in the ActiveX


Dll.
> So OLE
>
> Automation Dll (oleaut32.dll) can read this information from the Type
> Library and
>
> then could go ahead to process it. Please also pay attention to the fact
> that the
>
> feature to convert a UDT type to a Variant type is a new feature of OLE
> Automation
>
> and it is only supported in Visual Basic 6.0 (the oleaut32.dll must be
> 2.30.4261.1
>
> or higher).
>
>
> --
> Axel GUERRIER
> Microsoft France
> --------------------
> Merci de bien vouloir répondre à ce message dans le newsgroup où il a


été
> posté. Je le consulte régulièrement.
>
> "xx" wrote in message
> news:
> > Bonsoir
> >
> > J'ai un UDT dont la structure est e.g.
> > Public Type myUDT
> > a As String
> > b As String
> > c As Long
> > d As Integer
> > End Type
> > et une variable tableau
> > Dim testArray() As myUDT
> >
> > J'ai d'autre part une fonction (fournie par un tiers)
> > Private Declare Function XYZArrayD Lib "zzzzzz" _
> > (ByRef Vari As Variant) _
> > As Long
> >
> > QUESTION
> > Comment/ou declarer mon UDT pour que l'instruction
> > r = XYZArrayD(testArray)
> > soit valide?
> >
> > __________
> > J'ai essaye un certain nombre de combinaisons:
> > (dans le Form, dans un module .bas, dans un module .cls) ...
> > rien ne fonctionne.
> > Le seul moyen que j'aie trouve est de declarer mon UDT dans le module


de
> classe d'une .DLL, ce qui m'ennuie un peu.
> >
> > Y a-t'il un autre moyen
> > (module .cls avec une combinaison particuliere de parametres)
> > ???
> >
> >
> > Merci
> >
> >
>
>




Avatar
xx
"Zoury" a écrit dans le message de news:
Quel est la déclaration de la fonction en c/c++? Tu devrais pouvoir lui
passé ton UDT directement..



Ma fonction attend un Long: le pointeur au tableau d'UDT.

(FYI: Ma fonction XYZArrayD n'est pas ecrite en C/C++
Private Declare Function XYZArrayD Lib "zzzzzz" _
(ByRef Vari As Variant) _
As Long
Elle est en fait ecrite en (VB + VbAdvance) pour exposer les fonctions comme des API "normales", et je m'instruis en regardant le
contenu du SafeArray associe...

En fait:
je viens de trouver ce que je cherchais concernant le pointeur a mon tableau:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;199824


La seule chose qui me manque maintenant,
pour ce que j'avais envie d'apprendre aujourd'hui
ce sont les instructions .ODL pour creer le .TLB decrivant
Public Type myUDT
a As String
b As String
c As Long
d As Integer
End Type

Je viens de telecharger MkTypLib.Exe, GuidGen.exe, Midl.Exe (PlatformSDK),
donc je devrais avoir les outils?

Je repose la meme question en ouvrant un autre thread.

Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

Merci de poster les réponses au groupe afin d'en faire profiter à tous
"xx" wrote in message
news:3f868670$
> "Axel Guerrier [MS]" a écrit dans le message
de news:
> > Bonjour,
> >
> > Je crois que ce n'est pas possible:
>
> A part un parametre habile dans des .bas ou des .cls, j'avais pense a
creer mon propre .TLB.
> J'avais compris que , contrairement a .DLL qui doit etre present a la
compilation ET a l'execution, .TLB n'est necessaire qu'a la
> compilation.
> Si c'est le cas, quelqu'un pourrait-il poster le pas a pas pour creer le
.TLB pour mon exemple?
>
> Dans mon exemple [ByRef Vari as Variant], je n'ai en fait besoin que du
pointeur au variant, et je pourrais le remplacer par [Byval
> ptrVari as Long]
> Je n'ai trouve aucune instruction (VB ou API) pour obtenir ce pointeur???
>
>
> > The reason why it did not work above is that you declared the UDT type
in a
> >
> > Standard EXE project. In order for Visual Basic to add UDT to a
collection
> > or to
> >
> > convert a UDT type to a Variant type, the UDT type has to be declared as
> > "Public
> >
> > type" in a public class module, which means the class module has to be
in an
> >
> > ActiveX Dll project or an Active EXE project and its "Instancing
Property"
> > has to
> >
> > be "MultiUse" or "GlobalMultiUse". The reason behind the scene is that
if
> > you
> >
> > declare the UDT type in a "MultiUse" Class in an ActiveX Dll project,
then
> > the UDT
> >
> > type can be seen in the Type Library which is embedded in the ActiveX
Dll.
> > So OLE
> >
> > Automation Dll (oleaut32.dll) can read this information from the Type
> > Library and
> >
> > then could go ahead to process it. Please also pay attention to the fact
> > that the
> >
> > feature to convert a UDT type to a Variant type is a new feature of OLE
> > Automation
> >
> > and it is only supported in Visual Basic 6.0 (the oleaut32.dll must be
> > 2.30.4261.1
> >
> > or higher).
> >
> >
> > --
> > Axel GUERRIER
> > Microsoft France
> > --------------------
> > Merci de bien vouloir répondre à ce message dans le newsgroup où il a
été
> > posté. Je le consulte régulièrement.
> >
> > "xx" wrote in message
> > news:
> > > Bonsoir
> > >
> > > J'ai un UDT dont la structure est e.g.
> > > Public Type myUDT
> > > a As String
> > > b As String
> > > c As Long
> > > d As Integer
> > > End Type
> > > et une variable tableau
> > > Dim testArray() As myUDT
> > >
> > > J'ai d'autre part une fonction (fournie par un tiers)
> > > Private Declare Function XYZArrayD Lib "zzzzzz" _
> > > (ByRef Vari As Variant) _
> > > As Long
> > >
> > > QUESTION
> > > Comment/ou declarer mon UDT pour que l'instruction
> > > r = XYZArrayD(testArray)
> > > soit valide?
> > >
> > > __________
> > > J'ai essaye un certain nombre de combinaisons:
> > > (dans le Form, dans un module .bas, dans un module .cls) ...
> > > rien ne fonctionne.
> > > Le seul moyen que j'aie trouve est de declarer mon UDT dans le module
de
> > classe d'une .DLL, ce qui m'ennuie un peu.
> > >
> > > Y a-t'il un autre moyen
> > > (module .cls avec une combinaison particuliere de parametres)
> > > ???
> > >
> > >
> > > Merci
> > >
> > >
> >
> >
>
>