|
您的浏览器不支持Flash或者不支持Javascript脚本
|
|
 |
|
 |
|
|
|
|
.
| wyhw |  |   等级:总版主  财产:11501 元  经验:8987 值  魅力:9023 点  注册:2001-12-5 登录:2008-8-22 来自:已设成保密 文章:739 篇
|
|
|
.
| wyhw |  |   等级:总版主  财产:11501 元  经验:8987 值  魅力:9023 点  注册:2001-12-5 登录:2008-8-22 来自:已设成保密 文章:739 篇
|
|
消息 资料 好友 邮件 主页 引用
|
第2楼
|
|
|
inline HRESULT ......
inline HRESULT _O111::test2_1 ( const _variant_t & Param ) {
HRESULT _hr = raw_test2_1(Param);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}
inline HRESULT _O111::test2_2 ( const _variant_t & Param ) {
HRESULT _hr = raw_test2_2(Param);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}
Public Sub test2_1(Optional ByVal Param As Variant = -1)
End Sub
Public Sub test2_2(ByVal Param As Variant)
End Sub
发帖时间:2003-4-23 16:19:48
|
|
|
|
|
.
| wyhw |  |   等级:总版主  财产:11501 元  经验:8987 值  魅力:9023 点  注册:2001-12-5 登录:2008-8-22 来自:已设成保密 文章:739 篇
|
|
消息 资料 好友 邮件 主页 引用
|
第3楼
|
|
|
1.Get the class......
1.Get the class Id of the component.
To do this you can go to the registry and get the associated class ID or use the API CLSIDFromProgID to get the classID for the given progID.
To know more about this, check out the article in MSDN http://msdn.microsoft.com/library/techart/offaut.htm
2.Start the server using the CoCreateInstance
3.. then the rest.
The program would look like this
#include <windows.h>
#include <ole2.h> // Core OLE support
#include <dispatch.h> // IDispatch/Automation support
#include <olenls.h> // National Language support for LOCALE constants
#include <stdio.h>
#include <stdarg.h> // For variable-argument use in AutoWrap16()
#include <stdlib.h> // For _exit() in AutoWrap16()...
main()
{
HRESULT hRes = CoInitialize(NULL);
// Get CLSID for our server...
CLSID clsid;
HRESULT hr = CLSIDFromProgID("Excel.Application", &clsid);
// Start the server...
IUnknown *pUnk = NULL;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IUnknown, (void **)&pUnk);
// Query for IDispatch
IDispatch *pDispRoot = NULL;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDispRoot);
// Get App IDispatch
IDispatch *pDispApp = NULL;
{
VARIANT result;
VariantInit(&result);
AutoWrap16(DISPATCH_PROPERTYGET, &result, pDispRoot,
"Application", 0);
pDispApp = result.pdispVal;
}
// Set Visible...
{
VARIANT parm;
parm.vt = VT_I4;
parm.lVal = 1;
AutoWrap16(DISPATCH_PROPERTYPUT, 0, pDispApp, "Visible", 1,
parm);
}
// Get Workbooks collection...
IDispatch *pDispBooks = NULL;
{
VARIANT result;
VariantInit(&result);
AutoWrap16(DISPATCH_PROPERTYGET, &result, pDispApp,
"Workbooks", 0);
pDispBooks = result.pdispVal;
}
// Call Workbooks::Add()...
IDispatch *pDispBook = NULL;
{
VARIANT result;
VariantInit(&result);
AutoWrap16(DISPATCH_METHOD|DISPATCH_PROPERTYGET, &result,
pDispBooks, "Add", 0);
pDispBook = result.pdispVal;
}
// Get ActiveSheet...
IDispatch *pDispSheet = NULL;
{
VARIANT result;
VariantInit(&result);
AutoWrap16(DISPATCH_PROPERTYGET, &result, pDispBook,
"ActiveSheet", 0);
pDispSheet = result.pdispVal;
}
// Set a range of values...
for(int i=1; i<10; i++) {
for(int j=1; j<10; j++) {
// Get Range object (i,j)...
IDispatch *pDispRange = NULL;
{
VARIANT result;
VariantInit(&result);
VARIANT p1, p2;
p1.vt = p2.vt = VT_I4;
p1.lVal = i;
p2.lVal = j;
AutoWrap16(DISPATCH_PROPERTYGET, &result, pDispSheet,
"Cells", 2, p2, p1);
pDispRange = result.pdispVal;
}
// Set Range.Value to i*j
{
VARIANT parm;
parm.vt = VT_I4;
parm.lVal = i*j;
AutoWrap16(DISPATCH_PROPERTYPUT, 0, pDispRange, "Value",
1, parm);
}
// Release Range...
pDispRange->Release();
}
}
//ShowMsg("Preparing to clean up...");
// Clean up...
pDispSheet->Release();
pDispBook->Release();
pDispBooks->Release();
pDispApp->Release();
pDispRoot->Release();
pUnk->Release();
CoInitialize();
}
发帖时间:2003-4-23 16:21:31
|
|
|
|
|
.
| wyhw |  |   等级:总版主  财产:11501 元  经验:8987 值  魅力:9023 点  注册:2001-12-5 登录:2008-8-22 来自:已设成保密 文章:739 篇
|
|
消息 资料 好友 邮件 主页 引用
|
第4楼
|
|
|
Q171583 - HOWTO......
Q171583 - HOWTO: Fill a 32-bit VBA Array of UDType via a Visual C++ DLL, Microsoft
Q175030 ?HOWTO: Enumerate Application in Win32, Microsoft
Q177218 ?HOWTO: Return Array to VB from VC++ DLL or OLE Server, Microsoft
Q181444 - HOWTO: Pass an Automation Object from VB to a Visual C/C++ DLL, Microsoft
Q188541 ?INFO: Visual Basic Requirements for Using Exported DLLs, Microsoft
Q194609 ?HOWTO: Pass Array of UDTs with Variable Length Strings to C/C++, Microsoft
Q207931 ?HOWTO: Pass Array Between Visual Basic and C, Microsoft
Antonio Giuliana, Una DLL per il VB, CP Disk n. 14, dicembre 1994, Ed. Infomedia
Bruce McKinney, Extending Visual Basic with C++ DLLs, 1996, Microsoft Press
Bruce McKinney, Strings the OLE Way, 1996, Microsoft Press
Bruce McKinney, The Safe OLE Way of Handling Arrays, 1996, Microsoft Press
Don Box, Q & A: OLE, June 1996, Microsoft Systems Journal
Steven Roman, WIN32 API Programming with Visual Basic (chap. 6: Strings), O扲eilly & Associates Inc.
发帖时间:2003-4-23 16:43:06
|
|
|
|
|
|
|
|
 |
|
 |
|