Weird memory issue with dll. (code included!)

Windows specific forum
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Weird memory issue with dll. (code included!)

Post by jassing »

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")

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
Test code:

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
This will give you weird results:
Image
But looking at the debug output, it all looks right:
Image

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?
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Weird memory issue with dll. (code included!)

Post by luis »

Change the proto and add PeekS()

Code: Select all

If OpenLibrary(0,"test.dll")
   Prototype.i 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 PeekS(JustSQLPath(cImagePath))
   Else
      Debug "No Function"
   EndIf
Else
   Debug "no lib"
EndIf
"Have you tried turning it off and on again ?"
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Weird memory issue with dll. (code included!)

Post by jassing »

Thanks; despite reading the help file; I didn't read that one last line that references peeks()
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Weird memory issue with dll. (code included!)

Post by luis »

No problem, I hit the same wall time ago.

Personally I still find a little strange the fact you have to resort to this.
I would believe the compiler, seeing the prototype with .s, is able to understand my request and do the peeks() under the hood for me, but anyway this the way it works.

Maybe there is a reason preventing this. I don't know.
"Have you tried turning it off and on again ?"
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Weird memory issue with dll. (code included!)

Post by jassing »

luis wrote:No problem, I hit the same wall time ago.[/qoute]

Well; I'm glad I'm not alone -- although, these new "reading glasses" sure didn't help here. ;-) I'm rather embarrassed by that.
luis wrote:..I would believe the compiler, seeing the prototype with .s, is able to understand my request and do the peeks() under the hood for me
Agreed there.. in fact, that's what I was expecting to see...
Especially since you can use those ProcedureDLL.s Funcs() inside the dll w/o peeks() -- I expected to be able to do so outside with the proper deceleration.

again; thanks.
Post Reply