从vb调用c ++ dll [英] calling a c++ dll from a vb

查看:213
本文介绍了从vb调用c ++ dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的按钮,使用vb从c ++调用动态dll文件.

请帮忙
我被困

这是我的c ++ dll文件:hello world

I''m trying to create a simple button that call to a dynamic dll file from c++ using vb.

Please help
I''m stuck

Here is my c++ dll file: hello world

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include<algorithm>
#include<stdexcept>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_drf.h>
#include <uf_object_types.h>

#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))

static int report( char *file, int line, char *call, int irc)
{
    if (irc)
    {
        char    messg[133];
        printf("%s, line %d:  %s\n", file, line, call);
        (UF_get_fail_message(irc, messg)) ?
            printf("    returned a %d\n", irc) :
            printf("    returned error %d:  %s\n", irc, messg);
    }
    return(irc);
}

static void do_ugopen_api(void)
{
/******************************************************************
 *
 * UG/Open API calling GRIP sample program
 *
 * Define the argument structure needed for communication of
 * parameters to GRIP for this application. Pass the parameters for
 * masking and single selection. Receive the parameters concerning
 * the results of single selection. Use the results to create a
 * label.
 *
 ****************************************************************/
    double       masks[11], pick_point[3], user_response;
    tag_t        object;
    char         select_message[133], pick_view[133];
    char         *grip_exe = "J:\\NC_System\\Automation\\JUMBO\\TABLE.grx";
    int          status;
    int          grip_arg_count = 6;
    UF_args_t    grip_arg_list[6];

    /* pick_view is passed to grip, and must be initialized, even
       though it is an output character string.
    */
    pick_view[0] = '\0';

  /* Define the argument list for UG/Open API calling GRIP */
    grip_arg_list[0].type    = UF_TYPE_DOUBLE_ARRAY;
    grip_arg_list[0].length  = 11;
    grip_arg_list[0].address = masks;
    grip_arg_list[1].type    = UF_TYPE_CHAR;
    grip_arg_list[1].length  = 0;
    grip_arg_list[1].address = select_message;
    grip_arg_list[2].type    = UF_TYPE_TAG_T;
    grip_arg_list[2].length  = 0;
    grip_arg_list[2].address = &object;
    grip_arg_list[3].type    = UF_TYPE_DOUBLE_ARRAY;
    grip_arg_list[3].length  = 3;
    grip_arg_list[3].address = pick_point;
    grip_arg_list[4].type    = UF_TYPE_CHAR;
    grip_arg_list[4].length  = 0;
    grip_arg_list[4].address = pick_view;
    grip_arg_list[5].type    = UF_TYPE_DOUBLE;
    grip_arg_list[5].length  = 0;
    grip_arg_list[5].address = &user_response;

  /* Initialize the input arguments to the GRIP program */
  /* masks[0] is the count of mask types */
    masks[0] = 2;
    masks[1] = UF_point_type;
    masks[2] = UF_line_type;
    strcpy (select_message, "Select A Point Or A Line.");

  /* Execute the GRIP program */
    status = UF_CALL(UF_call_grip (grip_exe, grip_arg_count,
                            grip_arg_list));
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
    if (!UF_CALL(UF_initialize()))
    {
        do_ugopen_api();
        UF_CALL(UF_terminate());
    }
}

int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_IMMEDIATELY);
}




这是我的vb代码:




Here is my vb code:

Private Declare Function hello Lib "HELLO WORLD.dll" ()

Private Sub Command1_Click()
ChDir "J:\users\Huynh\cplus\HELLO WORLD\Debug"
Call hello
End Sub



我收到一条错误消息453,找不到DLL条目



I get an error message of 453 cannot find dll entry

推荐答案

您需要这样的想法:
You need somethink like that:
EXPORTS
    hello


在您的"hello world.def"中


in your "hello world.def"


我不是使用VB的专家,但我曾想过该声明实际上需要一个名为从DLL导出"hello".

至少您应该从RealBASIC调用它,这是我最近的参考点.

干杯,



PS:顺便说一句,您真的需要所有这些标头吗?如果确实要包括它们,为什么不实际使用它们中的某些功能来简化代码呢?
I''m not a great expert in using VB, but I''d have thought with that declaration you''d actually need a function called "hello" to be exported from the DLL.

At least you would to call it from RealBASIC which is my nearest point of reference.

Cheers,

Ash

PS: BTW do you really need all those headers? And if you do want to include them why not actually use some of the facilities from them to simplify your code?


这篇关于从vb调用c ++ dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆