PC Review


Reply
Thread Tools Rate Thread

accessing a function in a dll file

 
 
GEES
Guest
Posts: n/a
 
      21st Sep 2005
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







 
Reply With Quote
 
 
 
 
=?Utf-8?B?UmljaGFyZA==?=
Guest
Posts: n/a
 
      21st Sep 2005

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/de...edatatypes.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/de...edatatypes.asp


"GEES" wrote:

> 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
>
>
>
>
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Function - error accessing file message is displayed Pele Microsoft Access Macros 1 14th Apr 2005 04:57 PM
Accessing a Function Bill Martin -- (Remove NOSPAM from address) Microsoft Excel Misc 4 1st Jan 2005 05:46 AM
Accessing ActiveX VB function within C++ App Paul Brun Microsoft VC .NET 1 6th Aug 2004 02:48 PM
HELP: accessing phone function is CF liran_shahar Microsoft Dot NET Compact Framework 2 18th Nov 2003 06:02 AM
accessing asp .net function Mr. Roboto Microsoft Dot NET 2 29th Aug 2003 10:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 PM.