Jump to content
Sign in to follow this  
abb

Output bitmap from DLL

Recommended Posts

abb

Hello hello!

I've been using AutoIt for many years now but am pretty new to working with DLLs in AutoIt. I've been struggling with outputting a bitmap from a DLL to an image in my GUI.

I have the functioning code in Pascal but need to convert it to AutoIt so, two questions:

1) Does anyone know of a tool to convert Pascal to AutoIt?

2) What is the AutoIt pseudo-code for achieving this?

So far I've got

$dll = DllOpen("mydll.dll")
$dllResult = DllCall($dll,"int","LoadBitMap","none","AD0")

LoadBitMap is the DLL's function and the bitmap name is AD0. I'm unsure how to procede from here tho :)

Help would be greatly appreciated!

Share this post


Link to post
Share on other sites
zorphnog

There is no way that you are sending a string with a datatype of 'none'. Provide the documentation for your dll and maybe we can help you.

Share this post


Link to post
Share on other sites
abb

There is no way that you are sending a string with a datatype of 'none'. Provide the documentation for your dll and maybe we can help you.

Right. I wan't 100% sure what "Type1" should be so I put "none" in there thinking it was probably wrong :)

LoadBitMap returns a pointer so I believe the code should be:

$dll = DllOpen("mydll.dll")
$dllResult = DllCall($dll,"ptr","LoadBitMap","int","AD0")

Please correct me if I am wrong.

The Pascal code I'm attempting to convert to AutoIt is:

procedure TMainForm.ChangeAdImage();
var
   h : THandle;
   b1: TBitmap;
//   hRes : THandle; {handle to the resource}
   buf: Array[0..255] of char;
   sBitMapName:Array[0..3] of char;
   iNum: integer;
begin

   if m_bUseDefaultImage then
      begin
         m_bUseDefaultImage:=false;
         m_iCurrentAdImage:=0;
      end;

      h := LoadLibrary('eximg.dll');
      if h >= 32 then begin
      
          b1 := TBitmap.Create;

          StrCopy(sBitMapName,'AD');
          StrCat(sBitMapName,PChar(IntToStr(m_iCurrentAdImage)));

          b1.handle := LoadBitMap(h, sBitMapName);
          if b1.handle<>0 then begin
             AdImage.Picture.Bitmap := b1;
             b1.Free;

             iNum:=LoadString(h,m_iCurrentAdImage,@buf,sizeof(buf));
             if iNum >0 then
                m_sAdWebSite:=buf
             else
                m_sAdWebSite:=CONST_DEFAULT_ADWEB;
           end;
 
        end;

        m_iCurrentAdImage:=m_iCurrentAdImage+1;
        if  m_iCurrentAdImage >= CONST_NUM_ADS then
             m_bUseDefaultImage:=true;

        if h>0 then
            FreeLibrary(h);
end;

Hopefully this helps.

Thanks!

Share this post


Link to post
Share on other sites
zorphnog

Well it should probably be:

$dll = DllOpen("mydll.dll")
$dllResult = DllCall($dll,"ptr","LoadBitMap","str","AD0")

Don't forget that if the dll call executes properly, the result is an array. So the pointer will be returned to $dllResult[0].

Share this post


Link to post
Share on other sites
abb

It seems DllCall is returning @error = 3 meaning the function "LoadBitMap" is not found in the DLL file. So part of my problem is I interpreted the Pascal snippet incorrectly. My bad.

Is there another way to "stream out" the bitmap from the DLL into memory then update an image control perhaps?

Thanks for all your help in this Zorphnoq :)

Share this post


Link to post
Share on other sites
abb

Thanks Zedna. This looks like what I need but for the life of me I don't entirely understand how to use it. :)

Share this post


Link to post
Share on other sites
Zedna

Thanks Zedna. This looks like what I need but for the life of me I don't entirely understand how to use it. :)

I haven't implemented into my UDF optional $DLL parameter as proposed by ProgAndy yet.

I will do it later. So you must use ProgAndy's code for now.

Post your DLL file ...

Share this post


Link to post
Share on other sites
ProgAndy

I made it for the Newest resources.au3: http://www.autoitscript.com/forum/index.ph...st&p=522569

(With demo)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
abb

Perfect. Thank You Very Much! :)

With your help Progandy and Zedna I'm up and running again. Kudos!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.