ASCIIZ and VB String and DLL = GPF

Posted on 2002-03-23
Last Modified: 2010-05-18
Please help, this is driving me crazy.

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


ASCIIZ is a null terminated string.

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.

Question by:dougdeming
  • 2
LVL 16

Accepted Solution

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


Expert Comment

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)

Author Comment

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!

Author Comment

ID: 6891449
See my comment.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 46
Getting warning: You are about to delete 1 row(s) 9 43
VB6 - Convert HH:MM into Decimal 8 51
Excel Automation VBA 19 25
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now