Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Modify VB database with C++ dll. How?

Posted on 2003-03-11
1
Medium Priority
?
190 Views
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
Form1.Hide
Form2.Show
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.
****************************************************************************
0
Comment
Question by:sheila1978
1 Comment
 
LVL 4

Accepted Solution

by:
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.
0

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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 use strings and some functions related to them in the C programming language.
Suggested Courses

564 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