您的位置:程序门 -> vc/mfc -> 基础类



关于dll接收数组参数的问题!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于dll接收数组参数的问题!
发表于:2007-04-29 12:31:27 楼主
我在vc6中作了一个简单的dll,源代码如下:
.cpp文件
//   access   to   std::cout   and   std::endl
#include <stdafx.h>

//   decldir   will   perform   an   export   for   us
#define   dll_export

//   include   our   header,   must   come   after   #define   dll_export
#include   "c_dll.h "


//   get   rid   of   name   mangeling
extern   "c "
{
//   define   our   2   functions
//   add   will   return   the   sum   of   two   numbers

  int     __stdcall   tarray(int   *a,int   num)
  {
  int   i;
  int   x=0;
  x   =   a[2];

  return   x;
  }


}

.h文件
//   inclusion   guard
#ifndef   _dlltut_dll_h_
#define   _dlltut_dll_h_

//   make   our   life   easier,   if   dll_export   is   defined   in   a   file   then   decldir   will   do   an   export
//   if   it   is   not   defined   decldir   will   do   an   import
#if   defined   dll_export
#define   decldir   stdcall(dllexport)
#else
#define   decldir   stdcall(dllimport)
#endif

//   specify   "c "   linkage   to   get   rid   of   c++   name   mangeling
extern   "c "
{
//   declare   1   functions
            int   __stdcall     tarray(int   *a,int   num);
}

//   end   the   inclusion   guard
#endif

.def文件
library dll_tutorial ;   specify   the   name   of   the   dll   and   lib
description   "our   simple   dll "         ;   tell   people   what   it   does
exports ;   export   our   functions
tarray   @1

我在vb中如下定义:
  private   declare   function   tarray   lib   "d:\test\c_dll.dll "   (byref   samplea()   as   long,   byval   numsam   as   long)   as   long

调用代码如下:
private   sub   command2_click()
      dim   x(6)   as   long
      dim   y   as   long
           
      x(0)   =   6
      x(1)   =   1
      x(2)   =   2
      x(3)   =   3
      x(4)   =   4
      x(5)   =   50
     
      y   =   tarray(x,   6)
       
end   sub
调用结果y是0,为什么?我哪里写错啦,没看出来吗?请高手指点
发表于:2007-04-29 13:54:161楼 得分:0
怎么没人回呢?看贴子的可以帮我up


快速检索

最新资讯
热门点击