Extracting icons from DLLs and EXEs

13.0.46 adds support (see below for release notes) for extracting icons. I can get the internal icon method to work with e.g: dlg.control("static1").label = "#ziptoolkit"; but I am struggling to use LoadImage to extract from a DLL e.g: dlg.control("static1").label = DOpus.Loadimage("C:/Windows/System32/zipfldr.dll"); Is my syntax incorrect?

  • Scripting: Scripts can now extract icons from DLLs and EXEs using the standard LoadImage functions
  • Scripting: Scripts can now access internal icon images; pass the icon name prefixed with # (e.g. #copy). By default the large size is returned; use #0:name for the small size. You can also specify a particular set using #set:icon or #0:set:icon.

It's the same here but different with dlg.icon:

dlg.icon = "#copy" doesn't work but
dlg.icon = DOpus.Loadimage("/desktopdir\copy.ico") works, even with a PNG-file.

These all work, in fact I don't know the correct usage of DOpus.LoadImage. . .

dlgInpput.Control("static3").label = D:\\Icons\\Move.png;
dlgInpput.Control("static3").label = "#getsizes";
dlgInpput.Control("static3").label = "#0:getsizes";
dlgInpput.Control("static3").label = "C:\\Windows\\System32\\shell32.dll,20";

Looks like you need to specify an index at the moment, but we'll fix it in the next beta.

DOpus.Loadimage("C:/Windows/System32/zipfldr.dll,0"); should work now though.

It doesn't, but @WKen's method does: :grinning:
dlg.control("static1").label = "C:/Windows/System32/zipfldr.dll,0";

No doubt the next Beta will do the trick for DOpus.Loadimage.

This looks promising, I may not need to use another app to do this.

How does it work, i.e. how does one use it?

Currently available for script dialog.

function OnClick(clickData)
{
    if (!DOpus.version.AtLeast("13"))
    {
	    DOpus.Output("This script requires version 13 and above!");
		return
    }
	var clipText = '';
	if (DOpus.GetClipFormat() == 'text')
	    clipText = DOpus.GetClip('text');
	
	// inputBox(title, topic, notes, default value, style of dialog, width, height, iconFile)
	var text = inputBox("Directory Opus", "Topic", "notes", clipText, "editText", 500, 138, "D:\\Icons\\MOVE.png");
}


function inputBox(title, topic, notes, defValue	, style, width, height, iconFile)
{
    var dlgInpput = DOpus.Dlg();
    dlgInpput.title = title;
	if (style == "editText")
        dlgInpput.template = "dlgEdit";
	dlgInpput.detach = true;
    dlgInpput.Create();
	dlgInpput.Control("static").style = "b";
	dlgInpput.Control("static").label = topic;
	dlgInpput.Control("static2").label = notes;
	
	//dlgInpput.Control("static3").label = iconFile;                              // Icon
	//dlgInpput.Control("static3").label = "#getsizes";
	//dlgInpput.Control("static3").label = "#0:getsizes";
	dlgInpput.Control("static3").label = "C:\\Windows\\System32\\shell32.dll,20";
	
	dlgInpput.Control("editText").value = defValue;
	dlgInpput.Control("editText").SelectRange(0, -1);
	dlgInpput.AddHotkey("editText", "ctrl+enter")                                 // Add Hotkeys
	
	dlgInpput.Control("static").cx = width-12;
	dlgInpput.Control("static2").cx = width-12;
	dlgInpput.Control("static2").cy = height/4;
	if (width > 501)
	    dlgInpput.Control("editText").cx = width-42;
	else if (width < 801 && width > 501)
	    dlgInpput.Control("editText").cx = width-402;

	dlgInpput.Control("editText").y = height-(height/1.9);
	dlgInpput.cx = width;
	dlgInpput.cy = height;
    
    dlgInpput.Show();

//-- Add string trim() method
String.prototype.trim = function(s){s=s||"\\s";return this.replace(new RegExp("^("+s+"){1,}\|("+s+"){1,}$","g"),"");}

// msg loop	
	do
	{
		msg = dlgInpput.GetMsg();
/*
        // Selection
		if (msg == true && dlgInpput.Control("editText").focus == true) {
		    DOpus.Output(dlgInpput.Control("editText").label);
		}
*/
        // Result, perform the operation
		if (dlgInpput.result == 1 || msg.qualifiers == "ctrl" && msg.event == "hotkey") {
		    if (msg.qualifiers == "ctrl" && msg.event == "hotkey") dlgInpput.EndDlg;
            return dlgInpput.Control("editText").value.trim();
		}
/*
		// If the button 3 is pressed
		if (dlgInpput.result == 2) {
		    DOpus.Output("Button 3 is pressed");
		}
		
		// If the button 4 is pressed
		if (dlgInpput.result == 3) {
		    DOpus.Output("Button 4 is pressed");
		}
*/
	} while (msg == true);
}


==SCRIPT RESOURCES
<resources>
	<resource name="dlgEdit" type="dialog">
		<dialog fontsize="8" height="120" lang="english" resize="yes" title="Edit Tags" width="522">
			<control halign="left" height="62" multiline="yes" name="editText" resize="wh" type="edit" width="506" x="8" y="32" />
			<control close="1" default="yes" height="14" name="btnApply" resize="xy" title="&amp;OK" type="button" width="50" x="409" y="99" />
			<control close="0" height="14" name="btnCancel" resize="xy" title="&amp;Cancel" type="button" width="50" x="462" y="99" />
			<control halign="left" height="8" name="static" title="Edit Tags" type="static" valign="top" width="472" x="39" y="7" />
			<control halign="left" height="20" image="yes" name="static3" title="Static" type="static" valign="top" width="20" x="10" y="4" />
			<control halign="left" height="8" name="static2" title="Notes" type="static" valign="top" width="472" x="39" y="17" />
		</dialog>
	</resource>
</resources>

Thank you.

This is the first time I've used scripting in Dopus, so forgive me if I'm not doing it correctly.

So I've created a new button, and pasted the above code in the button.

And this is what I get when clicking the button

The style here is different from yours. :thinking:


What is supposed to happen when one clicks the button containing that code?

I noticed this path in the code (which I don't have):

var text = inputBox("Directory Opus", "Topic", "notes", clipText, "editText", 500, 138, "D:\Icons\MOVE.png");

Nothing will happen, just an example.

I was hoping it was a complete method to extract icons from DLLs and EXEs.

I guess I was expecting too much :grin:

Maybe that's what you expected, but there are some problems with that.

dll

function OnClick(clickData)
{
    if (!DOpus.version.AtLeast("13.0.46"))
    {
	    DOpus.Output("This script requires version 13 and above!");
		return
    }
	var cmd = clickData.func.command;
	var image =  DOpus.LoadImage("C:/Windows/System32/shell32.dll,15", 16, 16);
	//image.SetClip();   // Throw error
	DOpus.Output(image.SetClip() + image.width);   // The image was copied to the clipboard, but image.width was not the specified 16
	cmd.RunCommand('Clipboard PASTE=png AS "D:\\icon.png"')   // Image size is 32x32
}

png

function OnClick(clickData)
{
    if (!DOpus.version.AtLeast("13.0.46"))
    {
	    DOpus.Output("This script requires version 13 and above!");
		return
    }
	var cmd = clickData.func.command;
	var image =  DOpus.LoadImage("D:\\Test.png", 300);
	//image.SetClip();   // Throw error
	DOpus.Output(image.SetClip() + image.width);   // The image was copied to the clipboard, but image.width was not the specified 300
	cmd.RunCommand('Clipboard PASTE=png AS "D:\\icon.png"')   // Image size is 500x808
}

You'll also lose the icon's transparency if the image is saved via the clipboard (since clipboard image data has no alpha channel by convention).

There are lots of tools for extracting icons from DLL/EXE files already though, if that's what you need to do. Those can give you the full .ico file with all sizes and depths.

1 Like