By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

C# dll import function returning -1

P: n/a
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

Dec 9 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>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.

Dec 9 '05 #2

P: n/a
Thanks for the reply :)

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

Dec 9 '05 #3

P: n/a
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

<of****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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

Dec 9 '05 #4

P: n/a
Hi,
"Varangian" <of****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Dec 9 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.