I am calling a c++ dll in vb...
Everything is working fine..
Just i am unable to write the vb code in order to perform the require action...

Code for calling the c++ dll in vb

Private Declare Function do_encrypt Lib "AES.dll" (ByVal text As String, ByVal keyz As String) As String

So i have 3 text boxes and a command button on the form
text1.text = takes text
text2.text = takes keyz
and when i click on Command1_Click() the result must be displayed in text3
I have tried

Private Sub Command1_Click()
Text3.text = Str(do_encrypt, Val(Text1.text), Val(Text2.text))
End Sub

Its not working can anyone help how we can solve the problem

Hello I have tired to change the code in the comand1_click() to


but still getting errors...
I am posting the codes in zip file...
Can anyone help how we can solve the problem....

I am calling a c++ dll in vb..
The c++ code function is returning a value as a double...

double _stdcall aesen(string path1, string path2, string path3)
{double time;
    return time;

Now in the VB code:-I have called the example2.dll

Private Declare Function aesen Lib "example2.dll" (ByVal path1 As String, ByVal path2 As String, ByVal path3 As String) As String

Now I want to get the time in the textbox5
I have wriiten the code:-

Private Sub Command5_Click()
Text5.text = aesen(Text1.text, Text2.text, Text3.text)
End Sub

Its not responding and i have to end the program...
Can anyone help...

did you try to register the dll with your operating system?

if not then try using this command :-

regsvr32 <your dll file name>.Dll

then create a reference to the file from Project->References

No i have not registered the dll with the OS...
I will try it...
Btw can we have cout/printf statements inside the dll and will it work correctly?...

I am posting a new code in zip format...
Can anyone help just to be able to call the function aesen from the c++ dll and display the time in one of the textbox...
I have tried a function that converts low case letters to uppercase its working...
When running the vb forms text2.text takes p.txt and text3.text = encrypt.txt and text4.text= text.txt and the button encrypt must display the time for the keyshe_time...
The time that is returned in the c++ dll
Can anyone help me to solve this problem...

I have a function written in c++ to get the size of a file...
I have tested it by calling it in the main...
Thats working fine...Now i have created a dll of the code and call it form the vb
Now if i call it from the vb i am getting an error message c++ assertion debug,abort,retry
The c++ code...

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <windows.h>
#include <string.h>
#include <memory.h>
#include <process.h>
#include <tchar.h>
#include <dos.h>
#include <conio.h>
#include <fstream>
#include <string>
# include <bitset>
#include <cstring>
#include <algorithm>
using namespace std;

#include <time.h>

int _stdcall ss(string de)
    int size;
    ifstream myfile456 (de.c_str(), ios::binary);
	myfile456.seekg (0, ios::end);
	size = myfile456.tellg();
	cout << "File size is: " << size << " bytes.\n";
	return (size);

int main()
	return 0;

Thats working fine...
In the VB code i am calling it by...using this code that is the dll

Private Declare Function ss Lib "testing.dll" (ByVal de As String) As Integer

Now in the vb code i have a browse button to select the file p.txt and i get the path in a textbox2..That is i open the file p.txt and gets its path in the textbox2..
Now when i click the button 1 its not working...and i have to display the size of the file in the textbox3

Private Sub Command1_Click()
Text3.Text = ss(Text2.Text)
End Sub

Can anyone help to solve the problem..

I hope you realize that std::string in c++ programs is not the same as a String in VB. The function exported in the dll needs to be written in such a way that it can be called from languages other than c++, such as this: int _stdcall ss(const char* de) or this int _stdcall ss(VARIANT* de)

It is always recommended to register the component with windows and then use it in VB 6.0.
Add the same from Project---->References

and then use it.

I have a c++ code(function) which returns the time in double...
Now i am calling this function in VB and i am displaying the time in a textbox...
I am getting a different value...

double encryptTime, Add, sub, sft, mix;
int _stdcall encrypt()
{// calculate add sub sft mix
encryptTime = Add + sub + sft + mix;
printf("Encrytion Time : ");
printf("%lf ", encryptTime);
return 0;

double _stdcall encrypt_Encryption_Time()
	return (encryptTime);

The time i am getting is:-

0.000142 seconds

The c++ dll is called in VB:-

Private Declare Function encrypt Lib "example2.dll" () As Integer
Private Declare Function encrypt_Encryption_Time Lib "example2.dll" () As Double

The command button to click and display the value in a textbox

Private Sub Command6_Click()
Call Encrypt_Text()
Text11.text = encrypt_Encryption_Time()
End Sub

I am getting the time on the textbox11 as


Can anyone help to solve the problem..

I think that the problem is with the return type of the function that is double...
Is double in c++ and VB the same?
That is if i am returning a double in a function in c++ and display the returned value in a textbox in VB...will it work correctly?...

It is always recommended to register the component with windows and then use it in VB 6.0.
Add the same from Project---->References

and then use it.

Most dlls can not be registered.

In fact i am able to call a function which returns an int from a c++ code and display the value in the vb textbox... thats works fine...
Now i am calling the c++ function which returns a double and i am displaying the values in the vb textbox it is not displaying the correct value...

Original value: 0.000142
Value on the vb textbox: 1.42476208568407E-04

How can we solve the problem..

>> it is not displaying the correct value
Yes it is -- it is displaying it in scientific notation. You can do the same thing in C by using "%e" instead of "%f", for example:

int main()
    double x = 0.000142;
    printf("%f\n", x);
    printf("%e\n", x);
    return 0;

Press any key to continue . . .

Hello Ancient Dragon,
Thnx again the tutorial that really help me out to solve the problem....
The tutorial link is as follows: http://www.cyberiapc.com/master/vblesson6-4.htm
I have modified the code as follows so that VB displays the values on the textbox as the user wants to display it in a format specified by him...
The modified code is as follows:-

Text11.text = Format(encrypt_Encryption_Time(), "#.######")

The output on the textbox is as: 0.000142
Thanks Ancient Dragon for the help...

This article has been dead for over six months. Start a new discussion instead.