Re: C#, Perl and COM objects (PerlNET / Win32::OLE)

2015-10-28 Thread Andy Grundman
Hi Miriam,

I wish I could be more helpful, but unfortunately most of the PerlNET
expertise here at ActiveState was with my predecessor, and I am still
coming up to speed on it. You are probably already aware of it, but I would
point you at this old book on PerlNET that may be of some help:
http://amzn.com/0130652067

If you could put together a simple test case that demonstrates the problem
you're having, I would be happy to take a look at it.

---
Andy Grundman
Lead Perl Language Developer, ActiveState
an...@activestate.com

On Thu, Oct 22, 2015 at 5:51 PM, Miriam Heinz 
wrote:

> Hello!
>
>
>
> I’m trying to pass a COM object from C# code to perl.
>
> At the moment I’m wrapping my perl code with PerlNET and I have defined a
> simple subroutine to pass objects from C# to the wrapped perl module.
>
> It seems that the objects I pass are not recognized as COM objects.
>
>
>
> An example:
>
> In C#, the ScriptControl is used to load a simple class from a file
> written in VBScript.
>
>
>
> var host = new ScriptControl();
>
> host.Language = "VBScript";
>
> var text = File.ReadAllText("TestScript.vbs");
>
> host.AddCode(text);
>
>
>
> dynamic obj = ost.Run("GetTestClass");
>
>
>
> What I get (`obj`) is of type `System.__ComObject`. When I pass it to my
> perl/PerlNET assembly and try to call method `Xyz()` in perl I get the
> following (runtime) exception:
>
>
>
> Can't locate public method Xyz() for System.__ComObject
>
>
>
> If, however, I do more or less the same thing in perl, it works. (In the
> following case, passing only the contents of my .vbs file as parameter.)
>
> I can even use the script control :
>
>
>
> sub UseScriptControl {
>
> my ($self, $text, $) = @_;
>
> my $script = Win32::OLE->new('ScriptControl');
>
> $script->{Language} = 'VBScript';
>
> $script->AddCode($text);
>
> my $obj = $script->Run('GetTestClass');
>
>
>
> $obj->Xyz();
>
> }
>
>
>
> Now, calling `Xyz()` on `obj` works without any problems.
>
>
>
> In both cases I use
>
> use strict;
>
> use Win32;
>
> use Win32::OLE::Variant;
>
>
>
>
>
> Now I’m trying to figure out what could cause this problem - and if I can
> solve it or if it is an issue related with the wrapping done by PerlNET.
>
> Or if I can maybe extract some information of the __ComObject for it to be
> identified correctly as COM object.
>
>
>
> I have to add that I posted on the PDK discussion site too (but didn’t get
> any response yet): http://community.activestate.com/node/18247
>
>
>
>
>
> I would greatly appreciate any help - or advise on where to look further.
>
> mihe
>
>
>
>
>
>
>
>
>
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


AW: C#, Perl and COM objects (PerlNET / Win32::OLE)

2015-10-28 Thread Miriam Heinz
> Rob (2015-10-23, sisyph...@optusnet.com.au):  
> This is a very inactive list, and you may well get no helpful response to

> your request. 

thank you for the information regarding this mailing list.
I thought I'd start here, as this seems to be a problem closely related to
the inner workings of PerlNET (-> ActiveState).

> Rob (2015-10-23, sisyph...@optusnet.com.au):  
> That being the case, I would suggest posting to perlmonks (   
> http://www.perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom ).  
> Another option might be a post to stackoverflow   
> http://stackoverflow.com/) - which is a forum I haven't tried, but one
that   
> seems to be fairly well attended.

> Jason (2015-10-23, kirk...@hotmail.com):  
>To that end, if you do post the question elsewhere would you post a link to
your post back here.  I would like to read the resolution.

I now added some details to my question at the community site:  
http://community.activestate.com/node/18247

And additionally posted my question to both PerlMonks and StackOverflow   
- since I'm not quite sure if this is more a perl or C#/.NET question:  
PerlMonks: 
http://www.perlmonks.org/?node_id=1146244  
StackOverflow: 
http://stackoverflow.com/questions/33388853/passing-a-com-object-from-c-shar
p-to-perl-using-perlnet

---
Some further details:

In the meantime I discovered that I can invoke methods on the passed COM
(`$obj`) object by using `InvokeMember` of ` System.Type ` which I initially
thought didn't work.

It does work if I specify *exactly* which overload I want to use and which
types I'm passing:

use PerlNET qw(typeof);

typeof($obj)->InvokeMember("Xyz", 
PerlNET::enum("System.Reflection.BindingFlags.InvokeMethod"), 
PerlNET::null("System.Reflection.Binder"), 
$obj, 
"System.Object[]"->new());


Using this approach would mean rewriting the whole wrapped perl module. And
using this syntax..

Now I am wondering if I am losing both the advantages of the dynamic keyword
in .NET 4.0 and the dynamic characteristics of perl (with Win32::OLE) by
using PerlNET with COM objects.

It seems like my preferred solution boils down to some way of mimicking the
behaviour of the `dynamic` keyword in C#/.NET 4.0.  
Or finding some way of converting the passed COM object to something that
will be recognized as compatible with Win32::OLE.

Thanks again,
Miriam

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: C#, Perl and COM objects (PerlNET / Win32::OLE)

2015-10-23 Thread sisyphus1
From: Miriam Heinz
Sent: Friday, October 23, 2015 8:51 AM
To: perl-win32-users@listserv.ActiveState.com
Subject: C#, Perl and COM objects (PerlNET / Win32::OLE)

> I would greatly appreciate any help - or advise on where to look further.

Hi Miriam,

This is a very inactive list, and you may well get no helpful response to 
your request.
That being the case, I would suggest posting to perlmonks ( 
http://www.perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom ).
Another option might be a post to stackoverflow 
http://stackoverflow.com/)  - which is a forum I haven't tried, but one that 
seems to be fairly well attended.

Cheers,
Rob


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: C#, Perl and COM objects (PerlNET / Win32::OLE)

2015-10-23 Thread Jason Kirkwood
You can hear crickets around here for a while now, but I learned so much from 
the Q on here that I hang around.  To that end, if you do post the question 
elsewhere would you post a link to your post back here.  I would like to read 
the resolution.
Thanks,Jason

> From: sisyph...@optusnet.com.au
> To: miriam.he...@itk-austria.com; perl-win32-users@listserv.ActiveState.com
> Subject: Re: C#, Perl and COM objects (PerlNET / Win32::OLE)
> Date: Sat, 24 Oct 2015 00:56:19 +1100
> 
> From: Miriam Heinz
> Sent: Friday, October 23, 2015 8:51 AM
> To: perl-win32-users@listserv.ActiveState.com
> Subject: C#, Perl and COM objects (PerlNET / Win32::OLE)
> 
> > I would greatly appreciate any help - or advise on where to look further.
> 
> Hi Miriam,
> 
> This is a very inactive list, and you may well get no helpful response to 
> your request.
> That being the case, I would suggest posting to perlmonks ( 
> http://www.perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom ).
> Another option might be a post to stackoverflow 
> http://stackoverflow.com/)  - which is a forum I haven't tried, but one that 
> seems to be fairly well attended.
> 
> Cheers,
> Rob
> 
> 
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


C#, Perl and COM objects (PerlNET / Win32::OLE)

2015-10-22 Thread Miriam Heinz
Hello!

 

I'm trying to pass a COM object from C# code to perl.  

At the moment I'm wrapping my perl code with PerlNET and I have defined a
simple subroutine to pass objects from C# to the wrapped perl module.  

It seems that the objects I pass are not recognized as COM objects.

 

An example:  

In C#, the ScriptControl is used to load a simple class from a file written
in VBScript.

 

var host = new ScriptControl();

host.Language = "VBScript";

var text = File.ReadAllText("TestScript.vbs"); 

host.AddCode(text);

 

dynamic obj = ost.Run("GetTestClass");

 

What I get (`obj`) is of type `System.__ComObject`. When I pass it to my
perl/PerlNET assembly and try to call method `Xyz()` in perl I get the
following (runtime) exception:

 

Can't locate public method Xyz() for System.__ComObject

 

If, however, I do more or less the same thing in perl, it works. (In the
following case, passing only the contents of my .vbs file as parameter.)

I can even use the script control :

 

sub UseScriptControl {

my ($self, $text, $) = @_;

my $script = Win32::OLE->new('ScriptControl');

$script->{Language} = 'VBScript';

$script->AddCode($text);

my $obj = $script->Run('GetTestClass');

 

$obj->Xyz();

}

 

Now, calling `Xyz()` on `obj` works without any problems.

 

In both cases I use 

use strict;

use Win32;

use Win32::OLE::Variant;

 

 

Now I'm trying to figure out what could cause this problem - and if I can
solve it or if it is an issue related with the wrapping done by PerlNET.

Or if I can maybe extract some information of the __ComObject for it to be
identified correctly as COM object.

 

I have to add that I posted on the PDK discussion site too (but didn't get
any response yet): http://community.activestate.com/node/18247

 

 

I would greatly appreciate any help - or advise on where to look further.

mihe

 

 

 

 

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs