Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding modules from other languages 1

Status
Not open for further replies.

shawnnason

Programmer
Jun 12, 2001
26
US
I have some source code in C that is about 60000 lines long. Is there a way to incorporate this code into a Visual Basic application? Is there an easy way to convert it to VB? Can I compile it and use the binaries?
 
Compile you C code into a DLL with the appropriate DEF file and then call the code from VB as APIs. Or you could compile the C code as an ATL DLL and use it via a COM interface. - Jeff Marler B-)
 
Do like Jeff says.

The trick is using the .DEF file, not __declspec(dllexport).

Chip H.
 
So, in order to make the dll, do I make a new project with the MFC AppWizard, or is there another way to do this? I have VC++. I started it up, clicked new, then I tried to use the AppWizard to make a dll. I chose the static link option, with comment generation. A bunch of things were created (.cpp, .def, .rc, .h) and when I tried to add my source code, it didn't appear to compile my source code. I know basically nothing about VC++, so if I am missing something that is painfully obvious, please point it out.
 
How did you add the source code and what makes you think that is did not compile? Also, do you know how to add a Def file to a C++ project? - Jeff Marler B-)
 
Once I created the new project, I clicked on Project->Add to Project-> Files. Then, I added the .c / .h files I have. When I first started fooling with this, I made a project but don't remember what kind of app I told it to make. When I compile that I get an unresolved external _WinMain@16 error. When I compile the new project (that I hope will make a DLL), I get a fatal error - unexpected end of file while looking for precompiled header error. That is what makes me think that my source code isn't getting compiled.

I do not know how to add a Def file to a C++ project.

Beleive me, I'd love to have a book on VC++ that I could use to help me through this and to learn VC++, but there's no money for that right now. But when there is, what are some good books to get?
 
I don't remember the exact name . . .I'll post it tonight along with the author and ISBN, but look for this Book . . . "C++ Programming For Visual Basic Programmers". Its a great intro book for VB programmers who want to start looking at C++ and how to call C++ code from VB. - Jeff Marler B-)
 
Sorry about the delay Shawn, but when I went to post the information, Tek-Tips was down . . . I guess they had an accident near their host site that killed power for a couple days. Anyway, here is the book info


C++ for VB Programmers
Author Jonathan Morrison (Foreword by Dan Appleman)
ISBN : 1-893115-76-3
Publisher : Apress



This is an excellent book if you are a VB programmer who is interested in using C++ code (via APIs or ATL) in your VB applications. He describes (in great detail) exactly what you are trying to do and he provides several samples that that he will walk you through.
- Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top