tags:

views:

203

answers:

3

Hello,

I want to make a declaration of an external function,but I can't do it.

this is my Delphi declaration,which doesn't compile.

procedure Encode(input:byte^;output:byte^;size:DWORD);cdecl;external 'blowfish.dll';

This is my C# declaration,which works.

[DllImport("blowfish.dll")]
public static unsafe extern void Encode(byte* input, byte* output, UInt32 size);

My problem:the compiler exprects "(" after byte^ ,because of the ^.If I make a type mybyte= byte^; then how do I call the function with the first member in the byte array - it then cannot compile,because the array isnt type "myByte"?

+4  A: 

Shouldn't the ^'s be before the type names?

procedure Encode(input:^byte;output:^byte;size:DWORD);cdecl;external 'blowfish.dll';

Also, probably the dll wants arrays of bytes instead of pointers to bytes. So you might want to adjust for that too. (In C, arrays and pointers are declared the same way.)

jqno
+2  A: 

Jqno got it right. Plus you can always use PByte instead of ^byte.

gabr
@gabr: shouldn't this be a comment?
Argalatyr
PByte is declared in System, so there should be no need to "use" Windows.
Allen Bauer
Ooops, Allen is correct. (In my defense - I Ctrl-Clicked on PByte and Delphi opened Windows unit. Hence my mistake.)
gabr
+1  A: 
procedure Encode(CONST input ; VAR output ; size : DWORD); cdecl; external 'blowfish.dll';

or

procedure Encode(input : PByte ; output : PByte ; size : DWORD); cdecl; external 'blowfish.dll';

or

procedure Encode(CONST input ; OUT output ; size : DWORD); cdecl; external 'blowfish.dll';

or

procedure Encode(input : POINTER ; output : POINTER ; size : DWORD); cdecl; external 'blowfish.dll';

all depending on how your Delphi program calls the function

HeartWare