请问高手,怎样在VC的DLL里返回一个整型数组让VB接收,多谢指教,最好能给一个例子,谢谢

解决方案 »

  1.   

    你在vb的部件中引用它
    然后 dim a as 那个部件
         set a = new 那个部件就可以了
         参数可以a.什么什么就行了
      

  2.   

    #include <windows.h>
    #include <oleauto.h>
    //complier comment: cl NewLongs.cpp /LD kernel32.lib oleaut32.lib
    extern "C" __declspec(dllexport) short __stdcall NewArray(LPSAFEARRAY *ppsa)
    {
        LPSAFEARRAY psa;
        SAFEARRAYBOUND sa;    sa.lLbound = 1;
        sa.cElements = 10;    if (*ppsa == NULL) //没有初始化
        {
            if ((psa = SafeArrayCreate(VT_I2, 1, &sa)) == NULL)
                return -2;
            *ppsa = psa;
        }    if ((*ppsa)->cDims != 1)    // 检查数组的维数(1维数组)
            return -1;    else        return -3;
        
        return 0;
    }Private Declare Function NewIntArray Lib "NewLongs.dll" Alias "_NewArray@4" (FistElement() As Integer) As LongVB
    Dim a(1) As Integer
    Dim b() As IntegerMsgBox NewIntArray(a) & ":  " & LBound(a) & "  : " & UBound(a)
    MsgBox NewIntArray(b) & ":  " & LBound(b) & "  : " & UBound(b)