Solved

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

Posted on 2000-03-08
5
354 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

724 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