|
Hi Jörgen Sigvardsson,
Thanks. This was very informative.
-------------------------
Have a great day ahead!
Regards,
Sohail Kadiwala
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi There
I am having trouble automating Word from a win32 consol application.
I have used the example given on MSDN
http://support.microsoft.com/default.aspx?scid=kb;en-us;238393
and this works nicely. That is it opens a Word Document does some stuff, saves and closes.
Unfortunetly its the 'does some stuff I am having trouble with! I want to add tables to a word document and populate with data.
My variation to the MSDN example is as follows: that is I replace the Open and go from there...
/*******************************************************************************/
/******************************* MY AUTOMATION *********************************/
/*******************************************************************************/
// Call Documents.Add() to create a document
IDispatch *pDoc;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_METHOD, &result, pDocs, L"Add", 0);
pDoc = result.pdispVal;
}
//***Create a Table***
IDispatch *pTable;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pDoc, L"Tables", 0);
pTable = result.pdispVal;
}
//***Set Range to beginning of document***
IDispatch *pRange;
{
VARIANT result;
VariantInit(&result);
VARIANT varStart, varEnd;
varStart.vt = VT_I4;
varStart.lVal = 0;
varEnd.vt = VT_I4;
varEnd.lVal = 0;
AutoWrap(DISPATCH_METHOD, &result, pDoc, L"Range", 2, varEnd, varStart);
pRange = result.pdispVal;
}
//***Add table a location specified by range***
{
VARIANT result;
VariantInit(&result);
VARIANT varRange, varRows, varColumns;
varRange.vt = VT_DISPATCH;
varRange.pdispVal = pRange;
varRows.vt = VT_I4;
varRows.lVal = 0;
varColumns.vt = VT_I4;
varColumns.lVal = 0;
AutoWrap(DISPATCH_METHOD, &result, pTable, L"Add", 3, varColumns, varRows, varRange);
}
// Call Documents.SaveAs() to save a document at/as C:\myDoc.doc
{
VARIANT result;
VariantInit(&result);
VARIANT x;
x.vt = VT_BSTR;
x.bstrVal = ::SysAllocString(L"C:\\myDoc.doc");
AutoWrap(DISPATCH_METHOD, &result, pDoc, L"SaveAs", 1, x);
// pDoc = result.pdispVal;
SysFreeString(x.bstrVal);
}
/*******************************************************************************/
/*******************************************************************************/
/*******************************************************************************/
But it I get an error back from the IDispath raising an exception (no useful info) when AutoWrap (... "Add"...) ???
HELP!!!!! PLEASE!!!!
Regards Dean
|
|
|
|
|
A couple of weeks ago I was attempting to do something similar, except that I was using Visual C++ .NET and had imported the Word type library with TlbImp.exe. TlbImp.exe converts the Type Library into a metadata assembly (basically it's C syntax with attributes), and any .NET compiler can access it; all you have to do is reference the DLL and the namespace in your code. It's considerably easier than what you're doing here.
However, I did make a lot or errors with the Word Type Library (I used verion 10.0) objects and methods because I was reading the help file which was written for Visual Basic programmers. As I recall, before opening a document, you had to call the function which returns a Documents Collection object (this is the Get Documents Collection code block from the code you are using); this is implemented by the IApplication interface, or the Application CoClass,...in other words, you must instantiate the Application object before anything else. Then call Documents::Open (this returns a Document object if it is successful). I had created a blank document with calls to the Windows API CreateDirectory and CreateFile (you can accomplish the same thing by opening Word beforehand and creating a new document the way the article you are working from suggests). If you call Documents::Add, you are actually creating a NEW document. And, when you create a NEW document in Word, it's actually a Microsoft Office object, and this object is created from a separate DLL, the Office Type Library (in the Interop assembly that I used it's a enumeration in Office.dll). Anyway, after trying several approaches, I discovered that it is easier and more straightforward to call Documnents::Open and pass the string for a document that has already been created. But, you must obtain the Documents Collection object first, or the call to Documents::Open will fail, and you won't know why unless you look up the HRESULT.
Read through the help file for the Word Object hierarchy; it's in a directory called, 1033, or something, in the Microsoft Office directory. The code examples won't be helpful, but, it will give you an idea what methods to invoke from which objects.
When you do get it to work, there are methods for creating tables in the type library, you must extend the range to accomodate the table structure. As I recall you can call methods like Range::InsertAfter and Range::InsertBefore, but they take string objects as method parameters (they are just for text editing). Also, it would be easier to create the table as a JPEG document and use the Range::InsertPicture method. You really must be able to examine the entire type library to make appropriate choices with your code implementation.
I'm curious, and I'd like to attempt the same thing in unmanaged code, how do you read the type library to understand how the COM objects and interfaces are implemented? In Visual C++ .NET, the IL Disassembler will display the entire type library (as an Interop Assembly), which makes it much easier to decide which methods to call, and what parameters and their types are necessary to make the calls successful. Then, (and this part is like cheating), you use Intellisense to invoke the correct methods in sequence. Also, exceptions are easier to deal with than HRESULTS.
|
|
|
|
|
|
can any one tell me how I can demodualate v22.bis modem data via software
|
|
|
|
|
You have any link to specifications of v22.bis data ?
What is your scenario ? (i.e.: a brief explanation of the context in which you require to demodulate your data)
etc. etc.
|
|
|
|
|
Thanks for you reply I have a link to site which as Demodulation code for all formats. However I do not fully understand it the link is http://www-users.cs.york.ac.uk/~fisher/software/modem/
What I require is to run this software on a Handheld Pc and to demodulate the data in real time.
Hope this is of help
Regards
Max
|
|
|
|
|
I think you've got it wrong. This forum is for the Component Object Model. Not serial communication..
--
...Coca Cola, sometimes war...
|
|
|
|
|
i mite be sounding silly but yet want to get my doubt cleared.what actually happens in the MS-WORD addin written by Amit Dey?
i haven't yet been able to find out what happens on the click of the button?
|
|
|
|
|
I am having difficulty understanding how the Implement Interface wizard works.
I have a COM server with a coclass called CoShape with an interface IShape . I also have a number of shapes one of which is called CoSquare with an interface ISquare . I wish to create a coclass called CoMySquare which inherits the ISquare interface but I expect it also to inherit the IShape interface when I use the "Implement Interface" wizard. To do this I import a typelib and select an interface to implement. It seems that even though CoSquare implements the IShape interface, to implement both ISquare and IShape in my CoMySquare , I need to explicitly implement both. Is this right?
In other words:
ISquare inherits from IShape
IMySquare inherits from ISquare
Surely implementing ISquare for CoMySquare should also implement IShape ?
|
|
|
|
|
can or not?if can,how?
please contact:
max_xiayi@hotmail.com
|
|
|
|
|
Hi all,
Iam a newbie to com. I have to work in c++ and vc.Iam working on interfaces like IhtmlcontrolRange, IHtmlTxtRange,IHTMLDataTransfer etc.
I don't how to implement some these interfaces. It would be of great help if i could get some help on how to implement these in c++.
Msdn site gives only definitions not examples.
Kindly specify some websites which could provide some examples on to implement these.
Thanx in Advance.
Raj
|
|
|
|
|
Hi,
how do we implement pre element. plz explain with example
lokiz
|
|
|
|
|
When I try to connect a remote client to COM exe server, I receive E_ACCESSDENIED as a response to CoCreateInstanceEx. In the system event logger I get : The server did not register with DCOM within the required timeout.
Anyone has a clue why it happens?
|
|
|
|
|
hi...
For the remote access of a DCOM server we need marshal/unmarshal code on both server mechine and client machine. Second concern is the access right prblms. Make sure u headed both.
Regarding Marshaling-Unmarshaling:
If all the data types in ur server is automation compatiable, then u can use type library marshaling , so no need to do anything on the server mechine, but just register the type ibrary on the cleint mechine. To register a type library u can use regtlib.exe , which is available for download at topdownlods.com
If ur server uses automation incompatiable data types u have to go 4 MIDL marshaling . For this u have to create a proxy-stub dll and register it on the server and client mechine. To generate a proxy stub dll: Goto server project folder, There will be a projectnamePS.mk file. goto commandline and run the nmake utility by typing nmake projectnamePS.mk to generate projectnamePS.dll . U have to register this projectnamePS.dll on both server mechine and client mechine. u can use regsrvr32.exe to register this proxy-stub dll.
Regarding COM Server Launch rights and COM Server access rights: This section i had xplained in a previous post. jus go thru this[^]) link, before u start ur fixs.
luks forward ur response, if any more concerns...
rgds..mil10.
|
|
|
|
|
Hi.
Thanks for your response. Regarding DCOMCNFG.EXE: I believe you are not describing the one from the Win XP , since it doesn't fit the description . Anyways, by meantime I figured out that the problem was that I didn't define the permissions as "Interactive user" (since my client application uses MFC). I'm sure I'll use your hint for the data transfer between client/server.
Thanks again for your help.
|
|
|
|
|
hi ...
Oh is it so? DCOMCONFIG is diffrent in xp? i never tried it in xp. Anyway only thing is that u have to set those accesrights, launch rights and the identity as u set alredy.. that much only..
have nice time... rgds...mil10.
|
|
|
|
|
How can I get a class name (such as "Word.Application") from an interface to an object? (c++) thanks!!
|
|
|
|
|
I assume you want the CLSID..?
Then there's a function for you right here[^]
If you want the C++ class which implements Word.Application, I think you'll have to ask someone in the Office division at Microsoft. And you will also have to be version specific as Word.Application is a version independent progid.
--
Denn du bist, was du isst!
Und ihr wisst, was es ist!
Es ist mein Teil...?
|
|
|
|
|
Thanks for the quick reply, I appreciate it. However, I don't really have the skill to translate a CLSID into an actual name, unless I look it up in the registry. Also, how do you get the ProgID? All I have is an IDispatch interface...
|
|
|
|
|
<br />
WINOLEAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR* lplpszProgID);<br />
|
|
|
|
|
If you just have the IDispatch interface you may be out of luck. It all depends on what else the object exposes. It may expose a DISPID which will tell you something about the CLSID/ProgID (doubtful), or it may implement an interface such as IPersist (which has a nice function called GetCLSID), from which you can acquire the CLSID.
--
Denn du bist, was du isst!
Und ihr wisst, was es ist!
Es ist mein Teil...?
|
|
|
|
|
It would be really appreciated if anyone could explain me how to connect number of client application to the same instance of an out-of-process COM server. The client applications must be able to share the data via the COM server, as well as call the COM server methods.
|
|
|
|
|
|
Another way of connection to an out-of-process COM server is to use the ROT (Running Object Table). You'll find more info about the ROT in the MSDN docs.
--
Denn du bist, was du isst!
Und ihr wisst, was es ist!
Es ist mein Teil...?
|
|
|
|
|