C# dll import function returning -1

O

ofmars

Hi there,


In C# I'm using a DLL import attribute to call a function from this
DLL. This function was written in an older version of Vb and I know the

name of this function and it should return an integer.


public class Class1
{
[DllImport("DllDemo")]
public static extern int Initiliase(string Path);



}


// in Main Form
pathos = "initialisepath"
retval = Class1.Initialise(pathos);
Console.WriteLine(retval);

The DLL is found ... however this integer function I'm using, I'm
passing to it a string value which is this a case is a path to an INI
file. But its returning to me a -1 integer value and making Beep sound.



I'm passing a correct path. I tried to pass a garbaged string like
"dsfs3rt" to see if the problem was coming from the path but its
returning to me the same -1 integer value and making a beep sound.


I cannot see what this -1 means. Maybe I'm missing something. Maybe its

an error that doesn't stop the program.


Any help appreciated :)
Thanks
 
T

Truong Hong Thi

This function was written in an older version of Vb
DllImportAttribute is used to call traditional windows DLL. I am not
aware that vb can produce such DLL, it can only produce COM (ActiveX)
DLL.
 
V

Varangian

Thanks for the reply :)

I'm writing the application in C#.NET not in Vb. The Dllimportattribute
is used in the C# Win32
 
A

Abubakar

What version of vb was it made in? VB could only make activex dlls. .Net
provides support for using com components. You dont have to do anything
special for this dll function. Just add a reference to it and create a new
object and call the method. It should work.

Ab.
http://joehacker.blogspot.com
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Varangian said:
Thanks for the reply :)

I'm writing the application in C#.NET not in Vb. The Dllimportattribute
is used in the C# Win32

He means that VB could not create a native win32 dll, you could only create
COM dlls, therefore you cannot use dllimport. All you have to do is include
a reference to the dll using "Add Reference" and the IDE will create a
wrapper for you.


cheers,
 

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