Strange ,,,,,,
However please note the following
> Then I put in the vbs script then statement:
>
> dllobject.Importa comobjectname
would be
dllobject.Importa(comobjectname) ' i asume comobjectname is an initialized
com object of type VISUMLIB.Visum
wich must also registred on the target system in the system32 directory or
in the GAC ( note that the assembly path wil not work as the Windows
scripting host is the actuall caller in this situation )
Are you sure the VISUMLIB.Visum is initialized in the VBS file ? cause it
looks to me like the VB program is receiving an unitialized Object type wich
is valid for COM as VBS works with variants wich are equal to .Net Object
types
HTH
Michel Posseth [MCP]
> Hi to all!
> I created a VB.Net COM DLL which I can use in VBScript.
[quoted text clipped - 90 lines]
>
> M.G.
Sorry the correct title is "VB.NET COM DLL from a VBScript "
kind regards
M.G.
MicheleG - 08 May 2008 21:18 GMT
Thank you for your answer!
I tried to modify the public sub:
Public Sub Importa(ByRef o As Object)
MsgBox(obj.ToString())
MsgBox(Microsoft.VisualBasic.Information.TypeName(o))
Dim VisumCl As IVisum = o
End Sub
The reselts are:
MsgBox(obj.ToString()) ---> "System.__ComObject"
MsgBox(Microsoft.VisualBasic.Information.TypeName(o)) ----->
"IVisum"
Dim VisumCl As IVisum = o ---> same exception: cannot cast from
COM object of type "System.__ComObject" to interface type
"VISUMLIB.IVisum".
This is very strange since from all above it seems that:
"System.__ComObject" is the type of COM wrapper and
"VISUMLIB.IVisum" is the actual type behind the COM wrapper.
So a cast with "Dim VisumCl As IVisum = o" should be possible since
the System.__ComObject class is specifically designed to work with COM
object,
and it is always able to performe a QueryInterface to any COM
interfaces that are implemented by an object. So casting the specific
interface (as long as they
are implemented on the object) should be succesful.
Since in my development machine all works correctly I think it could
be a different problem behind the code.
To tell you everything I built the dll from a COM-class template.
VB.NET produced 6 files. Among this I copied the files:
ClassLibrary1.dll, ClassLibrary1.tlb, Interop.VISUMLIB.dll
in a new computer (together with vbs file I need for executing all),
and registered the assembly with:
"regasm.exe ClassLibrary1.dll /codebase /tlb:ClassLibrary1.tlb"
I used /codebase because I created a Strong Name for my
ClassLibrary1.dll with a AssemblyKeyFile
(now I don't need to register all in the GAC)
It give error!
Can you suggest me something?
About your question "Are you sure the VISUMLIB.Visum is initialized in
the VBS file"
the answer is that I don't need to declare nor initialize such object
because the vbs file is execute
inside a software (imagine like a script inside autocad or Arcgis or
like in Access VBA..) so when
I write Visum in vbs it is an already known object that I can use or
pass to a method of an external com-dll.
With Visual Basic 6 there weren't problem. And a friend of mine tried
the same code above in C#.NET and works
correctly.
Michel Posseth [MCP] - 09 May 2008 15:07 GMT
> Thank you for your answer!
>
[quoted text clipped - 53 lines]
> the same code above in C#.NET and works
> correctly.
The new regasm doesn`t register the assembly location
with a execytable this is not a problem as a executable will resolve the
assembly path and alternatively the system32 directory
to be more clear
if you want to run an .Net COM Object on a PHP page you must copy the .Net
COM dll to the Apache bin directory ( as PHP is run in this context ) or
isntall the assembly to the GAC
VBS files are run by the WSH wich is located in system32 so i guess copying
the LIBS to the system32 will solve your prpoblem
with C# you should have the same problem ( unless he is using this from a C#
prog and not from a VBS file )
HTH
Michel