Weird memory issue with dll. (code included!)
Posted: Thu Sep 29, 2011 7:39 pm
I have a small function in a dll that returns a string.
When compiled to a dll; the return result is invalid, when run "all together" (no dll) it works perfectly.
DLL : (Save as "test-dll.pb" and Compile to "test.dll")
Test code:
This will give you weird results:

But looking at the debug output, it all looks right:

However, this works fine:
When compiled to a dll; the return result is invalid, when run "all together" (no dll) it works perfectly.
DLL : (Save as "test-dll.pb" and Compile to "test.dll")
Code: Select all
Global gcSharedReturn.s
ProcedureDLL.s JustSQLPath( cPath.s )
Protected.s cNewPath
OutputDebugString_("JustSQL Path: "+cpath)
If Left(cPath,1)=#DQUOTE$
OutputDebugString_("Path starts with quote")
cNewPath = StringField(cPath,2,#DQUOTE$)
ElseIf FindString(cPath,Space(1)+"-sMSSQL",1)>0
OutputDebugString_("space + param")
cNewPath = StringField(cPath,2,Space(1))
Else
OutputDebugString_("Other...")
cNewPath = cPath
EndIf
gcSharedReturn = cNewPath
OutputDebugString_("Just path: "+gcSharedReturn)
ProcedureReturn gcSharedReturn
EndProcedure
Code: Select all
If OpenLibrary(0,"test.dll")
Prototype.s pJustSQLPath(cPath.s)
JustSQLPath.pJustSQLPath = GetFunction(0,"JustSQLPath")
If JustSQLPath
cImagePath.s = #DQUOTE$+"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn\sqlservr.exe"+#DQUOTE$+" -sMSSQLSERVER"
Debug JustSQLPath(cImagePath)
Else
Debug "No Function"
EndIf
Else
Debug "no lib"
EndIf

But looking at the debug output, it all looks right:

However, this works fine:
Code: Select all
XIncludeFile "test-dll.pb"
cImagePath.s = #DQUOTE$+"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn\sqlservr.exe"+#DQUOTE$+" -sMSSQLSERVER"
Debug JustSQLPath(cImagePath)
[/code
[img]http://jassing.com/temp/snap340.png[/img]
Any ideas?