Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

M2000 now can handle Word

$
0
0
After two days I found a way to call methods with named arguments. The problem was in typelib "IDispatch Interface - Eduardo Morcillo"
So I use the ole/com object user to extract the idl file.

Code:

        long _stdcall GetIDsOfNames(
                        [in] IID* riid,
                        [in] LPSTR* rgszNames,
                        [in] long cNames,
                        [in] long lcid,
                        [in, out] long* rgDispId);

I do a big search to find a way to pass a sting array for rgszNames, because from second element we have the named arguments. So after searching all possible variations (like safe arrays), I found the most easy solution.
Code:

        long _stdcall GetIDsOfNames(
                        [in] IID* riid,
                        [in] long* rgszNames,
                        [in] long cNames,
                        [in] long lcid,
                        [in, out] long* rgDispId);

I use mktyplib Idispatch.IDL to make the tlb

So how I can pass a string array? I think that the array is a simple long array with pointers to actual bstr (that use an array string). So i do a copy of StrPtr(stringvar or string_element_of_array) to a long type array and I pass that array. No need to convert to unicode, is ready in unicode. Secondly the array is read only for the GetIDsOfNames and i count that the job happen too fast, for vb to rearrange bstr (but maybe this is a fault). I do the same for rgDispId but here only we pass the first item.
This is a line from mdlIDispatch module in M2000 ver 8 rev 11, where fixnamearg is the number of named arguments. We just pass the first element of each array. and the others are valid from 3rd parameter, the number of elements.
lngRet = IDsp.GetIDsOfNames(rIid, myptr(0), fixnamearg + 1, cLid, varDISPID(0))

This is an example in M2000 using named arguments in Method command. Because SET is used for other purpose, I use Declare to set new objects. We can set objects as result from Method. We see that in Add method in Documents object of Word.Application.
I do some test with no named arguments, with mix and with one or two named arguments...and work fine.
Declare statement used for libraries also.
Here is the unfinished language definition
Here is the code - there is also a signed executable. Only the executable M2000.exe and the help2000.mdb needed to run the program.

Code:

declare global alfa "Word.Application"
declare global doc  use alfa, "Documents"
global wdDoNotSaveChanges=0
Global WdNewBlankDocument = 0 \\Blank document
Global WdNewEmailMessage = 2 \\E-mail message
Global WdNewFrameset = 3 \\Frameset
Global WdNewWebPage = 1 \\Web page
Global WdNewXMLDocument = 4 \\XML document
test
module kappa {
      With alfa, "visible" as anyname
      try ok {
            anyname=true
      }
      a$=key$
            try {
            with alfa, "top",100,"left",0
           
            try ok_doc { method doc, "add", "", DocumentType:=WdNewWebPage as doc1 }
            if not ok_doc then print "no doc" : exit
            method doc1, "activate"
            declare global selection  use alfa, "selection"  \\ now we can make a selection
            method selection, "TypeText","This is my text in Word Document using M2000"
            a$=key$
            try saved { method doc1,"close" }
         
            if not saved then {
            print "document not saved, press any key"
              refresh
              a$=key$
              method doc1,"close", SaveChanges:=wdDoNotSaveChanges  \\closed without saving
              }
            flush error
      }
      a$=key$
      \\ now we hide word
      if ok then {try { anyname=false }}
      try { declare doc1 nothing }     
      try { declare selection nothing }     
}
kappa
wait 10
try {method alfa, "quit"
declare doc nothing
declare alfa nothing }


Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>