MSVC++ lib strange behavior

Everything else that doesn't fall into one of the other PB categories.
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

MSVC++ lib strange behavior

Post by r_hyde »

I'm using a lib compiled with MSVC++6 using Import..EndImport. I have tested all the functions in the lib, and they all work fine as long as they are not used within procedures. Once I put a call to a lib function inside a procedure I get some pretty odd behavior. Example:

(I'm sorry that I cannot provide a more useful code example because I'm not at liberty to distribute the .lib in question or to reveal my full source.)

Code: Select all

Import "mylib.lib"
  MyFunction1(param$)
EndImport

Procedure test1(path$)
  dir = ExamineDirectory(#PB_Any, path$, "")
  If IsDirectory(dir)
    While NextDirectoryEntry(dir)
      MyFunction1(DirectoryEntryName(dir))
    Wend
    FinishDirectory(dir)
  EndIf
EndProcedure

mypath$ = "D:\test"
test1(mypath$)
This extremely minimal example (generalized and simplified from my actual code) fails on NextDirectoryEntry(dir), saying that the directory is not initialized even though the call to IsDirectory(dir) passes. If I comment out the call to the lib function it works perfectly. I find this very strange. In other cases I have run into invalid memory access errors calling the lib functions ONLY when they are called within procedures. Is this a known problem or bug? Am I doing something wrong? I'm pulling my hair out over this!
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

I suspect the lib uses cdecl calling convention, try using ImportC instead.
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

Post by r_hyde »

Spot on, jack! Working beautifully now.
Post Reply