After countless fits and starts I discovered why I don't see any CLR samples with the following snippet:
Code: Select all
class Program
{
static void Main(string[] args)
It turns out the answer is in Lexikos's original post for CLR 1.2 , staring me right in the face.
Also, as Lexikos pointed out here,Additional command-line arguments can be passed to the compiler via CompilerOptions. For instance, if FileName specifies an .exe file, a console app is generated unless CompilerOptions includes "/target:winexe".
I stubbornly resisted doing anything in either C# or VB because of the failures described above, but, well, okay, here it is.You can't call static methods directly; you must either use another language or use Reflection. For Reflection, asm (the Assembly object) is the starting point. If you're not familiar with Reflection and don't want to research it by yourself, I would recommend creating a wrapper object in C#/VB instead, as shown in the second post in this thread.
By blind luck, while trying to compile a script, using another dll (iDitect.Converter.dll, more on that in another post), I got the following error message:
It was pretty much downhill from there, although I would probably still be flailing around blindly if it hadn't been for that error message. There are other compiler options, and I won't get into them. Okay, let's get to the DocX code!Compilation Failed
---------------------------
Error CS5001 on line 0: Program 'c:\Users\burque505\Desktop\AHK\HTML\iDiTect\ouch.exe' does not contain a static 'Main' method suitable for an entry point
In the archive attached are "DocX.dll" and the script below.
Code: Select all
;DahkX.ahk by burque505
;Easter Sunday, 2019
;first (and probably last) version 0.0.1
;
csharp=
(
using System;
using Novacode;
using System.Drawing;
namespace FeedTheMonkey
{
class Program
{
static void Main(string[] args)
{
using (DocX document = DocX.Create("FeedTheMonkey.docx"))
{
// Add a new Paragraph to the document.
Paragraph p = document.InsertParagraph();
// Append some text.
p.Append("Please feed the monkey . . . ").Font(new FontFamily("Arial Black"));
p.InsertParagraphAfterSelf("Okay, gimme a recipe!!!").Font(new FontFamily("Times New Roman")).Bold().FontSize(30).Color(Color.Red);
Paragraph p2 = document.InsertParagraph();
p2.Append("Gee whiz - you're a bad zookeeper. (sigh..)").Font(new FontFamily("Algerian")).Bold().FontSize(15).Color(Color.Blue);
p2.AppendLine();
var bulletsList = document.AddList( "2 cups of flour", 0, ListItemType.Bulleted );
document.AddListItem( bulletsList, "3/4 cup of sugar" );
document.AddListItem( bulletsList, "1/2 cup of butter" );
document.AddListItem( bulletsList, "2 eggs" );
document.AddListItem( bulletsList, "1 cup of milk" );
document.AddListItem( bulletsList, "2 teaspoons of baking powder" );
document.AddListItem( bulletsList, "1/2 teaspoon of salt" );
document.AddListItem( bulletsList, "1 teaspoon of vanilla essence" );
document.InsertList(bulletsList);
// Save the document.
document.Save();
}
}
}
}
)
; "0" for the AppDomain, "DahkX.exe" for the temporary executable, and "/target:winexe" so a console window doesn't open.
asm := CLR_CompileC#(CSharp,"System.dll|System.Drawing.dll|Microsoft.CSharp.dll|DocX.dll", 0, "DahkX.exe", "/target:winexe")
; Run what you just compiled
RunWait, DahkX.exe
; Delay because sometimes it hiccups - not often
sleep, 100
; Get rid of the executable and .pdb file, comment this out if you want to keep them for some reason.
FileDelete, DahkX.exe
FileDelete, DahkX.pdb
; e finito tutto!
ExitApp
Below is a cropped shot of the Word document created. By the way, it does charts, lists, tables of contents, all kinds of good stuff!
Regards, and Happy Easter,
burque505