Solved

ASCIIZ and VB String and DLL = GPF

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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