AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

.NET Framework Interop
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tic



Joined: 22 Apr 2007
Posts: 1424

PostPosted: Fri May 16, 2008 10:46 am    Post subject: Reply with quote

This looks very cool. I'll have to give it a try. Thanks
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 308
Location: Houston, TX

PostPosted: Wed Nov 19, 2008 6:07 am    Post subject: managed cpp Reply with quote

Thanks for this useful CLR interop...

I tried a simple modification to get cpp managed code, but
This doesn't seem to work:
Code:

cpp =
(
#using <mscorlib.dll>
using namespace System;
void main() {
   Console::WriteLine(S"Hello World using Managed Extensions for C++!");
}
)
CLR_Start()
asm := CLR_CompileCPP(cpp, "System.dll | mscorlib.dll", 0, "cpptest.exe")
return

CLR_CompileCPP(Code, References, pAppDomain=0, FileName="", CompilerOptions="")
{
    return CLR_CompileAssembly(Code, References
        , "System", "Microsoft.VisualC.CppCodeProvider", pAppDomain
        , FileName, CompilerOptions)
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 4367
Location: Qld, Australia

PostPosted: Wed Nov 19, 2008 8:44 am    Post subject: Reply with quote

First, the ProviderAssembly parameter of CLR_CompileAssembly must be the assembly which contains the code provider type. CppCodeProvider is in cppcodeprovider.dll, not system.dll.

Second, cppcodeprovider.dll is included in the Visual Studio install directory, under Common7\IDE\PublicAssemblies. ProviderAssembly must be a full path in this case. It is not included by the .NET Framework.

Third, CppCodeProvider
Quote:
Provides a base class for a C/C++ implementation of CodeDomProvider.
Presumably you should use CppCodeProvider7.

Finally, CppCodeProvider and CppCodeProvider7 do not seem to support CreateCompiler() or CompileAssemblyFromSource(). Either one will set _hResult_ to E_INVALIDARG, despite CreateCompiler's complete lack of arguments. Looks like you're out of luck.
Back to top
View user's profile Send private message Visit poster's website
vjc



Joined: 17 Dec 2008
Posts: 5

PostPosted: Wed Jan 07, 2009 5:37 pm    Post subject: passing variables Reply with quote

Thanks for the cool CLR functionality...

I am having trouble passing an external variable to the test sub. I am wanting to pass the filename that the user picks from the fileselectfile call but all I get is a blank message box. I know that it is something simple that I am doing wrong, but for the life of me I just can't see it.

Code:
#Include CLR.ahk
#Include COM.ahk


FileSelectFile, filename, 3,, Open the desired Application, Control Builder Files (*.prj)

vb =
(
    Imports System.Windows.Forms
   
    Class Control_Open
      
      Private cb AS CONTROLBUILDERLib.CBOpenIf
      
      Public Sub Test(ByVal filename As String)
         Dim owner As IWin32Window
         
         'cb = NEW CONTROLBUILDERLib.CBOpenIf
         MessageBox.Show(owner, filename)
         
        End Sub
      
    End Class
)

CLR_Start()

asm := CLR_CompileVB(vb, "System.dll | System.Windows.Forms.dll | Interop.CONTROLBUILDERLib.dll")
obj := CLR_CreateObject(asm, "Control_Open")

COM_Invoke_(obj, "Test", "str", "filename")
COM_Release(obj), COM_Release(asm)
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4367
Location: Qld, Australia

PostPosted: Wed Jan 07, 2009 9:52 pm    Post subject: Reply with quote

COM_Invoke_ doesn't accept DllCall type names - it accepts VT_* constants such as VT_BSTR=8.
Back to top
View user's profile Send private message Visit poster's website
vjc



Joined: 17 Dec 2008
Posts: 5

PostPosted: Thu Jan 08, 2009 2:31 pm    Post subject: Reply with quote

Ok, I am still confused...

Is it possible to pass a variable(a string value) to the message box in the test sub so that it displays that string value?

Or should I be using a different method?
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4367
Location: Qld, Australia

PostPosted: Thu Jan 08, 2009 9:49 pm    Post subject: Reply with quote

You've used:
Code:
COM_Invoke_(obj, "Test", "str", "filename")
Try:
Code:
COM_Invoke_(obj, "Test", 8, "filename")
Clearer now?
Back to top
View user's profile Send private message Visit poster's website
vjc



Joined: 17 Dec 2008
Posts: 5

PostPosted: Fri Jan 09, 2009 2:14 pm    Post subject: Reply with quote

Yes it it clearer now...

I must be missing the sun from QLD.. lol

Thanks for you help Lexikos
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Thu Jan 22, 2009 2:53 pm    Post subject: Reply with quote

Lexikos.....
We all know I'm an idiot. My many rambling posts prove it. So given the context of who I am. I hope you will accept my sincere appreciation for CLR which I hadn't previously seen or searched for such. I hadn't even dared hope it was actually possible. I wouldnt have seen it at all except Sean mentioned it here. So as an avid Sean zealot, I looked it up. VB.net was previously my poison of choice and when my employer announced a position using AHK I abandoned it. Thank you I have been half doing with COM and AHK some fairly complex tasks that for the sake of existing documentation is just easier in .net. Now I get the ability to bridge the final gap.
It is a sad little world I exist in when I can use AHK but I cannot download or install Visual Studio Express suite. Even tho it is perfectly acceptable to use COM or any code I can store directly within an ahk file. Confused Yea I know it makes absolutely no sense to me either.

Again if you can find it in yourself to accept the gratitude of a rambling idiot
Thank you Very Happy
_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
Leonidas225



Joined: 30 Jan 2009
Posts: 12

PostPosted: Wed Feb 04, 2009 9:55 pm    Post subject: Reply with quote

i have some trouble to call this function:
Code:

;the c# code
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace SNGEGT
{
    class ICM
    {
private void handFromIndex(int index, int[] cards)
        {
            //for (int i = 0; i < 169; i++)
            //{
            for (int a = 0; a < 13; a++)
            {
                for (int b = 0; b < 13; b++)
                {
                    if (indexArray[a, b] == index)
                    {
                        // suited
                        if (a > b)
                        {
                            cards[0] = a;
                            cards[1] = b;
                        }
                        else if (b > a)
                        {
                            cards[0] = b;
                            cards[1] = a + 13;
                        }
                        else if (a == b)
                        {
                            cards[0] = a;
                            cards[1] = b + 13;
                        }
                        else
                            Debug.WriteLine("Nyt joku kusi pahasti korteissa!");
                        //Debug.WriteLine("{0} = [{1}][{2}]", i, a, b);
                        //Debug.WriteLine("{0} = [{1}][{2}]", index, a, b);
                        return;
                    }
                }
            }
           
        }
   }
}



Code:
#Include CLR.ahk
#Include COM.ahk

CLR_Start()

asm := CLR_LoadLibrary("SNGEGT.dll")
obj := CLR_CreateObject(asm, "SNGEGT.ICMClass")

hand := COM_Invoke(obj, "handFromIndex", "5")  ;problem

COM_Release(obj)
COM_Release(asm)


cards is an array but i have no idea how to handle it.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4367
Location: Qld, Australia

PostPosted: Thu Feb 05, 2009 11:20 am    Post subject: Reply with quote

There are few problems with your post:
  • indexArray is not defined.
  • handFromIndex is private, and therefore not accessible to the script.
  • ICMClass does not exist, only ICM.
Arrays must be in SafeArray format. You must replace COM_Invoke with COM_Invoke_ in order to indicate that the parameter is an array. An array of int would be VT_ARRAY|VT_I4; that is, 0x2003. Most primitive types may be passed as VT_BSTR:=8, but objects must be passed as VT_DISPATCH:=9.

The simplest way to create the array is probably via .NET. For instance:
Code:
C# =
(
using System;
using System.Windows.Forms;

namespace SNGEGT
{
    class ICM
    {
        public int cardFromIndex(int index, int[] cards) {
            return cards[index];
        }
        public int[] deal() {
            return new int[] { 3, 1, 2 };
        }
   }
}
)

CLR_Start()

asm := CLR_CompileC#(C#, "System.dll | System.Windows.Forms.dll")
obj := CLR_CreateObject(asm, "SNGEGT.ICM")

cards := COM_Invoke(obj, "deal")
Loop 3
    MsgBox % COM_Invoke_(obj, "cardFromIndex", 8, A_Index-1, 0x2003, cards)

COM_Release(obj)
COM_Release(asm)
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Tue Apr 21, 2009 7:52 pm    Post subject: Reply with quote

Can someone post an example for a simple plot using ZedGraph with the CLR?
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 4367
Location: Qld, Australia

PostPosted: Wed Apr 22, 2009 12:22 pm    Post subject: Reply with quote

I know nothing of ZedGraph, but I think you're much more likely to find success by searching for a C# (or VB) example and using that via CLR_CompileC# (or CLR_CompileVB). If you have any problems invoking the C# (or VB) code, post what you've tried.
Back to top
View user's profile Send private message Visit poster's website
BoBoł
Guest





PostPosted: Thu May 21, 2009 2:44 pm    Post subject: Reply with quote

Here the challenge to create (one or several) samples of code which would show that modules capabilities Exclamation
OK, OK. A real low level BoBo attempt to get you interested ... Embarassed

[Exchange Web Services - Operations/XML Elements]
[Independentsoft - Exchange Web Services ...]

Please feed me Sad
Back to top
yourbuddypal



Joined: 29 Jun 2009
Posts: 23

PostPosted: Wed Jul 15, 2009 6:41 pm    Post subject: Reply with quote

Great stuff you have here, I love it. I had the idea to interop to my dlls while commuting to work this morning, and pulled this up in no time. Excellent work.

Looking over your documentation, I have a question:

Quote:
CLR_Stop()

Stops the Common Language Runtime. Once stopped, it cannot be reinitialized into the same process.


Why would you ever want to use this method, if you can't reinitialize the CLR in your script? Or did I misinterpret something there? I was considering starting the CLR only to communicate with my DLL in certain intervals and then stopping it after completing that operation.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group