将结构数组从Visual Basic 5.0传递到Visual C 5.0编写的dll

将结构数组从Visual Basic 5.0传递到Visual C 5.0编写的dll,dll,Dll,我想将一组结构从Visual Basic 5.0传递到32位Visual C 5.0编写的dll survey32.dll。在dll端,所有记录的所有元素都是垃圾,很快就会导致APCRASE。显然,问题在于试图将结构数组传递给dll。我不知道我做错了什么,因为我反复检查了声明、定义和函数调用及其参数的语法 详情如下。为简洁起见,省略了dll的各种其他结构成员(所有类型为long或double)和本地函数: 在VISUAL BASIC中: '****************** survey32

我想将一组结构从Visual Basic 5.0传递到32位Visual C 5.0编写的dll survey32.dll。在dll端,所有记录的所有元素都是垃圾,很快就会导致APCRASE。显然,问题在于试图将结构数组传递给dll。我不知道我做错了什么,因为我反复检查了声明、定义和函数调用及其参数的语法

详情如下。为简洁起见,省略了dll的各种其他结构成员(所有类型为long或double)和本地函数:

在VISUAL BASIC中:

'******************  survey32.dll Exportable Subroutine:  *******************  
                                  'declaration of the subroutine to pass  
                                  'the entire array of structure records  
                                  'as a procedure argument by reference  
Public Declare Sub GetPolygon Lib "survey32.dll" Alias "_GetPolygon@8" _  
   (ByRef survey_data() As SURVEY_REC, ByRef survey_summary As SURVEY_SUM)  


'***************************  General Constants  ****************************  
Public Const NUMELEM = 10          'maximum number of sides in the polygon  


'***************************  Record Structures  ****************************  
Public Type SURVEY_REC             'global survey data record structure  
    bearing_deg As Long            'bearing (degrees)  
    bearing_min As Long            'bearing (minutes)  
    bearing_sec As Long            'bearing (seconds)  
    meridian As Long               'meridian reference line, N (decimal 78)  
                                   'or S (decimal 83)  
    deviation As Long              'deviation from meridian reference line,  
                                   'E (decimal 69) or W (decimal 87)  
    course_length As Double        'length of course, ft  
    x As Double                    'adjusted coordinate pair (x,y) of  
    y As Double                    'station  
    End Type  

Public Type SURVEY_SUM            'global survey summary structure  
    num_elements As Long          'number of traverse data points  
    total_length As Double        'total perimeter length, ft  
    total_area As Double          'total polygon area, sq-ft  
End Type  


'**************************  Array Declarations  ****************************  
Public survey_data(NUMELEM) As SURVEY_REC 'array of survey data structure records  
Public survey_summary As SURVEY_SUM   'the survey summary structure  
在VB监视窗口中,这些值存储在传递到dll的每条记录的各个成员中:

survey_data(0)  
    bearing_deg : 47 : Long  
    bearing_min : 16 : Long  
    bearing_sec : 19 : Long  
    course_length : 65.06 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
   y : 0 : Double  

survey_data(1)  
    bearing_deg : 3 : Long  
    bearing_min : 12 : Long  
    bearing_sec : 57 : Long  
    course_length : 49.54 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(2)  
    bearing_deg : 76 : Long  
    bearing_min : 39 : Long  
    bearing_sec : 59 : Long  
    course_length : 147.51 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(3)  
    bearing_deg : 20 : Long  
    bearing_min : 32 : Long  
    bearing_sec : 51 : Long  
    course_length : 63.2 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(4)  
    bearing_deg : 60 : Long  
    bearing_min : 20 : Long  
    bearing_sec : 23 : Long  
    course_length : 139.04 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  


survey_summary  
    num_elements : 5 : Long  
    total_length : 0 : Double  
    total_area : 0 : Double  
GetPolygon survey_data(), survey_summary  
/******   CONSTANTS   ******/  
#define NUMELEM        (10)       //number of expected survey points  


/******   GLOBAL VARIABLES   ******/  
                                  //define the global survey data  
struct SURVEY_REC {               //record structure  
              long bearing_deg;   //bearing (degrees)  
              long bearing_min;   //bearing (minutes)  
              long bearing_sec;   //bearing (seconds)  
              long meridian;      //meridian reference line, N (decimal 78)  
                                  //or S (decimal 83)  
              long deviation;     //deviation from meridian reference,  
                                  //E (decimal 69) or W (decimal 87)  
              double course_length;   //length of course (ft)  
              double x;           //adjusted coordinate pair (x,y) of a  
              double y;           //station  
              };  

struct SURVEY_SUM {                   //define the global survey summary  
                                      //structure  
              long num_elements;      //number of traverse data points  
              double total_length;    //total course length (ft)  
              double total_area;      //total polygon area (sq-ft)  
              };  


struct SURVEY_REC **survey_data;  //array of pointers to the survey data  
                                  //structure  

struct SURVEY_SUM *survey_summary;   //declare an instance of a pointer  
                                     //to the survey summary structure  


/******   FUNCTION DECLARATIONS   ******/  

//functions global to program and exportable (called outside of the dll):  
extern DllExport VOID __stdcall GetPolygon (struct SURVEY_REC **survey_data,  
                                            struct SURVEY_SUM *survey_summary);  

//functions local to this module, not exportable:  
static VOID   __stdcall CalcTraverseAzimuths (struct SURVEY_REC *survey_data,  
                                              long num_elements);  
survey_data[0]  
    bearing_deg : 1179649 : Long  
    bearing_min : 176 : Long  
    bearing_sec : 0 : Long  
    bearing_DecDeg : 1179651.9333333 : double  
    bearing_Radians : 20588.810437266 : double  
    course_length : 9.8813129...e-324 : Double  
    deviation : 1947014728 : Long  
    meridian : 5311368 : Long  
    x : 1.6021618...e-306 : Double  
    y : 1.6911933...e-306 : Double  
这是对dll的Visual Basic调用:

survey_data(0)  
    bearing_deg : 47 : Long  
    bearing_min : 16 : Long  
    bearing_sec : 19 : Long  
    course_length : 65.06 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
   y : 0 : Double  

survey_data(1)  
    bearing_deg : 3 : Long  
    bearing_min : 12 : Long  
    bearing_sec : 57 : Long  
    course_length : 49.54 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(2)  
    bearing_deg : 76 : Long  
    bearing_min : 39 : Long  
    bearing_sec : 59 : Long  
    course_length : 147.51 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(3)  
    bearing_deg : 20 : Long  
    bearing_min : 32 : Long  
    bearing_sec : 51 : Long  
    course_length : 63.2 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(4)  
    bearing_deg : 60 : Long  
    bearing_min : 20 : Long  
    bearing_sec : 23 : Long  
    course_length : 139.04 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  


survey_summary  
    num_elements : 5 : Long  
    total_length : 0 : Double  
    total_area : 0 : Double  
GetPolygon survey_data(), survey_summary  
/******   CONSTANTS   ******/  
#define NUMELEM        (10)       //number of expected survey points  


/******   GLOBAL VARIABLES   ******/  
                                  //define the global survey data  
struct SURVEY_REC {               //record structure  
              long bearing_deg;   //bearing (degrees)  
              long bearing_min;   //bearing (minutes)  
              long bearing_sec;   //bearing (seconds)  
              long meridian;      //meridian reference line, N (decimal 78)  
                                  //or S (decimal 83)  
              long deviation;     //deviation from meridian reference,  
                                  //E (decimal 69) or W (decimal 87)  
              double course_length;   //length of course (ft)  
              double x;           //adjusted coordinate pair (x,y) of a  
              double y;           //station  
              };  

struct SURVEY_SUM {                   //define the global survey summary  
                                      //structure  
              long num_elements;      //number of traverse data points  
              double total_length;    //total course length (ft)  
              double total_area;      //total polygon area (sq-ft)  
              };  


struct SURVEY_REC **survey_data;  //array of pointers to the survey data  
                                  //structure  

struct SURVEY_SUM *survey_summary;   //declare an instance of a pointer  
                                     //to the survey summary structure  


/******   FUNCTION DECLARATIONS   ******/  

//functions global to program and exportable (called outside of the dll):  
extern DllExport VOID __stdcall GetPolygon (struct SURVEY_REC **survey_data,  
                                            struct SURVEY_SUM *survey_summary);  

//functions local to this module, not exportable:  
static VOID   __stdcall CalcTraverseAzimuths (struct SURVEY_REC *survey_data,  
                                              long num_elements);  
survey_data[0]  
    bearing_deg : 1179649 : Long  
    bearing_min : 176 : Long  
    bearing_sec : 0 : Long  
    bearing_DecDeg : 1179651.9333333 : double  
    bearing_Radians : 20588.810437266 : double  
    course_length : 9.8813129...e-324 : Double  
    deviation : 1947014728 : Long  
    meridian : 5311368 : Long  
    x : 1.6021618...e-306 : Double  
    y : 1.6911933...e-306 : Double  
在VB开发环境中,会出现一个VB错误,“运行时错误'53':找不到文件:survey32.dll”

在VISUAL C中,这些是dll的详细信息:

survey_data(0)  
    bearing_deg : 47 : Long  
    bearing_min : 16 : Long  
    bearing_sec : 19 : Long  
    course_length : 65.06 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
   y : 0 : Double  

survey_data(1)  
    bearing_deg : 3 : Long  
    bearing_min : 12 : Long  
    bearing_sec : 57 : Long  
    course_length : 49.54 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(2)  
    bearing_deg : 76 : Long  
    bearing_min : 39 : Long  
    bearing_sec : 59 : Long  
    course_length : 147.51 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(3)  
    bearing_deg : 20 : Long  
    bearing_min : 32 : Long  
    bearing_sec : 51 : Long  
    course_length : 63.2 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(4)  
    bearing_deg : 60 : Long  
    bearing_min : 20 : Long  
    bearing_sec : 23 : Long  
    course_length : 139.04 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  


survey_summary  
    num_elements : 5 : Long  
    total_length : 0 : Double  
    total_area : 0 : Double  
GetPolygon survey_data(), survey_summary  
/******   CONSTANTS   ******/  
#define NUMELEM        (10)       //number of expected survey points  


/******   GLOBAL VARIABLES   ******/  
                                  //define the global survey data  
struct SURVEY_REC {               //record structure  
              long bearing_deg;   //bearing (degrees)  
              long bearing_min;   //bearing (minutes)  
              long bearing_sec;   //bearing (seconds)  
              long meridian;      //meridian reference line, N (decimal 78)  
                                  //or S (decimal 83)  
              long deviation;     //deviation from meridian reference,  
                                  //E (decimal 69) or W (decimal 87)  
              double course_length;   //length of course (ft)  
              double x;           //adjusted coordinate pair (x,y) of a  
              double y;           //station  
              };  

struct SURVEY_SUM {                   //define the global survey summary  
                                      //structure  
              long num_elements;      //number of traverse data points  
              double total_length;    //total course length (ft)  
              double total_area;      //total polygon area (sq-ft)  
              };  


struct SURVEY_REC **survey_data;  //array of pointers to the survey data  
                                  //structure  

struct SURVEY_SUM *survey_summary;   //declare an instance of a pointer  
                                     //to the survey summary structure  


/******   FUNCTION DECLARATIONS   ******/  

//functions global to program and exportable (called outside of the dll):  
extern DllExport VOID __stdcall GetPolygon (struct SURVEY_REC **survey_data,  
                                            struct SURVEY_SUM *survey_summary);  

//functions local to this module, not exportable:  
static VOID   __stdcall CalcTraverseAzimuths (struct SURVEY_REC *survey_data,  
                                              long num_elements);  
survey_data[0]  
    bearing_deg : 1179649 : Long  
    bearing_min : 176 : Long  
    bearing_sec : 0 : Long  
    bearing_DecDeg : 1179651.9333333 : double  
    bearing_Radians : 20588.810437266 : double  
    course_length : 9.8813129...e-324 : Double  
    deviation : 1947014728 : Long  
    meridian : 5311368 : Long  
    x : 1.6021618...e-306 : Double  
    y : 1.6911933...e-306 : Double  
在VC Watch窗口中,这些是dll传递和接收的第一条记录的各个成员中存在的值:

survey_data(0)  
    bearing_deg : 47 : Long  
    bearing_min : 16 : Long  
    bearing_sec : 19 : Long  
    course_length : 65.06 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
   y : 0 : Double  

survey_data(1)  
    bearing_deg : 3 : Long  
    bearing_min : 12 : Long  
    bearing_sec : 57 : Long  
    course_length : 49.54 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(2)  
    bearing_deg : 76 : Long  
    bearing_min : 39 : Long  
    bearing_sec : 59 : Long  
    course_length : 147.51 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 78 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(3)  
    bearing_deg : 20 : Long  
    bearing_min : 32 : Long  
    bearing_sec : 51 : Long  
    course_length : 63.2 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 69 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  

survey_data(4)  
    bearing_deg : 60 : Long  
    bearing_min : 20 : Long  
    bearing_sec : 23 : Long  
    course_length : 139.04 : Double  
    bearing_DecDeg : 0 : double  
    bearing_Radians : 0 : double  
    deviation : 87 : Long  
    meridian : 83 : Long  
    x : 0 : Double  
    y : 0 : Double  


survey_summary  
    num_elements : 5 : Long  
    total_length : 0 : Double  
    total_area : 0 : Double  
GetPolygon survey_data(), survey_summary  
/******   CONSTANTS   ******/  
#define NUMELEM        (10)       //number of expected survey points  


/******   GLOBAL VARIABLES   ******/  
                                  //define the global survey data  
struct SURVEY_REC {               //record structure  
              long bearing_deg;   //bearing (degrees)  
              long bearing_min;   //bearing (minutes)  
              long bearing_sec;   //bearing (seconds)  
              long meridian;      //meridian reference line, N (decimal 78)  
                                  //or S (decimal 83)  
              long deviation;     //deviation from meridian reference,  
                                  //E (decimal 69) or W (decimal 87)  
              double course_length;   //length of course (ft)  
              double x;           //adjusted coordinate pair (x,y) of a  
              double y;           //station  
              };  

struct SURVEY_SUM {                   //define the global survey summary  
                                      //structure  
              long num_elements;      //number of traverse data points  
              double total_length;    //total course length (ft)  
              double total_area;      //total polygon area (sq-ft)  
              };  


struct SURVEY_REC **survey_data;  //array of pointers to the survey data  
                                  //structure  

struct SURVEY_SUM *survey_summary;   //declare an instance of a pointer  
                                     //to the survey summary structure  


/******   FUNCTION DECLARATIONS   ******/  

//functions global to program and exportable (called outside of the dll):  
extern DllExport VOID __stdcall GetPolygon (struct SURVEY_REC **survey_data,  
                                            struct SURVEY_SUM *survey_summary);  

//functions local to this module, not exportable:  
static VOID   __stdcall CalcTraverseAzimuths (struct SURVEY_REC *survey_data,  
                                              long num_elements);  
survey_data[0]  
    bearing_deg : 1179649 : Long  
    bearing_min : 176 : Long  
    bearing_sec : 0 : Long  
    bearing_DecDeg : 1179651.9333333 : double  
    bearing_Radians : 20588.810437266 : double  
    course_length : 9.8813129...e-324 : Double  
    deviation : 1947014728 : Long  
    meridian : 5311368 : Long  
    x : 1.6021618...e-306 : Double  
    y : 1.6911933...e-306 : Double  
注意:一些long看起来像地址(DecDeg和Radians成员值只是从DMS值派生而来)

extern DllExport VOID\uu stdcall GetPolygon(结构测量记录**测量数据、,
结构调查(汇总*调查汇总)
/*===========================================================================  
*=========================================================================*/  
{  
long num_elements=0;//实际坐标对数
//获取导线测量数据点的数量
num\u elements=调查总结->num\u elements;
CalcTraverseAzimuths(*调查数据,数量元素);
.//为简洁起见,请使用省略号
.  
.  
返回;
}  
静态无效数据调用CalcTraverseAzimuths(结构测量记录测量数据,
长num_元素)
/*===========================================================================  
*=========================================================================*/  
{  
寄存器int i;
经络长;
长偏差;
对于(i=0;i
在VC开发环境内部的CalcTraverseAzimuths()中,您会得到一个VC错误,“survey.exe(SURVEY32.DLL)中未处理的异常:0xC0000005:访问冲突。”


我将非常感谢您的帮助,可能简单地说,因为我显然对自己的错误一无所知

我倾向于说您的dll没有注册,也没有在任何常用路径中注册。至少,
文件未找到:survey32.dll
对我说了这句话。我道歉。dll与可执行文件位于同一目录中。此Visual Basic错误通常发生在调用和dll的入口点之间出现问题时。调用成功,直到dll代码执行为止。只是结构数组是垃圾。我仍然相信我在一些声明、定义等语法方面犯了错误。我倾向于说,您的dll没有注册,也没有在任何常用路径中注册。至少,
文件未找到:survey32.dll
对我说了这句话。我道歉。dll与可执行文件位于同一目录中。此Visual Basic错误通常发生在调用和dll的入口点之间出现问题时。调用成功,直到dll代码执行为止。只是结构数组是垃圾。我仍然相信我在一些声明、定义等语法上犯了错误。