Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASCIIZ and VB String and DLL = GPF

Posted on 2002-03-23
4
Medium Priority
?
286 Views
Last Modified: 2010-05-18
Please help, this is driving me crazy.

I have written a DLL (in PowerBasic) which has the following declaration:

FUNCTION TEST_DLL( BYREF Message AS ASCIIZ ) EXPORT AS STRING

ASCIIZ is a null terminated string.

PROBLEM:
1. The following does NOT work and causes a GPF in MS VB 6.0 within about 20 calls:

Dim MyMessage as String
MyMessage =""
MyMessage = Chr$(65) & Chr$(66) & Chr$(67) & Chr$(68) & Chr$(69)
MyStr = TEST_DLL(MyMessage)

2. HOWEVER the following always works fine in MS VB 6.0:

Dim MyMessage as String
MyMessage = "ABCDE"
MyStr = TEST_DLL(MyMessage)

I need to build the string like in #1 above but it crashes. I look forward to your solution.


0
Comment
Question by:dougdeming
[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
4 Comments
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 300 total points
ID: 6891067
maybe:
Dim MyMessage as String
MyMessage =""
MyMessage = Chr$(65) & Chr$(66) & Chr$(67) & Chr$(68) & Chr$(69) & chr$(0)
MyStr = TEST_DLL(MyMessage)

0
 
LVL 4

Expert Comment

by:pellep
ID: 6891435
Have you tried null-terminating your string. VB strings are BSTR (OLE) strings and not null terminated.

ie try
MyMessage = Chr$(65) & Chr$(66) & Chr$(67) & Chr$(68) & Chr$(69) & Chr$(0)
0
 

Author Comment

by:dougdeming
ID: 6891448
Okay here's what I found out. Adding the CHR$(0) did NOT fix the problem. After pouring thru lots of documentation and code, I discovered the problem was in my DLL.

The DLL defined the parameter as BYREF which is correct and VB defined it as BYVAL which is also correct.

However, I inadvertantly was changing the value of the parameter inside the DLL which messed up data in VB because I was increasing the length of the string inside the DLL, hence causing a GPF in VB.

Whew!  Thank you for everyone's help and insight. I am awarding the points to the first person who suggested the CHR$(0) because I appreciate his super fast response.

Thank you!
0
 

Author Comment

by:dougdeming
ID: 6891449
See my comment.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 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