way to call my dll file made by C#

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Parama
Posts: 40
Joined: 27 Sep 2017, 22:38

way to call my dll file made by C#

17 Oct 2017, 04:58

I made a dll file in C# to get what i want in autohotkey.
There is a function in the dll file ,which capture a screen and convert captured image to hex without making image file
I wanted to call this fucntion by means of DllCall but i failed. so i inluded CLR.ahk in my script

this is my script in autohotkey

Code: Select all

#include C:\Users\me\Desktop\CLR.ahk

f1::

hex=
(
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 hex
{
    public class Hex1
    {
        public string HexFunct()
        {

            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;



        }
    }
}




)
asm := CLR_CompileC#(hex)
obj := CLR_CreateObject(asm, "Hex1")
msgbox % obj.HexFunct()

return

f2::

exitapp

If running this, get an error like below

Error CS0234 : There is not 'Linq' type or namespace in 'System' namespcae. Make sure that there is a assembly reference.

Error CS0234 : There is not 'Drawing' type or namespace in 'System' namespcae. Make sure that there is a assembly reference.

Error CS0234 : There is not 'WIndows' type or namespace in 'System' namespcae. Make sure that there is a assembly reference.





I desperately want to solve it.
I sincerely hope that you will help me.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: way to call my dll file made by C#

17 Oct 2017, 05:36

Why you haven't used Gdip.ahk (that is plain AHK) to create that screnshot based hex index?
Parama
Posts: 40
Joined: 27 Sep 2017, 22:38

Re: way to call my dll file made by C#

17 Oct 2017, 06:13

Of course I tried, but I don't know how to do it
i tried to use Gdip_BitmapFromScreen(). this function's return variable is pBitmap,which has address of variable of image data, but i don't know how to get image data from pBitmap. Although I questioned about that in this web site, i cannot get any answer. so i gave up that way

Do you know how to get image data from pBitmap and how to get hex from image data in Gdip.ahk? if you know, i hope you to answer me
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: way to call my dll file made by C#

17 Oct 2017, 06:39

Personally, I just pre-compile the DLL in Visual Studio rather than using the in-line compile of CLR.
This also means that you can handle the references in VS, making life easier.

So... I took your code, started a new "Class Library" project in VS, then right-clicked References and added a reference to "System.Windows.Forms" and "System.Drawing", after which all the build errors disappeared.

Attached is the resulting DLL file. I also attached the solution for you.

Use this ahk code:

Code: Select all

#include <CLR>

asm := CLR_LoadLibrary("hex.dll")
hex := asm.CreateInstance("hex.Hex1")

result := hex.HexFunct()
Attachments
Solution.zip
(21.72 KiB) Downloaded 21 times
DLL.zip
(2.02 KiB) Downloaded 20 times
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: way to call my dll file made by C#

17 Oct 2017, 08:44

I have a script that does pBitmap to hex string. Note: it retrieves the image data upside down, so it has to reverse the order of the lines.

Gdip: image binary data to hex string for OCR - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 71#p168571
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: way to call my dll file made by C#

17 Oct 2017, 09:22

ImageGetColors()* uses Gdip_CreateBitmapFromFile() instead of Gdip_BitmapFromScreen(), so needs to be tweaked to cover your requirement. Result is delivered as a variable that contains an index of hex values.

https://autohotkey.com/boards/viewtopic.php?f=9&t=37006

* kindly created by just me :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 213 guests