简体   繁体   English

如何声明一个指针(字节^)?

[英]How to declare a pointer(byte^)?

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. 这是我的Delphi声明,无法编译。

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

This is my C# declaration,which works. 这是我的C#声明,可以正常工作。

[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"? 我的问题:由于^,编译器会在byte ^之后显示“(”。如果我键入mybyte = byte ^;那么我该如何用byte数组中的第一个成员调用该函数-因为它无法编译,因为数组不是类型“ myByte”?

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. 同样,dll可能需要字节数组而不是字节指针。 So you might want to adjust for that too. 因此,您可能也要对此进行调整。 (In C, arrays and pointers are declared the same way.) (在C语言中,数组和指针的声明方式相同。)

Jqno got it right. Jqno正确。 Plus you can always use PByte instead of ^byte. 另外,您始终可以使用PByte而不是^ byte。

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 一切取决于您的Delphi程序如何调用该函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM