Windows ole word automatism / use JUNO (this posts are getting longer and longer ; )

JohnC johnch_atms at hotmail.com
Wed Nov 15 07:02:24 PST 2006


"Gregor Kopp" <gk at cutcopy.com> wrote in message 
news:ejf52t$1t2q$1 at digitaldaemon.com...
> Hi JohnC,
>
> thank you very very much for your time and helping.
> I downloaded your new version of Tlbimpd, found the 3 named files and now 
> im stucking again with Tlbimpd (step 1).
>
> But i don not know what I can do. I tried tlbimpd with the options, 
> without the options, with full path in \ and / notation, a always get the 
> Access Violation on all 3 files. I too tried, just to find out how, to 
> generate it with the sqlite3.dll to see if it is tlbimpd, or me but here 
> tlbimpd says, that he cannot open the dll file. Could it be, that tlbimpd 
> don't do the job on a Windows 2000?

sqlite3.dll doesn't contain a COM type library! Try something like 
msxml4.dll instead.

I have no way of testing on operating systems other than XP, but I don't 
think there's anything in the program that would prevent it from working on 
Windows 2000. Just tried it on each of my XP machines in Windows 2000 
compatibility mode, and it worked fine.

See my further comments below...

>
> tlbimpd.exe is stored in my c:/dmd/bin directory wich is in my PATH 
> Variable, if that helps.
>
> Whatever i try to do with it, here is an example output:
>
> C:\Documents and Settings\gk>f:
>
> F:\>cd \dfiles\mswordolb
>
> F:\dfiles\mswordolb>dir
>  Volume in drive F is Daten
>  Volume Serial Number is 6833-CBCE
>
>  Directory of F:\dfiles\mswordolb
>
> 11/15/2006  02:13p      <DIR>          .
> 11/15/2006  02:13p      <DIR>          ..
> 09/01/2006  03:02p           9,816,840 MSO.DLL
> 02/19/2001  08:12p             626,688 MSWORD.OLB
> 01/22/2001  06:39p              45,056 VBE6EXT.OLB
>                3 File(s)     10,488,584 bytes
>                2 Dir(s)     928,391,168 bytes free
>
> F:\dfiles\mswordolb>tlbimpd /?
> Type Library to D Module Converter 1.0
>
> Syntax: tlbimpd TypeLibName [Options]
> Options:
>     /comments             Adds documentation as comments
>     /noblanks             Omits blank lines between members
>     /noenums              Prevents generating named enums
>     /nologo               Omits display of logo
>     /silent               Suppresses all output except errors
>     /tabs                 Indents new lines with tabs instead of spaces
>     /indent:indentCount   Indents new lines with the specified number of 
> spaces
>     /braces:newLine       Places braces on a new line
>     /module:moduleName    Name of module to be produced
>     /out:fileName         File name of module to be produced
>     /propget:prefix       Prefix to use for property getters
>     /propput:prefix       Prefix to use for property setters
>     /unnamed:value        Value for unnamed parameters
>     /order:verbatim       Generate types in original order
>     /? or /help           Displays this usage message
>
>
> F:\dfiles\mswordolb>tlbimpd MSWORD.OLB /module:msword /out:msword.d
> Type Library to D Module Converter 1.0
>
> Access Violation
>
>
> F:\dfiles\mswordolb>

I don't think you're doing anything wrong. So it's running on Windows 2000, 
but there's clearly a bug in tlbimpd that's causing an access violation. 
Well, it is untested pre-beta software, so things will go wrong.

I've generated the word, office and vbide modules for you so that you can 
get started. Just add the IPictureDisp definition as described earlier, and 
you should be good to go. http://www.paperocean.org/d/mso.zip

Here's some code (untested and without error checking) that creates a Word 
object:

import com, office, word;

void main() {
    _Application application = 
Application.coCreate!(_Application)(CoClassContext.LocalServer);

    Documents documents;
    application.get_Documents(documents);

    VARIANT empty; // for empty arguments
    VARIANT templateName = VARIANT("template.dot");
    Document templateDoc;
    documents.Add(&templateName, &empty, &empty, templateDoc);
    templateName.clear();

    application.set_Visible(VARIANT_TRUE);

    Selection selection;
    application.get_Selection(selection);
    Find find;
    selection.get_Find(find);

    wchar* text = utf8ToBstr("find this text");
    find.set_Text(text);
    freeBstr(text);
    short dummy;
    find.Execute(&empty, &empty, &empty, &empty, &empty, &empty, &empty, 
&empty, &empty, &empty, &empty, &empty, &empty, &empty, &empty, dummy);

    // And so on...

    // release our COM objects.
    find.Release();
    selection.Release();
    templateDoc.Release();
    documents.Release();
    application.Release();
}

>
>
> JohnC schrieb:
>> "Gregor Kopp" <gk at cutcopy.com> wrote in message 
>> news:ejepvc$1h3m$1 at digitaldaemon.com...
>>
>>>Hm. I played around with it now for several hours. With Tlbimpd I always 
>>>get an access violation, i dont know why. But I must say, that I don't 
>>>know if I did it the right way. I seems that ive always the poor stupid 
>>>guy who does always wants to learn something about new technologies and 
>>>always gets undocumented pieces of software :(
>>>Its really annoying.
>>
>>
>> Sorry it's not documented. I'm readying a new release of my Juno library 
>> and related tools, and will provide documentation this time around. It 
>> should be done by late December.
>>
>> For now, get the latest test version of tlbimpd from 
>> http://wwwpaperocean.org/d/tlbimpd.zip.  The /? switch on the command 
>> line explains the various options.
>>
>> Tlbimpd attempts to generate a D source module from a COM type library. 
>> It doesn't work on every type library yet. And when it does work you 
>> might need to tweak the generated files to get them to compile.
>>
>> I just ran this version of tlbimpd on msword.olb, and it generated word.d 
>> without any errors. Here's what you need to do to get Word automation 
>> working:
>>
>> 1) Run tlbimpd (the latest version from the above link) on msword.olb, 
>> mso.dll and vbe6ext.olb.
>> I had to search my system for vbe6ext.olb. It was buried in a CAB file - 
>> if that's the same for you, copy it to another location before using 
>> tlbimpd on it.
>>
>> 2) Download http://www.paperocean.org/d/comtest.zip and use the com 
>> module from there instead of the one from Juno.
>>
>> 3) Import the resulting "office" and "vbide" modules into word.d, like 
>> this:
>>
>>     private import com, office, vbide;
>>
>> Import the "office" module into vbide.d.
>>
>> 4) office.d requires IPictureDisp, which isn't defined in the included 
>> com module (I'll add it in the next release) so add the following lines 
>> to the bottom of the "com" module:
>>
>>     interface IPictureDisp : IDispatch {
>>         static GUID IID = { 0x7BF80981, 0xBF32, 0x101A, 0x8B, 0xBB, 0x00, 
>> 0xAA, 0x00, 0x30, 0x0C, 0xAB };
>>     }
>>
>> 5) Try to compile everything, using DMD. You'll get a few errors saying 
>> something like "Range is used as a type". This means that Range is 
>> defined as a type but is also the name of a function, and they clash. So 
>> just go through them in turn and prefix the function names where the 
>> errors occur with "get_". For example change the function named Range to 
>> get_Range.
>>
>> After following these steps, it should all compile.
>>
>> I know I said it was easier to use early binding rather than late 
>> binding, and while this may make you think otherwise, it'll save you a 
>> lot of work in the long run.
>>
>>
>>>I thought about using OleView and do it by hand about 2 seconds ;)
>>>Im a Noob about such things, I think I need 3-4 years of experience 
>>>before I know what I'm doing with that *g*
>>>
>>>Anyway, enough mimimimi...
>>>
>>>Can anyone tell me what I could do to reach my goal? I would be really be 
>>>sad if i have to drop my interest on D because the lack of my knowledge 
>>>about windows programming.
>>>
>>>But maybe Im just to dump to use Tlbimpd :/
>>>I don't know...
>>
>>
>> If you follow the guidance above, you shouldn't need to drop either. 





More information about the Digitalmars-d mailing list