Home > Software engineering >  C com form the invocation of the problem
C com form the invocation of the problem

Time:10-23

Doing a thing, it involves the COM programming something, but I just call others write good COM form, this let me mentally, feel peace in the library is not the same ah, gave a document introduces the usage of some functions inside, but I don't know how to call these functions the ah, don't know if I made myself clear no, willing to help me a great god add my QQ: 1785703760, the first time in this post, don't know how to play, the integral is less, I hope you can appreciate the great god, thank you!!

CodePudding user response:

There may not be clear, have what problem can ask me directly

CodePudding user response:

Fyi:
//Copyright (C) 1992-1998 Microsoft Corporation 
//All rights reserved.
//
//This source code is only intended as a supplement to the
//Microsoft Visual c + + Language Reference and related
//electronic documentation provided with Microsoft Visual c + +.
//See these sources for detailed information regarding the
//Microsoft Visual c + + product.

//NOTE: This example will only work with Excel8 Office97 in
//the Compile with cl/GX comexcel. CPP
//TO DO: Edit the # import paths
//# pragma message (" Make sure you go to view the Options. The Directories and add the paths to mso97. DLL and vbeext1. The olb. Mso97. DLL will usually be a c: \ \ \ "\ Program Files \ Microsoft Office " \ \ \ "" \ \ Office, and vbeext1. The olb will be in c: \ \ " \ Program Files \ \ \ \ "" Common Files " \ \ \ "Microsoft Shared \ \ " VBA ")
# import "C: \ \ Program Files \ \ Common Files \ \ Microsoft Shared \ \ Office11 \ \ the oledata.mso DLL" no_namespace rename (" DocumentProperties ", "DocumentPropertiesXL")
# import "C: \ \ Program Files \ \ Common Files \ \ Microsoft Shared \ \ VBA \ VBA6 \ \ VBE6EXT OLB" no_namespace
# import "C: \ \ Program Files \ \ Microsoft Office \ \ OFFICE11 \ \ excel exe" rename (" DialogBox ", "DialogBoxXL") rename (" RGB ", "RBGXL") rename (" DocumentProperties ", "DocumentPropertiesXL") no_dual_interfaces

# pragma warning (of which: 4192 4146)

#include
#include

Void dump_com_error (_com_error & amp; E)
{
_tprintf (_T (" Oops - hit an error! \ n "));
_tprintf (_T (" \ \ a tCode=% 08 lx \ n "), e.E rror ());
_tprintf (_T (" \ \ a tCode fancy=% s \ n "), e.E rrorMessage ());
_bstr_t bstrSource (e.S ource ());
_bstr_t bstrDescription (e.D escription ());
_tprintf (_T (" \ \ a tSource=% s \ n "), (LPCTSTR) bstrSource);
_tprintf (_T (" \ \ a tDescription=% s \ n "), (LPCTSTR) bstrDescription);
}

//If this is placed in the scope of the smart Pointers, they must be
//explicitly Release (d) before CoUninitialize () is called. If any reference
//count is non - zero, a protection fault will occur.
Struct StartOle
{
StartOle () {CoInitialize (NULL); }
~ StartOle () {CoUninitialize (); }
} _inst_StartOle;

Void main ()
{
Using the namespace Excel;

_ApplicationPtr pXL;

Try
{
PXL. CreateInstance (L "Excel. Application");

The pXL - & gt; The Visible=VARIANT_TRUE;

WorkbooksPtr pBooks=pXL - & gt; Workbooks.
_WorkbookPtr pBook=pBooks - & gt; Add ((long) xlWorksheet);
_WorksheetPtr pSheet=pXL - & gt; ActiveSheet.

RangePtr pRange.
PRange=pSheet - & gt; Range [A21 "];
PRange - & gt; Value2=75 l;
//pRange - & gt; NumberFormatLocal="@".

_CommandBarsPtr pCmdbars=pXL - & gt; CommandBars;
Int iCmdbars=pCmdbars - & gt; GetCount ();

Sleep (1000);
PRange=pSheet - & gt; Range (" he "),
PRange - & gt; Insert ((long) Excel: : xlDown);
PRange - & gt; Merge ();

Sleep (1000);

PBook - & gt; Saved=VARIANT_TRUE;
The pXL - & gt; The Quit ();
}
The catch (_com_error & amp; E)
{
Dump_com_error (e);

The pXL - & gt; The Quit ();
}
}


CodePudding user response:

COM when using, need
The definition of the interface and every,
You see to you. The idl document is ok,

Create a service,
IXXX pXXX=NULL;
Retrieves the hr=CoCreateInstance (& lt; Classid> , NULL, IID_PPV_ARGS (& amp; PXXX));
//use IXXX instance methods,
PXXX - & gt; Release ();//use after the release of,

People usually have provided sample, first take a look at,

CodePudding user response:

reference Saleayas reply: 3/f
COM when using, need
The definition of the interface and every,
You see to you. The idl document is ok,

Create a service,
IXXX pXXX=NULL;
Retrieves the hr=CoCreateInstance (& lt; Classid> , NULL, IID_PPV_ARGS (& amp; PXXX));
//use IXXX instance methods,
PXXX - & gt; Release ();//use after the release of,

People usually have provided sample, first take a look at,

Have the idl file, but the idl file is loaded into the compiler, the compiler will generate the corresponding. H and. C file, these all have, they use the include included can call library functions? My question is a little bit more, a great god, can you leave your contact information, thanks

CodePudding user response:

refer to the second floor 4 teacher zhao response:
are for reference only:
//Copyright (C) 1992-1998 Microsoft Corporation 
//All rights reserved.
//
//This source code is only intended as a supplement to the
//Microsoft Visual c + + Language Reference and related
//electronic documentation provided with Microsoft Visual c + +.
//See these sources for detailed information regarding the
//Microsoft Visual c + + product.

//NOTE: This example will only work with Excel8 Office97 in
//the Compile with cl/GX comexcel. CPP
//TO DO: Edit the # import paths
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related