?
Solved

Call C++ DLL from VB6 using user-defined data type

Posted on 2000-03-08
5
Medium Priority
?
363 Views
Last Modified: 2010-04-02
From VB, I'm calling a DLL created with C++.  When I pass in a string ByVal, the DLL funstions fine.  When I pass, ByRef, a user-defined data type including strings and longs, the DLL fails.

I've setup an identical structure in Vb to match what is defined in the DLL (including the use of fixed length strings).

I believe using fixed length VB strings will give me a null terminated string in the C-based DLL.

The problem is complicated because I cant find a way to get into debug mode to test the DLL by stepping into it from the VB call.  As a result, I first created and debugged the code with a C-based EXE, then, moved the functions into the DLL.
0
Comment
Question by:GregoryGr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
dlmartz earned 800 total points
ID: 2597701
You need to use BSTR's for your strings in the structures used to pass between VB and C/C++

The knowledge base article Q194609 defines this specifically.

As for debugging, you can debug your DLL in the C++ environment. Assuming your using VisualC++ (if not, others are simular)... go to the settings on your project and assign your VB application as the executable to debug. You may need to add your DLL to the pre-loaded DLL listing (same screen, different tab). They press F5 to begin debugging. It will warn you the process does not contain debug information, set your break points and continue anyway. Your be debugging your DLL.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2599374
listen...
0
 

Author Comment

by:GregoryGr
ID: 2600767
The UDT contains fixed length strings and integers into the DLL, not variable length strings.  With the debugging info you gave me, I found the issue to be VB doesn't NULL terminate strings by default.  I ran into problems trying the BSTR data type so I was planning just to NULL terminate the incoming VB strings.  

Do you think that is a bad idea and I must use BSTR data types?
0
 

Author Comment

by:GregoryGr
ID: 2601960
Using the fixed length strings instead of BSTR within the UDT seems to work for me once I NULL terminated the strings.

Your instructions to test the DLL from C++ helped a great deal!

Thanks!
0
 
LVL 1

Expert Comment

by:dlmartz
ID: 2606616
Glad I could help
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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

764 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