AutoHotkey Community

It is currently May 26th, 2012, 1:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 133 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 9  Next
Author Message
 Post subject:
PostPosted: May 16th, 2008, 11:46 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
This looks very cool. I'll have to give it a try. Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject: managed cpp
PostPosted: November 19th, 2008, 7:07 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2008, 9:44 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: passing variables
PostPosted: January 7th, 2009, 6:37 pm 
Offline

Joined: December 17th, 2008, 8:08 pm
Posts: 5
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:52 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
COM_Invoke_ doesn't accept DllCall type names - it accepts VT_* constants such as VT_BSTR=8.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 3:31 pm 
Offline

Joined: December 17th, 2008, 8:08 pm
Posts: 5
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 10:49 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
You've used:
Code:
COM_Invoke_(obj, "Test", "str", "filename")
Try:
Code:
COM_Invoke_(obj, "Test", 8, "filename")
Clearer now?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2009, 3:14 pm 
Offline

Joined: December 17th, 2008, 8:08 pm
Posts: 5
Yes it it clearer now...

I must be missing the sun from QLD.. lol

Thanks for you help Lexikos


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 3:53 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
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. :? 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 :D

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2009, 10:55 pm 
Offline

Joined: January 30th, 2009, 5:43 am
Posts: 12
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2009, 12:20 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 21st, 2009, 8:52 pm 
Can someone post an example for a simple plot using ZedGraph with the CLR?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2009, 1:22 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2009, 3:44 pm 
Here the challenge to create (one or several) samples of code which would show that modules capabilities :!:
OK, OK. A real low level BoBo attempt to get you interested ... :oops:

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

Please feed me :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2009, 7:41 pm 
Offline

Joined: June 29th, 2009, 8:09 pm
Posts: 28
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.


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 ... 9  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Klark92, Yahoo [Bot] and 21 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