Solved

ASCIIZ and VB String and DLL = GPF

Posted on 2002-03-23
4
279 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 100 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

820 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