how to load an unmanaged DLL

D

dev

Good Morning,
First, I must say that I'm completly newbie about C# and .NET, nevertlessy
my company put me on work on a C# projects...

So I'm here to ask for help:

I have an unmanaged DLL that export a function.

The function is (as declare in VB software that import it):
Private Declare Function SCardComand Lib "SCARD32"
(Handle As Long,
ByVal cmd As String,
CmdLen As Long,
ByVal DataIn As String,
DataInLen As Long,
ByVal DataOut As String,
DataOutLen As Long) As Long

As you can see we have a mix of input and output parameters. How can I:
1) Import/Declare this function in C#?
2) Pass the equivalent of a C++ NULL pointer to the function
3) Pass the equivalent of a long* to the function

Thanks for whater help you can provide me.

Dev
 
M

Mattias Sjögren

1) Import/Declare this function in C#?

Probably something like this

[DllImport("scard32.dll")]
static extern int SCardComand(ref IntPtr Handle, string cmd, ref int
mdLen As Long, string DataIn, ref int DataInLen, StringBuilder
DataOut, ref int DataOutLen);

2) Pass the equivalent of a C++ NULL pointer to the function

It depends on the parameter type, but usually with the null keyword or
IntPtr.Zero.

3) Pass the equivalent of a long* to the function

ref int (or out int if it's an out-only argument).



Mattias
 
D

dev

Thank you very much Matthias,
I didn't know about the out param or StringBuilder, now I go try...

Bye

Dev


Mattias Sjögren said:
1) Import/Declare this function in C#?

Probably something like this

[DllImport("scard32.dll")]
static extern int SCardComand(ref IntPtr Handle, string cmd, ref int
mdLen As Long, string DataIn, ref int DataInLen, StringBuilder
DataOut, ref int DataOutLen);

2) Pass the equivalent of a C++ NULL pointer to the function

It depends on the parameter type, but usually with the null keyword or
IntPtr.Zero.

3) Pass the equivalent of a long* to the function

ref int (or out int if it's an out-only argument).



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top