Page 1 of 1
How I can call my DLL? (C# net8)
Posted: 16 Apr 2024, 10:48
by xMaxrayx
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.
Re: How I can call my DLL? (C# net8)
Posted: 16 Apr 2024, 20:36
by andymbody
Just a guess... but does the method need to be static? (I know nothing about DLL structure, but have coded C#)
Re: How I can call my DLL? (C# net8)
Posted: 16 Apr 2024, 21:24
by Seven0528
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.
Re: How I can call my DLL? (C# net8)
Posted: 17 Apr 2024, 02:53
by xMaxrayx
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";
}
}
}
Re: How I can call my DLL? (C# net8)
Posted: 17 Apr 2024, 03:02
by xMaxrayx
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.
Re: How I can call my DLL? (C# net8)
Posted: 23 Apr 2024, 04:00
by lexikos
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.