Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASCIIZ and VB String and DLL = GPF

Posted on 2002-03-23
4
Medium Priority
?
288 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
  • 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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

876 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