Sign in to follow this  
Followers 0
cppman

DllCall()

7 posts in this topic

is it possible to make a dll call to a dll written in C#?

My friend said, its not... but I was curious...

i've seen some console function that the dll was written in C#(i think)..

is it possible?

Share this post


Link to post
Share on other sites



Why wouldn't it be possible I think is the better question. Have you tried?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I beleive it's entirely possible as long it's it is a 'standard' format dll. As it says in the help file for dllcall, some dlls are a different standard and take aruments in a different way. Any particular case in mind?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

here is the reason my friend said it would'nt work:

"native dll's like the ones made in C++ are compiled down into machine code. machine code is ASM. C# dll's are compiled down to MSIL (I belive that is it). than when you run the dll or exe the .net CLR takes the MSIL and compiles it down to Machine Code. but the problem is the CLR doesn't compile the whole thing, it is inteligent. those are the reasons it doesn't work. you can call native from managed but not managed from native"...

and i just wanted to know if it'd work before i take the time to write a class library...

i did a quick test and does'nt seem to work...

c# code:

using System;
using System.IO;
namespace ClassLibrary3
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class Class1
    {
        public Class1()
        {
        
        }

        public void fwrite()
        {
            FileStream fs = new FileStream("file.txt", System.IO.FileMode.Open);
            StreamWriter sw = new StreamWriter("file.txt");
            sw.Write("test");
            sw.Close();
            fs.Close();
        }
    }
}

auto it code:

DllCall("test.dll", "none", "fwrite")

* I know someone wrote a C# dll and used it for some console functions im sure, but could'nt find that thread...

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Your friend is right, but he's also jumping the gun a little...

C# dll are compiled to MSIL only using the microsoft compiler (like in visual studio)

You need a different compiler (look at ngen at http://msdn2.microsoft.com/en-us/library/6t9t5wcf.aspx) to compile it into machine code like your friend said.

Edit: posted link wrong

Edited by evilertoaster

Share this post


Link to post
Share on other sites

I'm quite shure I have seen tools to make stub dll's to make calls to a C# "dll" possible. But there are probably a lot of constraints on what your aloved to do. I also think you would be better of using a COM dll and the COM interface/methodes in AutoIt.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Your friend is right, but he's also jumping the gun a little...

C# dll are compiled to MSIL only using the microsoft compiler (like in visual studio)

You need a different compiler (look at ngen at http://msdn2.microsoft.com/en-us/library/6t9t5wcf.aspx) to compile it into machine code like your friend said.

ah. That sounds more reasonable. Thanks.

ulten > Im not sure how to write a COM dll.. I've searched for tutorials but can't seem to find any..

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0