Jonas Maebe wrote:


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.


It is declared as stdcall ... and it was so when using ver. 1.0.10.

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.


I had that option in my mind too, but the number of parameters in Box2Proc is also correct. I use the fpc compiler on a source code written in the CrEdit program. I have not changed the configuration file that comes with the FreePascal download (except for file location of units).
The only compiler directive I have used in the program is the {$APPTYPE GUI}

Then I tried to define a procedural type TBoxproc and then declared a variable:
var BoxProc: TBoxproc;


How is TBoxProc defined?

Here is the definition that I used:
Type TBoxProc = Function(x: longword; y: longword; a: longint; b: longint): longint; stdcall;

and changed my program to:
BoxProc:[EMAIL PROTECTED];
if DialogBoxIndirect(0, pBox2, Window, BoxProc)=0 then exit;

Now FPC compiled my program to the end.


This is the declaration of DialogBoxIndirect:

function DialogBoxIndirect(hInstance:HINST; hDialogTemplate:LPCDLGTEMPLATE; hWndParent:HWND; lpDialogFunc:DLGPROC):longint;

This is the declaration of DLGPROC:

DLGPROC = function (_para1:HWND; _para2:UINT; _para3:WPARAM; _para4:LPARAM):LRESULT;stdcall;

As long as the definition of Box2Proc is compatible with this, there should be no problem.


I cannot see any problem here.
But where are these definitions, I cannot find them in the FPC download, should they be downloaded separately?
Are they exactly the same as the definitions in the Microsoft documentation?


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.


Yes of course. I only hoped that someone could point out some simple mistake I had made, or, inform me that there were some known problem with the compiler. The problem is that my program is large with many units that depends on each other, so it was not easy to pick out the part that invoked the error. Also it seemed very strange to me that the source code after some changes could be compiled with both FPC 1.0.10 AND FPC 2.0.2 and both exe files worked, except for that the FPC 2.0.2 version did not show the dialog boxes. Now, I will try to construct a simple program that can reproduce the problems.

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

I tried to omit the stdcall, which made the compiler produce an error message (something like: wrong format of procedure)


Thank you for your careful answer. I will return later if I am able to make a simple sample program that can reproduce the problem.
(Or may be I should stick to 1.0.10 that worked for me)

Hans Mårtensson

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to