0

This is the C++ header for this function. I imported everything already except for that calllback I don't know how to do it.

struct abs_operation;

typedef struct abs_operation ABS_OPERATION;  /* forward declaration */

typedef void (BSAPI  *ABS_CALLBACK) ( const ABS_OPERATION*, ABS_DWORD, void*);

struct abs_operation {
        ABS_CALLBACK Callback;  ///< Pointer to application-defined function, implementing operation callback.
} ;

1 Answer 1

1

Based on knowledge of your previous questions, it's like this, I think:

type
  PABSOperation = ^TABSOperation;
  TABSCallback = procedure(const Operation: PABSOperation;
     Flags: DWORD; Ptr: Pointer); stdcall;
  TABSOperation = record
     Callback: TABSCallback;
  end;
Sign up to request clarification or add additional context in comments.

5 Comments

It is not right to use const in the delphi declaration. In C++ const means not modificable; in delphi means passed by ref and not modificable: instead use (operation : PBASOperation, ...) or (const Operation : TABSOperaion ...)
@Stefano Actually the const was added in an edit by Remy. But it is fine here and it actually doesn't matter whether or not you include the const. You say that const in Delphi means "passed by ref". That statement is false. Use of const will induce pass by ref if the parameter is bigger than the size of a pointer. In fact this is the source of some very subtle bugs when porting to 64 bit. Consider a record of size 8, TRecord say. Pass it const R: TRecord in 32 bit and it is passed by ref. Pass it that way in 64 bit and it is passed by value.
Thanks, I did not known that subtle difference. I tested your case (using CPU view) in my D7 using a record size <= 4 byte and using a record >8. in the first case the argument are passed in AX(al, ax or eax depending on the size of the input). in the second case the input address in passed into EDX. However my opinion is the same: do not use const parameters when translating C function declaration. you depends on the compiler implementation and on CPU architecture. if "struct abs_operation" have had another field then it would be passed by value in 32 bit and by ref in 64 bit delphi!
@StefanoMoratto As you can tell, I basically agree with you. The const was added as an edit by Remy. I don't strongly mind one way or another. In C and C++, const ABS_OPERATION* is a little pointless since that particular const is only really meaningful at the point of implementation. So for a function pointer typedef, it makes no real sense to add it.
You don't call anything in this question. You supply a callback that fits the interface defined by TABSCallback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.