>> 欢迎您,客人请先登陆| 注册收藏新贴搜索帮助
 
您的浏览器不支持Flash或者不支持Javascript脚本
中国.Net论坛
『 VB.Net 』
  How to pass Array Variant VB 《--》 VC
  
:::发表一个新主题::::::发表一个投票帖子::::::回复这个主题::: 返回      快速向下
 *贴子主题: 『 VB.Net 』 [ How to pass Array Variant VB 《--》 VC ]    [结贴]
保存该页为文件   报告本帖给版主   立即打印本页  把本贴打包邮递     发送本页面给朋友   把本贴加入IE收藏夹 
.
wyhw帅哥离线,给我留言吧!
 
 
等级:总版主 级别指数20
财产:11501 元 流通货币
经验:8987 值 资格证明
魅力:9023 点 尊崇指数
注册:2001-12-5
登录:2008-8-22
来自:已设成保密
文章:739 篇 已经发表的文章
给wyhw发消息消息  查看wyhw的资料资料  加wyhw为好友好友  电子邮件地址邮件  wyhw的主页主页  引用回复引用  1

How to pass Array Variant VB 《--》 VC
I have problem in VC++ server developed using ATL
I have written a Server Component object as follows

This takes an input parameter which is a an array of variants. If I call this method from a VC++ client it works fine but if this is called from a VB Client I am getting an error. The VB client code is also given below

STDMETHODIMP CDCOMServer::readData( VARIANT  arrData,VARIANT* arrRes)
{
   // TODO: Add your implementation code here
try
{
   char buf[200];
   VARIANT varRes;  // variabke to store return data
   VariantInit(&varRes);  // initialize the data

   if(arrData.vt != VT_ARRAY)
   {
      sprintf(buf", The data input is not an Array");
      throw(buf);
   }



VB Code client

Dim bError As Boolean
Dim i As Integer
Dim inData() As Variant
Dim outData() As Variant

    Set objServer = CreateObject("DCOMServer.DCOMAtl")
    
    ReDim inData(cInParams.Count) As Variant
    For i = 0 To cInParams.Count - 1
        inData(i) = CVar(cInParams.Item(i + 1))
        'MsgBox inData(i) & " " & VarType(inData(i))
    Next i
    
    bError = objServer.ReadData(inData, outData)
   
  

solution:
When calling from your VB code arrData.vt will be: 
arrData.vt == VT_ARRAY | VT_VARIANT 

You check for VT_ARRAY only and it throws an exception... 


发帖时间:2003-4-23 16:01:25

2002-2008年度微软最有价值专家。
让我们一起进步,共享人类的技术资源。

欢迎注册使用普通人的 MBlogger
.
wyhw帅哥离线,给我留言吧!
 
 
等级:总版主 级别指数20
财产:11501 元 流通货币
经验:8987 值 资格证明
魅力:9023 点 尊崇指数
注册:2001-12-5
登录:2008-8-22
来自:已设成保密
文章:739 篇 已经发表的文章
给wyhw发消息消息  查看wyhw的资料资料  加wyhw为好友好友  电子邮件地址邮件  wyhw的主页主页  引用回复引用  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

2002-2008年度微软最有价值专家。
让我们一起进步,共享人类的技术资源。

欢迎注册使用普通人的 MBlogger
.
wyhw帅哥离线,给我留言吧!
 
 
等级:总版主 级别指数20
财产:11501 元 流通货币
经验:8987 值 资格证明
魅力:9023 点 尊崇指数
注册:2001-12-5
登录:2008-8-22
来自:已设成保密
文章:739 篇 已经发表的文章
给wyhw发消息消息  查看wyhw的资料资料  加wyhw为好友好友  电子邮件地址邮件  wyhw的主页主页  引用回复引用  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

2002-2008年度微软最有价值专家。
让我们一起进步,共享人类的技术资源。

欢迎注册使用普通人的 MBlogger
.
wyhw帅哥离线,给我留言吧!
 
 
等级:总版主 级别指数20
财产:11501 元 流通货币
经验:8987 值 资格证明
魅力:9023 点 尊崇指数
注册:2001-12-5
登录:2008-8-22
来自:已设成保密
文章:739 篇 已经发表的文章
给wyhw发消息消息  查看wyhw的资料资料  加wyhw为好友好友  电子邮件地址邮件  wyhw的主页主页  引用回复引用  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

2002-2008年度微软最有价值专家。
让我们一起进步,共享人类的技术资源。

欢迎注册使用普通人的 MBlogger
页次:1/1每页10个主题

9 7 1 8 :  跳转到第





*快速回复: How to pass Array Variant VB 《--》 VC
  • [ 还没注册 ]
  • [ 忘记密码 ]
  • [心情图标放帖子前面]
  • 内容限制

  • HTML标签:可用

  • UBB标签:允许
  • 贴图标签:允许
  • Flash标签:允许
  • 显示图片方法:
  • [img]...[/img]
  • 文字飞翔方法:
  • [fly]...[/fly]

  • [Ctrl+Enter直接提交贴子]
    快速向上

      中国.NET论坛 版权所有© 2003-1-05
    ChinaAspx.Com All Rights Reserved
    | 程序设计:飘雪 && WYHW
    京 ICP 证 041477 号
    (最佳浏览器分辨率1024*768)