AutoHotkey Community

It is currently May 27th, 2012, 12:30 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 133 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 9  Next
Author Message
 Post subject:
PostPosted: July 15th, 2009, 10:45 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I wrapped it for symmetry. I don't suppose it has much use.
Quote:
It is typically unnecessary to call the Stop method, because the code stops executing when the process exits.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2009, 1:46 am 
Offline

Joined: May 22nd, 2009, 2:48 pm
Posts: 12
zip library for dotnet from http://dotnetzip.codeplex.com/

Code:
CLR_Start()

Zip := CLR_LoadLibrary("Ionic.Zip.dll")
ZipFile  := CLR_CreateObject(Zip,"Ionic.Zip.ZipFile")

com_invoke(zipfile, "password=", "1234")
com_invoke(zipfile, "addfile", "Contents.txt")
com_invoke(zipfile, "adddirectory", A_scriptdir "\DotNetZip-v1.8")

com_invoke(Zipfile, "name=", A_scriptdir "\xxx.zip")
com_invoke(zipfile,"save")

com_release(zipFile)
msgbox, compressed done!

zipFile  := CLR_CreateObject(Zip,"Ionic.Zip.ZipFile")
com_invoke(zipfile, "password=", "1234")
com_invoke(zipFile, "initialize", A_scriptdir "\xxx.zip" )
filecreatedir, %A_scriptdir%\xxx
com_invoke(zipfile,"extractall", A_scriptdir "\xxx")

msgbox, extracted in xxx folder

com_release(zipFile)
com_release(Zip)

exitapp




the script is working ok, but unfortunatley problemes are

1)
it's not compatible with COM_L.
When calling CLR_createobject, com_l throws an error message.

2)

And I notice you made an explicit statment that the "static" method can't be called, which I don't know at all.
but from what i have tested so far, I guess that it means like system.Net.Dns class's gethostname method
'cause dns class has no contruction method so i couldn't create object for it and therefore couldn't call Gethostname method.
or is it possible to call dns.gethostname method with CLR lib?


3)
and finally could it be possible to make dot syntax possible as in Autohotkey_L and Com_L

possible or not, thanks for the script and Autohotkey_L.
Com_L and autohotkey_L combination is really fantastic.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2009, 3:49 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
fasto wrote:
it's not compatible with COM_L.
COM_L has been updated to fix this issue.
Quote:
When calling CLR_createobject, com_l throws an error message.
I'm going to assume you mean that CLR.ahk was throwing an error mesage about number of parameters passed to COM_CreateObject. If that's not correct, please give more detail.
Quote:
And I notice you made an explicit statment that the "static" method can't be called,
Static methods can't be called with COM_Invoke because it requires an object to invoke. Static methods can be called, and in fact are called internally by CLR.ahk. It is difficult enough that I would recommend using embedded C# or VB in your scripts (as in the MessageBox.Show example).
Quote:
and finally could it be possible to make dot syntax possible as in Autohotkey_L and Com_L
You may use COM_Enwrap to wrap any pointer which works with COM_Invoke, including those returned by CLR_CreateObject.

I tested briefly with the following (and updated COM_L):
Code:
CLR_Start()
lib := CLR_LoadLibrary("mscorlib")
obj := COM_Enwrap(CLR_CreateObject(lib,"System.Object"))
COM_Release(lib)

MsgBox % obj.ToString()
A "select few" types have ProgID's (keys in HKEY_CLASSES_ROOT), so can be simply instantiated with COM_CreateObject:
Code:
obj := COM_CreateObject("System.Collections.ArrayList")
MsgBox % obj.ToString()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2009, 4:01 pm 
Offline

Joined: May 22nd, 2009, 2:48 pm
Posts: 12
Quote:
COM_L has been updated to fix this issue.


At first I couldn't decide whether it is appropritate to ask here or COM Thread.
But since I had some other questions about CLR, I came here. Thanks for the request.

Quote:
I would recommend using embedded C# or VB in your scripts (as in the MessageBox.Show example)


OK, I tried that. It's working flawlessly though it's a bit tricky for me.

Quote:
You may use COM_Enwrap to wrap any pointer which works with COM_Invoke.


I saw that function name before but until now i didn't know what the heck it is for. :lol:
Now I get it!

Some silly requests and sweet, detailed guides from the master!

Thanks, Lexikos


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2009, 8:28 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
How do I enumerate a System.Object[]? I have tried this (using COM_L):
Code:
Loop, % array.Length
   myArray%A_Index% := array.GetValue(A_Index-1)

But it doesn't work...

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 2:05 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I wrote:
Arrays must be in SafeArray format.
Source: post


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 11:30 am 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thanks, Lexikos.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2010, 10:55 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
CLR_CompileAssembly wasn't working in COM_L/U, so I've uploaded a new version of CLR with the following changes:
  • AutoHotkey_L or AutoHotkeyU required. (However, the old version is still available.)
  • CLR_LoadLibrary, CLR_CreateObject, and CLR_CompileC#/VB return a COM wrapper object.
  • It should not be necessary to call CLR_Start explicitly.
Note that in simple cases, Assembly.CreateInstance(TypeName) can be used in place of CLR_CreateObject:
Code:
CorLib := CLR_LoadLibrary("mscorlib")
stk := CorLib.CreateInstance("System.Collections.Stack")
que := CorLib.CreateInstance("System.Collections.Queue")
...
Code:
CLR_CompileC#("class c{public void F(){System.Windows.Forms.MessageBox.Show(""Hello, world!"");}}" ,"System.dll|System.Windows.Forms.dll").CreateInstance("c").F()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2010, 1:44 pm 
Offline

Joined: April 18th, 2010, 11:33 am
Posts: 159
Hi Lexikos and all!

Im fairly new to C# and really want to learn it
(and someday write some dll to use with ahk)

Just for fun, a few days ago i followed a tutorial on how to create a C# DLL. I compiled it with C#2008Express and tried to DllCall it. But it didnt work(returned Errorlevel=-4 Function not found). Even the disasm didnt show any exported functions. I considered that the dll was to use with only C# as a class lib(i tried it with c# and obviously it worked).

So With this CLR for Ahk, will I be able to call functions from C# dlls?

edit: I cant call mscorlib.dll

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2010, 3:59 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
CyberGeek wrote:
edit: I cant call mscorlib.dll
Post code if you're having difficulty. It sounds like you're still trying to use DllCall, in which case you wouldn't actually be using this script.

Typically you'll need to load an assembly (CLR_LoadLibrary), create an object from it (CLR_CreateObject), then invoke the object (COM_Invoke). Make sure you're using the appropriate version of CLR.ahk for your version of AutoHotkey. That is, CLR for standard AHK or CLR_L for AutoHotkey_L (allows "dot" syntax and automatic cleanup). For instance:
Code:
; CLR or CLR_L
CLR_Start()  ; one-time init
mscorlib := CLR_LoadLibrary("mscorlib")
cookie := CLR_CreateObject(mscorlib, "System.Object")
MsgBox % COM_Invoke(cookie, "ToString")
COM_Release(cookie)
Code:
; CLR_L only
mscorlib := CLR_LoadLibrary("mscorlib")
cookie := CLR_CreateObject(mscorlib, "System.Object")
MsgBox % cookie.ToString()
cookie := ""  ; optional in this case


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2010, 10:32 am 
Offline

Joined: April 18th, 2010, 11:33 am
Posts: 159
Thx for the reply,
but how can i use Math.Tan method (http://msdn.microsoft.com/en-us/library/system.math.tan.aspx)

Code:
CLR_Start()  ; one-time init
mscorlib := CLR_LoadLibrary("mscorlib.dll")
cookie := CLR_CreateObject(mscorlib, "Math.Tan")
MsgBox % COM_Invoke(cookie, "5")
COM_Release(cookie)

#Include clr.ahk

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2010, 5:38 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
CLR_CreateObject is only for instantiating a class. Static methods like Math.Tan are difficult to call via COM as it requires...
  • getting an instance of the Type object representing the type which contains the method,
  • initializing a SAFEARRAY of VARIANTs containing parameters,
  • calling the appropriate overload of Type.InvokeMember via a complicated DllCall, and
  • interpreting the result VARIANT as necessary.
For instance, this is a slightly modified (for readability) extract from CLR.ahk:
Code:
; pApp is a pointer to an AppDomain as returned by CLR_GetDefaultDomain()
p_App := COM_QueryInterface(pApp,"{05F696DC-2B29-3663-AD8B-C4389CF2A713}")
...
; Get typeof(Assembly) for calling static methods. (p_App->GetType()->Assembly->GetType())
DllCall(NumGet(NumGet(p_App+0)+40),"uint",p_App,"uint*",p_Type)
DllCall(NumGet(NumGet(p_Type+0)+80),"uint",p_Type,"uint*",p_Asm)
COM_Release(p_Type)
DllCall(NumGet(NumGet(p_Asm+0)+40),"uint",p_Asm,"uint*",p_Type)
COM_Release(p_Asm)

; Initialize VARIANTs & SAFEARRAY(VARIANT) for method args.
VarSetCapacity(vArg,16,0), NumPut(8,vArg), NumPut(psLib,vArg,8)
VarSetCapacity(vRet,16,0)
VarSetCapacity(rArgs,24,0), NumPut(1,NumPut(&vArg,NumPut(16,NumPut(1,rArgs))+4))

; Attempt to load from file.  (Call Assembly.LoadFrom().)
hr:=DllCall(NumGet(NumGet(p_Type+0)+228),"uint",p_Type
    ,"uint",COM_SysString(ws,"LoadFrom"),"int",0x118
    ,"uint",0,"int64",1,"int64",0,"uint",&rArgs,"uint",&vRet)
The equivalent C# would be:
Code:
Assembly.LoadFrom(sLibrary)

It's generally easier to use C#.
Code:
helper_code=
(
class helper {
    public double Tan(double a) {
        return System.Math.Tan(a);
    }
}
)
CLR_Start()
if !asm := CLR_CompileC#(helper_code, "")
    ExitApp
hlp := CLR_CreateObject(asm, "helper")
MsgBox % COM_Invoke(hlp, "Tan", 1.0)
MsgBox % COM_Invoke(hlp, "Tan", 0.5)

...or in this case, AutoHotkey. :P
Code:
SetFormat, FloatFast, 0.14  ; for results closer to the above
MsgBox % Tan(1.0)
MsgBox % Tan(0.5)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2010, 12:29 pm 
Offline

Joined: April 18th, 2010, 11:33 am
Posts: 159
I dont really wanna create Assemblies to use with C#
instead the dll should have exported functions

in Borland Delphi, its much easier
i downloaded Delphi7 and built my first dll using an example and i can use it in ahk with DLLCALL

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2010, 2:25 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
CyberGeek wrote:
I dont really wanna create Assemblies to use with C#
I wasn't suggesting you do. Any assembly you create with CLR.ahk must be written in C# or VB.Net anyway. My example shows how to use C# in AHK to make static methods more accessible to AHK.
Quote:
instead the dll should have exported functions
Exporting functions in a way that allows them to be called by DllCall requires a bit of work and does not involve CLR.ahk. If you want to use CLR-based objects (i.e. not just flat functions) in AHK, use CLR.ahk but avoid static methods.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ironahk
PostPosted: May 29th, 2010, 7:02 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Lexikos,
Can we expect to see an IronAhk_L ?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 133 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 9  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cristi®, Google Feedfetcher, tidbit and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group