Problems translating code to PB4.0

Just starting out? Need help? Post your questions and find answers here.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Problems translating code to PB4.0

Post by utopiomania »

I'm trying to translate a program from 3.94 to 4.00, but can't get the code below to work. As soon as it get's to
SendMessage_(), it chrashes totally.

I got the stream load/save from code on the forums, and can't see what is wrong with it under PB 4.0

Code: Select all

;Utility procedures
Procedure ReLoadSaveCallback(dwCookie, *pbBuff, Cb, *Pcb.LONG) 
  ;Callback used by ReSave/ReLoad
  If dwCookie = 1
    ;Save    
    WriteData(FileH, *pbBuff, Cb) 
    *Pcb\l = Cb 
  Else
    ;Load 
    Length = Lof(FileH) - Loc(FileH)
    If Length > Cb 
      ReadData(FileH, *pbBuff, Cb) 
      *Pcb\l = Cb 
    Else 
      ReadData(FileH, *pbBuff, Length) 
      *Pcb\l = Length 
    EndIf
  EndIf 
  ProcedureReturn 0 
EndProcedure 

Procedure ReLoad(Id, FileName.s, Rtf) 
  ;RichEdit Load file
  FileH = ReadFile(#PB_Any, FileName)
  If FileH
    Stream.EDITSTREAM 
    Stream\dwCookie    = 0 
    Stream\pfnCallback = @ReLoadSaveCallback() 
    If Rtf
      SendMessage_(GadgetID(Id), #EM_STREAMIN, #SF_RTF, @Stream)
    Else
      SendMessage_(GadgetID(Id), #EM_STREAMIN, #SF_TEXT, @Stream)
    EndIf
    CloseFile(FileH)
    ResetModified(Id)
  EndIf 
EndProcedure

Procedure ReSave(Id, FileName.s, Rtf) 
  ;RichEdit Save file
  FileH = CreateFile(#PB_Any, FileName.s) 
  If FileH
    Stream.EDITSTREAM 
    Stream\dwCookie    = 1 
    Stream\pfnCallback = @ReLoadSaveCallback() 
    If Rtf
      SendMessage_(GadgetID(Id), #EM_STREAMOUT, #SF_RTF, @Stream) 
    Else
      SendMessage_(GadgetID(Id), #EM_STREAMOUT, #SF_TEXT, @Stream) 
    EndIf
    ResetModified(Id)
    CloseFile(FileH) 
  EndIf 
EndProcedure