dougdeming
asked on
ASCIIZ and VB String and DLL = GPF
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
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!
ASKER
See my comment.
ie try
MyMessage = Chr$(65) & Chr$(66) & Chr$(67) & Chr$(68) & Chr$(69) & Chr$(0)