应该是对应于vc中SAFEARRAY吧。
使用result[i]:="...";应该会有问题吧?除非你的程序将不用于跨进程;不过那样也就没有必要用这种对象了。

解决方案 »

  1.   

    to duz(肚子) 使用result[i]:="..."; 是可以的
    在Delphi调用如var 
    aVariant:OleVariant;
    begin
       aVariant:=Get_Records('abc')
       showmessage(aVariant[2]);
    end;
      

  2.   

    result 改成return呀
    不知行不行?
      

  3.   

    Function Get_Records(Name:phar):OleVariant;Stdcall;
    var res:olevariant;
    begin
        res:= VarArrayCreate([0,2],varVariant);
        res[0]:='1234567';
        res[1]:='adsfasdf';
        res[2]:='asdfasdf';
        resutl:=res;
    end;
      

  4.   

    如果真的不行,改成这样呢?
    procedure Get_Records(Name:phar;var Res:OleVariant);Stdcall;
    ...呵呵,VC我不懂的,Delphi也学了没几天。(蹭分来了:)
      

  5.   

    procedure Get_Records(Name:phar;var Res:OleVariant);Stdcall;
    改成这样效果不是一样??
      

  6.   

    C++ 的函数申明应当是:
    VARIANT* Get_Records(char* name);
    使用:
    VARIANT* t=Get_Records(char* name);
    BSTR b1=t->bstrVal;
    t++;
    BSTR b2=t->bstrVal;
    t++;
    BSTR b3=t->bstrVal;可能是这样,没有验证过.
      

  7.   

    to longx() 
    我去试试看 :)
      

  8.   

    请到:http://www.csdn.net/expert/topic/167/167323.shtm来解决问题!
      

  9.   

    急死我了,拿不到分。我以前也遇到过同样的问题,问了csdn后都不会,后来到microsoft的新闻组给解决了,那里高人多多,可惜现在他给我的答案找不到了,不然就可以挣到3000分了。
    强烈建议去microsoft或borland去查询新闻组,很多人问safearray的问题,保你一天就解决。
      

  10.   

    Dll的代码在这里:202.96.112.122/plastic/jera/dll.zip
      

  11.   

    分在
    http://www.csdn.net/expert/topic/167/167849.shtm
    http://www.csdn.net/expert/topic/167/167848.shtm
    http://www.csdn.net/expert/topic/167/167846.shtm
    http://www.csdn.net/expert/topic/167/167844.shtm
    http://www.csdn.net/expert/topic/167/167838.shtm
    http://www.csdn.net/expert/topic/167/167842.shtm
    http://www.csdn.net/expert/topic/167/167835.shtm
    http://www.csdn.net/expert/topic/167/167843.shtm
    http://www.csdn.net/expert/topic/167/167833.shtm
    http://www.csdn.net/expert/topic/167/167837.shtm
      

  12.   

    其实很简单啦!很多API都有这种情况啦!你需要在函数中用Var参数返回数组长度:
    Function Get_Records(Name:phar;Var iLength:Integer):OleVariant;Stdcall;
    begin
        result:= VarArrayCreate([0,2],varVariant);
        result[0]:='1234567';
        result[1]:='adsfasdf';
        result[2]:='asdfasdf';
        Length:=3;
    end;然后在调用时先给字符串数组类型的变量分配内存,再赋值!
      

  13.   

    你把我的意思搞错了,这是我一个Dll的简化例子我主要的问题是VC++如何使用COleVariant这个类来使用这个函数
      

  14.   

    Delphi我不懂,
    但是DLL返回值只能是32为的DWORD数值,兄弟你用的,倒有点象是需要使用OLE、ACTIVEX之类的!!
      

  15.   

    在C++Builder下如下调用可以实现,而为了在VC中调用,必须提供Variant类的实现,可以从C++Builder中拷贝复制该类的实现(参考C++Builder的include/vcl/sysdefs.h和source/vcl/variant.cpp作简化修改),这样应该可以,而由于COleVariant的实现不同于Variant,故应该不能套用OleVariant,只能自己在VC中实现Variant类,并用下面方法调用
      typedef Variant ( pascal* GetRecordsProc)( char *name );
      HMODULE hInst;
      GetRecordsProc Get_Records;  hInst = LoadLibrary( "testdll.DLL" );
      if ( hInst == 0 ) {
         ShowMessage( "不能找到动态链接库!");
         return;
      }  try {
        Get_Records = (GetRecordsProc)GetProcAddress( hInst, PSTR(MAKELONG( 100, 0)) );
        if (0 == Get_Records) {
            ShowMessage( "不存在函数Get_Records");
            FreeLibrary( hInst );
            return;
        }    Variant v;
        Variant *vx;    v = Get_Records( NULL );
        vx = (Variant *)v.ArrayLock();
        ShowMessage( vx[2] );
        v.ArrayUnlock();
        FreeLibrary( hInst );
      }
      catch (... ) {
          FreeLibrary( hInst );
      }
      

  16.   

    sorry, 上面的一句有笔误:“...而由于COleVariant的实现不同于Variant,故应该不能套用OleVariant,只能自己在VC中实现Variant类...”应为“...而由于COleVariant的实现不同于Variant,故应该不能套用COleVariant,只能自己在VC中实现Variant类...”,C++Builder另定义了OleVariant类(从Variant派生),它不同于COleVariant类。你也可在VC中实现OleVariant类(方法参我的前一贴),这样你可直接使用OleVariant代替Variant