GlobalAlloc -- WinXP, Lazarus 1.0.2 lazarus / 34-Windows ---------------------------------------------------------------------- Curt Carpenter · 2013-02-24 16:21 Hello. I'm trying to convert an old Delphi3 program to Lazarus.  I am getting errors where the Delphi program uses the windows GlobalAlloc function.   I've searched the forum for this issue, but have not found any information.  Can anyone tell me if/where I can find the GlobalAlloc function in the Lazarus 1.0.2 resources?  Input much appreciated.  The program I'm trying to convert is an audio sweep generator -- and the Delphi-generated .exe runs fine. Thanks Curt Carpenter ---------------------------------------------------------------------- Leledumbo · 2013-02-24 17:08 GlobalAlloc is WinAPI function, it should work with FPC. What errors do you get? What FPC version? ---------------------------------------------------------------------- taazz · 2013-02-24 17:44 Code: [Select]function GlobalAlloc(uFlags: UInt32; dwBytes: DWORD): Pointer; stdcall; external 'kernel32.dll' name 'GlobalAlloc'; function GlobalFree(hMem: Pointer): Pointer; stdcall; external 'kernel32.dll' name 'GlobalFree'; Add the above declaration to the unit using those and you should be able to use them on windows. those are probably used to copy data in to the clipboard in some custom format you should try to replace the complete with the lazarus clipoard streaming capabilities although I haven't tested them yet my self so I can't actually recommend them over the existing code. ---------------------------------------------------------------------- User137 · 2013-02-25 00:14 All you need to do is add Windows in uses list, it finds GlobalAlloc() and GlobalFree(). Using FPC 2.7.1. ---------------------------------------------------------------------- Curt Carpenter · 2013-02-25 02:53 Thank you for the help. I'm using fpc2.6.0 with Lazarus 1.0.2. If I include "Windows" in my uses clause, the program compiles correctly but gives me the following error when I try to run it: Debugger Exception Notification Project SweepGen raised exception class 'Exception' with message: Failed to creat win32 control, error:1407: Cannot find window class. At address 53FC37 If I don't include "Windows" in my uses clause, the program won't compile, with two source lines like the following:     hBuffer1 := GlobalAlloc (gHnd or gMem_Share, buffer_bytes * 2);     p_buffer1 := pBuffer (GlobalLock (hBuffer1)); generating the following error messages: MainForm.pas(211,27) Error: Identifier not found "GlobalAlloc" MainForm.pas(211,33) Error: Identifier not found "gHnd" MainForm.pas(211,46) Error: Identifier not found "gMem_Share" MainForm.pas(212,36) Error: Identifier not found "GlobalLock" I haven't tried turning off the debugger.  I wonder if that would work? Thanks again for the help. ---------------------------------------------------------------------- Leledumbo · 2013-02-25 13:19 You MUST have Windows in uses clause nevertheless, the "Failed to creat win32 control, error:1407: Cannot find window class" is something else that must be fixed. How's your .lpr looks like? ---------------------------------------------------------------------- Curt Carpenter · 2013-02-25 15:05 The .lpr appears as follows: program SweepGen; {$MODE Delphi} uses   Forms, Interfaces,   MainForm in 'MainForm.pas' {Form1}; begin   Application.Title := 'David''s Audio Sweep Generator';   Application.CreateForm(TForm1, Form1);   Application.Run; end. ---------------------------------------------------------------------- Leledumbo · 2013-02-25 15:09 Does it work if you swap Interfaces and Forms? ---------------------------------------------------------------------- Curt Carpenter · 2013-02-25 18:21 Many thanks for your help on this. I swapped Interfaces and Forms as you suggested, but no luck.  The program compiles OK but if I try to run it I get Debugger Exception Notification Project SweepGen raised exception class 'Exception' with message: Failed to creat win32 control, error:1407: Cannot find window class. At address 53FC37 and if I click "continue" a few times I get the following from heaptrc: Heap dump by heaptrc unit 2187 memory blocks allocated: 230167/236344 2183 memory blocks freed: 229987/236160 4 unfreed memory blocks: 180 True heap size: 262144 (96 used in System startup) True free head: 261552 Should be: 261608 call trace for block... I tried running the .exe without the IDE, but got the same error as above with a slight difference in memory blocks allocated/freed. ---------------------------------------------------------------------- User137 · 2013-02-25 22:30 For now we can only guess what is happening. Any chance to see code of what is going on when the program starts? Any events like initialization, onFormCreate, onFormShow or such? ---------------------------------------------------------------------- Curt Carpenter · 2013-02-26 02:03 Here is an update/conclusion on my problem. My Delphi program was converted to Lazarus using the Delphi-to-Lazarus conversion tool.   This appeared to work seamlessly, and on examination each of the generated files looked correct -- but I apparently missed something somewhere.  This afternoon, I rebuilt the program and it's one form manually from scratch, one component at a time -- and with that, I'm able to run the program without any Debugger Exception Notifications or reported heap problems.  The program still won't work -- but my issue now seems to be that none of the Windows call-back functions I'm using via the are mmSystem unit are working   But this is a totally different problem, and I'll have to investigate it further to see if I can figure out what's going on.  Meanwhile, thanks so much to all of you that gave me some help and ideas here.  It has been much appreciated. ---------------------------------------------------------------------- Curt Carpenter · 2013-02-26 20:43 Windows messages problem resolved, program working. Thanks again to all.