How I can call my DLL? (C# net8)

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
xMaxrayx
Posts: 352
Joined: 06 Dec 2022, 02:56
Contact:

How I can call my DLL? (C# net8)

Post by xMaxrayx » 16 Apr 2024, 10:48

so I did this simple DLL in c# net8

Code: Select all

namespace consoleDLLtest
{
    public class ClassHello
    {
            public string Method()
        {
            return "Hi, this is from DLL";
        }
    }
}

How I can use it with AHK?
I did this but it doesn't work probably because it was bad coded xd

Code: Select all

#Requires AutoHotkey v2.0
Result := DllCall("ClassLibrary1" ,"Str" , "Method" , )
MsgBox Result
I got this EROR
Error: Call to nonexistent function.

▶ 003: Result := DllCall("ClassLibrary1" ,"Str" , "Method" , )
004: MsgBox(Result)
007: testVariable := unset

The current thread will exit.

sorry I'm net at learning DLL stuff.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

User avatar
andymbody
Posts: 1034
Joined: 02 Jul 2017, 23:47

Re: How I can call my DLL? (C# net8)

Post by andymbody » 16 Apr 2024, 20:36

Just a guess... but does the method need to be static? (I know nothing about DLL structure, but have coded C#)

User avatar
Seven0528
Posts: 497
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: How I can call my DLL? (C# net8)

Post by Seven0528 » 16 Apr 2024, 21:24

 Except for User32.dll, Kernel32.dll, ComCtl32.dll, and Gdi32.dll, you must not omit the DllFile.
If unsure, provide the full path of the DllFile along with the function name. For example, C:\DllDir\DLLFile.dll\Function.
For more information, please read the parameters section of the DllCall documentation.

I actually have experience creating DLLs in C++ and applying them in AHK, but I haven't tried it in C#.
Therefore, I'm unable to offer advice on creating DLLs in C#. Sorry.
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

User avatar
xMaxrayx
Posts: 352
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I can call my DLL? (C# net8)

Post by xMaxrayx » 17 Apr 2024, 02:53

andymbody wrote:
16 Apr 2024, 20:36
Just a guess... but does the method need to be static? (I know nothing about DLL structure, but have coded C#)
IDK I didn't learn about void, static stuff yet but I did it

Code: Select all

namespace consoleDLLtest_v2
{
    public class ClassHello_v2
    {


        public static string Hi()
        {
            return "Hi, this is from DLL";
        }

        public string Goodboey()
        {
            return "good bye";
        }


    }
}
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

User avatar
xMaxrayx
Posts: 352
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I can call my DLL? (C# net8)

Post by xMaxrayx » 17 Apr 2024, 03:02

Seven0528 wrote:
16 Apr 2024, 21:24
 Except for User32.dll, Kernel32.dll, ComCtl32.dll, and Gdi32.dll, you must not omit the DllFile.
If unsure, provide the full path of the DllFile along with the function name. For example, C:\DllDir\DLLFile.dll\Function.
For more information, please read the parameters section of the DllCall documentation.

I actually have experience creating DLLs in C++ and applying them in AHK, but I haven't tried it in C#.
Therefore, I'm unable to offer advice on creating DLLs in C#. Sorry.
even if it was from relative link?

I see , I read that .Net DLL not same as DLL and they are callable only with Net languages but there are workaround, and I found some stuff are only work with old Net Framwork (only windows) and not with current .Net (cross-patform).

I will try re-search more.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: How I can call my DLL? (C# net8)

Post by lexikos » 23 Apr 2024, 04:00

Recent versions of .NET have their own hosting API which differs too much from the old one for the old scripts to work.

If you can create a .dll which can be called from C (i.e. a dll with unmanaged exports), you can call it with DllCall. C++ can mix managed and unmanaged code in older .NET Framework versions, so I assume it can be done in .NET 8 as well. I don't think it can be done in C#, but I haven't tried and I very rarely touch C#.

I assume you can create COM components with .NET 8. A properly registered component can be instantiated with ComObject.

Post Reply

Return to “Ask for Help (v2)”