[fpc-pascal] Problem with FPC2.0.2 and windows
jonas.maebe at elis.ugent.be
Mon Jan 2 01:46:25 CET 2006
On 28 Dec 2005, at 23:49, Hans Mårtensson wrote:
> The problem was the following program line, using the windows unit:
> if DialogBoxIndirect(0, pBox2, Window, @Box2Proc) = 0 then exit;
> The compiler assessed an error in parameter 4. Should not be an
> address, but a variable.
Is your Box2Proc procedure declared as stdcall? In FPC 1.x, the
default calling convention was compatible with stdcall, but in 2.x
this is no longer the case.
> So I tried:
> if DialogBoxIndirect(0, pBox2, Window, Box2Proc) = 0 then exit;
> And the compiler assessed that the number of parameters was wrong.
> But this is an error in message, because the number of parameters
> is right.
It was probably complaining that too few parameters were specified to
Box2Proc, not to DialogBoxIndirect. I guess from this that you are
working in either fpc or objfpc mode.
> Then I tried to define a procedural type TBoxproc and then declared
> a variable:
> var BoxProc: TBoxproc;
How is TBoxProc defined?
> and changed my program to:
> if DialogBoxIndirect(0, pBox2, Window, BoxProc)=0 then exit;
> Now FPC compiled my program to the end.
This is the declaration of DialogBoxIndirect:
This is the declaration of DLGPROC:
DLGPROC = function (_para1:HWND; _para2:UINT; _para3:WPARAM;
As long as the definition of Box2Proc is compatible with this, there
should be no problem.
> BUT following problems remains:
> 1) I don’t understand why it should be necessary to use a variable
> that is assigned to @Box2Proc, in stead of using @Box2Proc directly
> as the parameter.
It shouldn't be. Please always supply a fully compilable (or non-
compilable in this case, but in any case *complete*) sample if you
want us to investigate.
> 2) Even though the compiler produces an exe file, this does not
> work. The call of DialogBoxIndirect does not produce any dialogue
> box, but returns having done nothing. Now it is a bit tricky to
> make this dialogue box business work, because pBox2 must point to a
> data structure, and if there are errors in this data structure,
> windows do not produce any error message. But in this case, my data
> structure worked with the old version of FPC. I have tried to
> compile exactly the same source files with compiler 1.0.10 and with
> 2.0.2. The first program worked all right, but the second did not
> show any dialogue box, when the procedure in question was invoked.
> So I suspect that the compiler or the windows unit that comes with
> the 2.0.2 version has some error.
> Does anybody know about these problems?
The most likely reason is that your callback is not declared as
stdcall. But then the compiler should complain that the calling
conventions don't match, and not say that it "Should not be an
address, but a variable" (btw, what is the exact error message you
get since this error does not exist). And you should not be able to
circumvent calling convention requirements by using a procvar, as
procvars also have a calling convention associated with them (so that
would be a bug in the compiler if you can do that nevertheless).
More information about the fpc-pascal