471,319 Members | 3,224 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

C# dll import function returning -1

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
4 4123
>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
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
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
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.

Similar topics

26 posts views Thread by Adam Warner | last post: by
2 posts views Thread by pendell | last post: by
26 posts views Thread by aruna.mysore | last post: by
13 posts views Thread by Sri Harsha Dandibhotla | last post: by
13 posts views Thread by Rafe | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.