Calling dll

  • Thread starter Finn Stampe Mikkelsen
  • Start date
F

Finn Stampe Mikkelsen

Hi

I have a problem. I need to use routines i have previously called using
below code from Pascal :

PROCEDURE pGetVersionNr(
var AVersionNr : word); pascal; external 'raccd32a.dll';


PROCEDURE pCheckDatabaseFormat(
ADriveInfo : pointer;
var AResult : word;
var AErrorCode : SmallInt); pascal; external 'raccd32a.dll';

PROCEDURE pGetCallInfo(
DriveInfo: pointer;
ACall: pointer;
AInfo: pointer;
var AErrorCode: SmallInt); pascal; external 'raccd32a.dll';

Now i need to do this in C# and i have tried using this declaration:

[DllImport(@"M:\tsrDll\WIN32\raccd32a", EntryPoint =
"sGetVersionNr",
ExactSpelling = false, CallingConvention =
CallingConvention.StdCall)]
static extern void sGetVersionNr(ref int AVersionNr);

[DllImport(@"M:\tsrDll\WIN32\raccd32a", EntryPoint =
"sCheckDatabaseFormat",
ExactSpelling = false, CallingConvention =
CallingConvention.StdCall)]
static extern void sCheckDatabaseFormat(string ADriveInfo, ref int
AResult, ref int AErrorCode);

[DllImport(@"M:\tsrDll\WIN32\raccd32a", EntryPoint = "sGetCallInfo",
ExactSpelling = false, CallingConvention =
CallingConvention.StdCall)]
static extern void sGetCallInfo(ref string ADriveInfo, ref string
ACall, ref string AInfo, ref int AErrorCode);

sGetVersionNr and sCheckDatabaseFormat function okay. sGetCallInfo however
does not and i have an idea, that it is the use of pointer.

In Pascal i used this call to the dll : pGetCallInfo(@DriveInfo, @Call,
@Info, ErrorCode);

Here is the code i'm using now in C#:

sGetCallInfo(ref ADriveInfo, ref ACall, ref Ainfo, ref
AErrorCode); // Does NOT work

sCheckDatabaseFormat(ADriveInfo, ref AResult, ref AErrorCode);
// Works OKAY

Anyone?? Help will me much appreciated.. ;-))

/Finn
--
Der er 10 slags mennesker - Dem som forstår binær og dem som ikke gør.
There are 10 kinds of people. Those who understand binary and those who
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.

--
Der er 10 slags mennesker - Dem som forstår binær og dem som ikke gør.
There are 10 kinds of people. Those who understand binary and those who
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.
 
F

Finn Stampe Mikkelsen

Finn Stampe Mikkelsen said:
Hi

I have a problem. I need to use routines i have previously called using
below code from Pascal :

This code in VB works perfectly:

Declare Sub sGetVersionNr Lib "M:\tsrDll\win32\raccd32a" (ByRef
AVersionNr As Integer)
Declare Sub sCheckDatabaseFormat Lib "M:\tsrDll\win32\raccd32a" (ByVal
ADriveInfo As String, ByRef AResult As Integer, ByRef AErrorCode As Integer)
Declare Sub sGetCallInfo Lib "M:\tsrDll\win32\raccd32a" (ByVal
ADriveInfo As String, ByVal ACall As String, ByVal AInfo As String, ByRef
AErrorCode As Integer)


Call sGetVersionNr(AResult)

ADriveInfo = "m:\"

AInfo = Space$(500)

Call sCheckDatabaseFormat(ADriveInfo, AResult, AErrorCode)


'ADriveInfo = "m:\"

AInfo = Space$(500)

'ACall = "w1aw"

Call sGetCallInfo(ADriveInfo, ACall, AInfo, AErrorCode)

What am i doing wrong in C#??

/Finn
 
P

Patrice

You are using the ref keyword for your string parameters on this call (but
Pascal and VB seems to use the same declaration for all methods so I believe
you mistakenly used ref parameters).
 
F

Finn Stampe Mikkelsen

Patrice said:
You are using the ref keyword for your string parameters on this call (but
Pascal and VB seems to use the same declaration for all methods so I
believe you mistakenly used ref parameters).

Hi Patrice

Nope.. Tried to remove the ref from all parameters other than AErrorCode,
which is needed to be a ref.. Get an error of writing to memory vialation
otherwise..

So, it's not that..

/Finn
--
Der er 10 slags mennesker - Dem som forstår binær og dem som ikke gør.
There are 10 kinds of people. Those who understand binary and those who
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.
 
P

Patrice

Nope.. Tried to remove the ref from all parameters other than AErrorCode,
which is needed to be a ref.. Get an error of writing to memory vialation
otherwise..

And the error you had with the previous version was the same ?

If I decompile the VB declaration using Reflector it comes with :

[DllImport(@"M:\tsrDll\win32\raccd32a", CharSet=CharSet.Ansi,
SetLastError=true, ExactSpelling=true)]
public static extern void sGetCallInfo([MarshalAs(UnmanagedType.VBByRefStr)]
ref string ADriveInfo, [MarshalAs(UnmanagedType.VBByRefStr)] ref string
ACall, [MarshalAs(UnmanagedType.VBByRefStr)] ref string AInfo, ref int
AErrorCode);

If it still doesn't work not sure what to try next (hopefully someone else
will help).
 
F

Finn Stampe Mikkelsen

Patrice said:
Nope.. Tried to remove the ref from all parameters other than AErrorCode,
which is needed to be a ref.. Get an error of writing to memory vialation
otherwise..

And the error you had with the previous version was the same ?

If I decompile the VB declaration using Reflector it comes with :

[DllImport(@"M:\tsrDll\win32\raccd32a", CharSet=CharSet.Ansi,
SetLastError=true, ExactSpelling=true)]
public static extern void
sGetCallInfo([MarshalAs(UnmanagedType.VBByRefStr)] ref string ADriveInfo,
[MarshalAs(UnmanagedType.VBByRefStr)] ref string ACall,
[MarshalAs(UnmanagedType.VBByRefStr)] ref string AInfo, ref int
AErrorCode);

If it still doesn't work not sure what to try next (hopefully someone else
will help).

Hi Patrice....

YEAH... That one worked... I must have a look at that Reflector... ;-))

Thanks a million...

/Finn
--
Der er 10 slags mennesker - Dem som forstår binær og dem som ikke gør.
There are 10 kinds of people. Those who understand binary and those who
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.
 

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

Similar Threads

WebBrowser content 3

Top