accessing a function in a dll file

G

GEES

Friends,

I would like to access a function in a dll file.

I have the call from a vb programme, it looks like
Declare Function bapiVersionInfo Lib "bapi" (ByVal versionString As String,
ByVal maxSize As long) As long
I c# I would do it as followes:

[DllImport("BAPI.DLL", EntryPoint = "bapiVersionInfo", CharSet =
CharSet.Ansi)]

public static extern int bapiVersionInfo([MarshalAs(UnmanagedType.LPStr)]
string versionString, int maxSize);

The problem is that the dll is a on bibary based C++ file. Fromout C# the
long is transferred to a int. But hou to handle the string????

Regards

Gerrit Esmeijer
 
G

Guest

C#/PInvoke knows about C style char* NULL terminated strings so you
shouldn't have to do anything special if the string is a null terminated IN
parameter, here's the default type conversion chart for .NET PInvoke:

http://msdn.microsoft.com/library/d...cpguide/html/cpconplatforminvokedatatypes.asp

If you need to pass a string buffer aka if the C++ declaration expects "char
sz[21]" then you can do that with a MarshalAs UnmanagedType.ByValTStr or a
StringBuilder depending on your needs. PInvoke string marshalling is
discussed at length here:

http://msdn.microsoft.com/library/d...cpguide/html/cpconplatforminvokedatatypes.asp
 

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