Modify VB database with C++ dll. How?

Posted on 2003-03-11
Medium Priority
Last Modified: 2010-08-05
I created a dll (in c++) to modify a 2D array and return the modified 2D array. I have a database in VB with 200 records of 5 fields each. I want to use my dll to return certains fields into my VB application.

The dll function: int _stdcall pusingan1(float now1[200][5])
it returns: dahPasang[200][5];
dahPasang is declared as float
the .def file exports: pusingan1;

The dll file is successfully built:

pusingan1.dll - 0 error(s), 32 warning(s)

there are only 2 types of warnings ..

warning C4101: 'pasang1' : unreferenced local variable
warning C4244: '=' : conversion from 'float' to 'int', possible loss of data

the unreferenced local variables are for future use; the float -> integer conversion is for calculation purpose

In VB I use 2 forms : Form1 for the database & Form2 to display the required fields

I have declared the dll in both forms:

Private Declare Function pusingan1 Lib "C:\My Documents\vbPsm\pusingan1\Debug\pusingan1.dll" () As Variant

Then I want to give a variable name for my database using these steps:

Private Sub Command3_Click()
now1 = Data1.Recordset
End Sub

In Form2 I want to call the dll to modify my database but I'm not very familiar with VB.

If I use pusingan1(now1) .. error .. This program has performed an illegal operation
If I use now1.pusingan1 .. error .. run-time error '424': object required

Q1 : Please tell me how to send my database to the dll.

Then, I tried to just display a specific field from the database in the previous form using the command below:

Private Sub Command1_Click()
    Dim arrayKu As Variant
    Dim num1 As Integer

    arrayKu = now1
    num1 = arrayKu(0, 0)
    Text1.Text = num1
End Sub

The result when I press Command1 is:
run-time error '13': Type mismatch at num1 = arrayKu(0,0)

Q2 : Please tell me how to retrieve the field I want into a text box.
Question by:sheila1978
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

rd707 earned 200 total points
ID: 8118118
You can't pass a VB array in this way to a C/C++ DLL. Use a single C++ function to store a record in the C++ DLL and then call it from VB however many times you need.

Once you performed your processing on the array in C++ then have another function to return each record to VB.

N.B. I'm assuming here that you need all the records in the DLL at once to be able to perform the processing - if you process one record at a time then you can return the data in the same call.

A function to return the number of records in the DLL might be handy too.

Calls to and from VB and C/C++ can only really handle simple types such as strings and numbers. Linked lists and arrays don't work due to the different ways they're stored in memory in the two languages.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question