I made dll file myself. There is a function in the file ,which is a function without parameter like ScreenShot() this function
I want to call this fucntion by means of DllCall
At this situation, How do i enter a parameters?
please give me a some advice
parameter of DllCall() when dll's function does not have a parameter
Re: parameter of DllCall() when dll's function does not have a parameter
I'm not sure if your DllCall would need Cdecl.
I'm not sure if DllCall needs a return type if no value is returned.
So perhaps one of these:
Here are some DllCall examples:
I'm not sure if DllCall needs a return type if no value is returned.
So perhaps one of these:
Code: Select all
DllCall("DllFile\ScreenShot")
DllCall("DllFile\ScreenShot", "Int")
DllCall("DllFile\ScreenShot", "Ptr")
DllCall("DllFile\ScreenShot", "Cdecl Int")
Code: Select all
;e.g. 2 parameters:
;Result := DllCall("DllFile\Function", Type1,Arg1, Type2,Arg2, ReturnType)
;Result := DllCall("DllFile\Function", Type1,Arg1, Type2,Arg2) ;you can omit ReturnType if it's Int
;e.g. 0 parameters:
;Result := DllCall("DllFile\Function", ReturnType)
;Result := DllCall("DllFile\Function") ;you can omit ReturnType if it's Int
vRet := DllCall("user32\EmptyClipboard")
;vRet := DllCall("user32\LockWorkStation") ;same as pressing Win+L
vTickCount := DllCall("kernel32\GetTickCount", UInt)
vLastError := DllCall("kernel32\GetLastError", UInt)
vPIDAhk := DllCall("kernel32\GetCurrentProcessId", UInt)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: parameter of DllCall() when dll's function does not have a parameter
Thank you for your answer
I've tried all the choices you've made.
But Whichever i choose, it doesn't work.
My dll file was made in C# and it worked well when I tried to use it directly in C#
And My dll file is located in working directory
My Function of my dll file returns String type variable like
/
string a = "abcdef123456";
return a;
/
Below are the things I tried.
dllcall("Mydll.dll\ScreenShot",)
dllcall("Mydll.dll\ScreenShot","Str")
dllcall("Mydll.dll\ScreenShot","Cdecl Str")
dllcall("Mydll.dll\ScreenShot","Ptr")
dllcall("Mydll.dll\ScreenShot","Cdecl Str")
dllcall("Mydll.dll\ScreenShot","AStr")
dllcall("Mydll.dll\ScreenShot","WStr")
dllcall("Mydll.dll\ScreenShot","Cdecl AStr")
dllcall("Mydll.dll\ScreenShot","Cdecl WStr")
I've tried all the choices you've made.
But Whichever i choose, it doesn't work.
My dll file was made in C# and it worked well when I tried to use it directly in C#
And My dll file is located in working directory
My Function of my dll file returns String type variable like
/
string a = "abcdef123456";
return a;
/
Below are the things I tried.
dllcall("Mydll.dll\ScreenShot",)
dllcall("Mydll.dll\ScreenShot","Str")
dllcall("Mydll.dll\ScreenShot","Cdecl Str")
dllcall("Mydll.dll\ScreenShot","Ptr")
dllcall("Mydll.dll\ScreenShot","Cdecl Str")
dllcall("Mydll.dll\ScreenShot","AStr")
dllcall("Mydll.dll\ScreenShot","WStr")
dllcall("Mydll.dll\ScreenShot","Cdecl AStr")
dllcall("Mydll.dll\ScreenShot","Cdecl WStr")
Re: parameter of DllCall() when dll's function does not have a parameter
Code: Select all
dllcall("Mydll.dll\ScreenShot",)
I don't know whether you can use C# dlls or not, or whether you need the full path of the dll file or not.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: parameter of DllCall() when dll's function does not have a parameter
yes i also tried that
The way I made C# dll file is as below. it is made in project of class library.
After building the scripts, the dll file is created in the debug folder. I used it
and when i called the my dll file, i also locaeted my autohotkey file in folder where dll file exist
and I've also even filled out every path when i called dll file
Am i wrong?
The way I made C# dll file is as below. it is made in project of class library.
After building the scripts, the dll file is created in the debug folder. I used it
and when i called the my dll file, i also locaeted my autohotkey file in folder where dll file exist
and I've also even filled out every path when i called dll file
Am i wrong?
Code: Select all
namespace Mydll
{
public class MyClass
{
public string MyFunct()
{
string res = "0E154324D324321"; //I made a very simple function for testing purpose
return res;
}
}
}
Re: parameter of DllCall() when dll's function does not have a parameter
I don't know if you can use dlls like that. I stated all of the things I knew re. DllCall that might be helpful, and to give this thread a bump. I hope that someone can come along who has more to contribute re. DllCall.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: parameter of DllCall() when dll's function does not have a parameter
Are you loading the dll? If not, when you call the function in the dll, ahk loads the dll, and when it returns, ahk unloads the dll, which (I assume) will free any memory allocated by the dll, hence the string is freed.
I would try the following:
1) Load the dll
2) Make an explicit allocation in the dll, eg, char* res = malloc(x); (or whatever allocation functions c# uses)
3) Return the pointer (res), use strget(res) to copy the string to the script, then use free(res) (again use what is proper for c#). You could also make a function in the dll which you pass the pointer to when you are done with it, which ofc then should free it.
4) Unload the dll when you are done.
Alternatively, try CLR.ahk,
Cheers.
I would try the following:
1) Load the dll
2) Make an explicit allocation in the dll, eg, char* res = malloc(x); (or whatever allocation functions c# uses)
3) Return the pointer (res), use strget(res) to copy the string to the script, then use free(res) (again use what is proper for c#). You could also make a function in the dll which you pass the pointer to when you are done with it, which ofc then should free it.
4) Unload the dll when you are done.
Alternatively, try CLR.ahk,
Code: Select all
#include CLR.ahk
myDll=
(
public class MyClass
{
public string MyFunct()
{
string res = "0E154324D324321";
return res;
}
}
)
asm := CLR_CompileC#(myDll)
obj := CLR_CreateObject(asm, "MyClass")
msgbox % obj.MyFunct()
Re: parameter of DllCall() when dll's function does not have a parameter
OMG!! It's running! Thank you very much!! However, when i applied my real dll file, not a test dll file, an error occured.
contents of error is next
1. be unable to find 'Size' , 'Bitmap' , 'Graphic' , 'MemoryStream' , 'Image' format or name of namespace. Check if there is a using directive or assembly reference
2. Name of 'Screen' have no name in the present context
3.be unable to find 'Drawing' format or name of namespace in 'System namespace'. Check if there is a assembly reference
4.name 'BitConverter' is unabel to find in the present context.
My function of dll file is to cature a screen and to get a hex bitmap data.
Below is the contents of script of my dll
contents of error is next
1. be unable to find 'Size' , 'Bitmap' , 'Graphic' , 'MemoryStream' , 'Image' format or name of namespace. Check if there is a using directive or assembly reference
2. Name of 'Screen' have no name in the present context
3.be unable to find 'Drawing' format or name of namespace in 'System namespace'. Check if there is a assembly reference
4.name 'BitConverter' is unabel to find in the present context.
My function of dll file is to cature a screen and to get a hex bitmap data.
Below is the contents of script of my dll
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace screenshotdll
{
public class Screenshotclass
{
public string ScreenShot()
{
Size size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, size);
MemoryStream mem = new MemoryStream();
Image scrs = bmp;
scrs.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
var c = mem.ToArray();
var hexstring = BitConverter.ToString(mem.ToArray()).Replace("-", "");
mem.Dispose();
return hexstring;
}
}
}
Re: parameter of DllCall() when dll's function does not have a parameter
Are the errors from using CLR.ahk? You should ask in the relevant thread, I know nothing about those errors.
Cheers.
Cheers.
Re: parameter of DllCall() when dll's function does not have a parameter
It was meant to be CLR.ahk.
Does the word " load the dll " mean dllcall? unless it means this, I don't know what "load the dll" and "unload the dll" means
Does the word " load the dll " mean dllcall? unless it means this, I don't know what "load the dll" and "unload the dll" means
Who is online
Users browsing this forum: CrowexBR and 258 guests