Calling c++ dll in vb

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Calling c++ dll in vb

 
0
  #1
Mar 27th, 2008
Hello,
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Text3.text = Str(do_encrypt, Val(Text1.text), Val(Text2.text))
  3. End Sub
Its not working can anyone help how we can solve the problem
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Calling c++ dll in vb

 
0
  #2
Mar 28th, 2008
must be some syntax errors. rectify like this :-

Text3.text=do_encrypt(Text1.text,Text2.text)

regards
Shouvik
Last edited by choudhuryshouvi; Mar 28th, 2008 at 1:16 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #3
Mar 28th, 2008
Hello I have tired to change the code in the comand1_click() to
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Text3.text=do_encrypt(Text1.text,Text2.text)
but still getting errors...
I am posting the codes in zip file...
Can anyone help how we can solve the problem....
Attached Files
File Type: zip Vb.zip (1.61 MB, 31 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #4
Mar 29th, 2008
Hello,
I am calling a c++ dll in vb..
The c++ code function is returning a value as a double...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. double _stdcall aesen(string path1, string path2, string path3)
  2. {double time;
  3. .
  4. .
  5. .
  6. return time;
  7. }
Now in the VB code:-I have called the example2.dll
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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:-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command5_Click()
  2. Text5.text = aesen(Text1.text, Text2.text, Text3.text)
  3. End Sub
Its not responding and i have to end the program...
Can anyone help...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Calling c++ dll in vb

 
0
  #5
Mar 29th, 2008
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
Last edited by choudhuryshouvi; Mar 29th, 2008 at 11:44 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #6
Mar 29th, 2008
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?...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #7
Mar 29th, 2008
Hello,
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...
Attached Files
File Type: zip c++ code + dll.zip (147.7 KB, 15 views)
File Type: zip vb_code.zip (134.5 KB, 22 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #8
Mar 30th, 2008
Hello,
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...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <assert.h>
  5. #include <windows.h>
  6. #include <string.h>
  7. #include <memory.h>
  8. #include <process.h>
  9. #include <tchar.h>
  10. #include <dos.h>
  11. #include <conio.h>
  12. #include <fstream>
  13. #include <string>
  14. # include <bitset>
  15. #include <cstring>
  16. #include <algorithm>
  17. using namespace std;
  18.  
  19. #include <time.h>
  20.  
  21. int _stdcall ss(string de)
  22. {
  23. int size;
  24. ifstream myfile456 (de.c_str(), ios::binary);
  25. myfile456.seekg (0, ios::end);
  26. size = myfile456.tellg();
  27. cout << "File size is: " << size << " bytes.\n";
  28. return (size);
  29. }
  30.  
  31. int main()
  32. {
  33. ss("c:/p.txt");
  34. return 0;
  35. }
Thats working fine...
In the VB code i am calling it by...using this code that is the dll
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Text3.Text = ss(Text2.Text)
  3. End Sub
Can anyone help to solve the problem..
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,624
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1494
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Calling c++ dll in vb

 
0
  #9
Mar 30th, 2008
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)
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 80
Reputation: kartouss is an unknown quantity at this point 
Solved Threads: 0
kartouss's Avatar
kartouss kartouss is offline Offline
Junior Poster in Training

Re: Calling c++ dll in vb

 
0
  #10
Mar 30th, 2008
Thanks Ancient dragon that really works...
Thanks again...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC