Sviluppo e Sviluppi
lunedì, febbraio 14, 2005
 
Language Similarity
I need to use a DLL function in a .NET project (C# is the language)

I declare a Class with a static method as suggest in the help. I used this syntax:
public class ttE
{
[DllImport("PCSHLL32.dll")]
public static extern UInt32 hllapi(
out UInt32 Func,
StringBuilder Data,
out UInt32 Length,
out UInt32 RetC);
}

In the past I used the same function in a Delphi program.
The import statement is the following
function hllapi(var Func:DWord ;DataString:PChar;var Length:DWord;

var RetC:DWord):DWord stdcall; external 'PCSHLL32.DLL' ;

In Delphi is not necessary to include this function declaration inside a class.
For syntax:
- DWord --> UInt32 (.NET type)
- PChar --> StringBuilder (It's a buffer)
- Delphi var parameters is translated as out in C#.
- stdcall is the default call convention for dll functions in C# so is not important to include in the attribute DllImport

So It's really simple to convert a code from Delphi to C#!
Comments: Posta un commento

<< Home

Powered by Blogger