All source code in Visual Basic Ask a Visual Basic Pro Discussion Forum Categories All jobs in Visual Basic
CPP,DLL,NOTES,LPSTR,Well,been,studying,combin
   Code/Articles � |  Newest/Best � |  Community � |  Jobs � |  Other � |  Goto � | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 5,135,513. lines
 Jobs: 279. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for Visual Basic.
Click here to see a screenshot of this code!Crypto
By Krishna Ram Prakash on 3/13

(Screen Shot)

LOCK YOUR TEXTBOX
By MUHAMMAD SAIF UL RAHMAN HASHMI on 3/13


Click here to see a screenshot of this code!SMSlogger
By Emilio Ficara on 3/8

(Screen Shot)

Click here to see a screenshot of this code!Real Photomosaic v12 (cieLAB)
By reexre on 3/12

(Screen Shot)

Click here to see a screenshot of this code!Kimmo - MyHelp
By Anele Mbanga on 9/24

(Screen Shot)

Click here to see a screenshot of this code!Kimmo - CoolCode Update
By Anele Mbanga on 2/9

(Screen Shot)

Click here to see a screenshot of this code!NIC VALIDATION
By Kasun Nayanajith Jayamuni on 3/12

(Screen Shot)

Click here to put this ticker on your site!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Loading C++ DLL In Visual Basic

Print
Email
 
winzip icon
Submitted on: 11/17/2009 9:01:56 AM
By: Andron Smith  
Level: Beginner
User Rating: Unrated
Compatibility:VB 6.0

Users have accessed this code 2598 times.
 
author picture
(About the author)
 
     Well i have been studying combining C++ with Visual Basic. See C++ offers power while Visual Basic offers Rapid Development. The Limitations Visual Basic may have can be over taken with a bit of help from C++. With that said, I introduce to you my attempt at CPP with Visual BAsic programming. After some research and studying of using the DLL with vb, i've put it to code base on my understanding. Now The first two functions will work. but you must compile the program, leave the DLLs in the Debug folder CPP would provide. The Program fails on MultiplyAll on my System, maybe it might do better on yours but being a programmer, real programmers never let anything beat us so i will try to figure out why multiplyall is recieving error and i will reupload the corrected.. Thanks. Experiment with the code, use my comments section for any discussion you wish to have on CPP DLL and VB. TECH NOTES UPDATE: Tech notes and Findings: Well since the post. I have done some more practices on it. As a result i've found, that visual C++ does actually passes the arguments, this is tested when i called a MessageBox from out of the C++ DLL. Notice, that prior to the Bad Dll Calling Prevention you would get an email listing the data you sent. This is because the DLL is recieving the data, it is compatible with the data being sent to it. i used how ever LPSTR for the data type giving and passed. Now the problem comes when it returns a value back to the DLL. For some reason visual basic, is reading our Function as a Sub Routine so it's like it's expecting us to be calling a sub routine. This is tested when i created a TellUser function in C++. I noticed the function was void. returned no value but instead of calling it as a sub routine i called it as a function and as a result i recieve similiar error however when i called it as a sub routine it recieved no error. So i will study and dive deeper into this. Also i have also found that Dev C++ allows full DLL calling. in that i used the following extern "C" __declspec(dllexport) __stdcall LPSTR MessageMe(LPSTR message); from the function i made it send a message box containing the message. Through my studies on it, i've realize DevC++ does not like the .def declaration. but how ever it listed the function and called with out an error visual basic. my attempt to use the similiar line in visual c++ failed prompting me to believe that C++ does not like DevC++ calling methods where as DevC++ does not like C++ calling methods. Norm Cook, i try and experiment with your suggestion, believe me you will read the results here in the future posting.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.

Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:
1)Re-scan downloaded files using your personal virus checker before using it.
2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
3)Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 38 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
11/13/2009 4:32:02 AMLefteris Eleftheriades

Thank you, I never knew about the .def files, I always exported with __declspec(dllexport) and I got wierd exportnames for my functions
(If this comment was disrespectful, please report it.)

 
11/13/2009 1:08:19 PMBob Hutchison

MultiplyAll fails on my system as well (XP-SP2). Being a real noob at C++, I'll let the experts figure it out <G>
(If this comment was disrespectful, please report it.)

 
11/14/2009 11:46:12 AMAndron Smith

Well, let's look at it real quickly. In the other functions declared in visual basic, neither of them asked for parameters to be passed. Where as multiplyAll is asking for a parameter. So here the error is exporting a function that requires a parameter to be passed. i also have a passion for software engineering so i like to study my coding. on one hand maybe the parameters i'm attempting to pass in C++ to visual basic is not compatible with visual basic. I mean maybe they have a certain datatype that replaces the INT. But then again, visual basic accepts a return in the same type. Confusing? I know. it's just trying to study it and learn a bit more about Importing C++ functions into Visual Basic that requires Parameters.
(If this comment was disrespectful, please report it.)

 
11/14/2009 1:34:42 PMNorm Cook

VB6 expects C++ dll routines to use
__stdcall vice __declspec. Note that the routine that fails has two arguments, so __declspec reverses them in your call.
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright� 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.