Accessing from C# to an vb dll

  • Thread starter Thread starter jaume.pf
  • Start date Start date
J

jaume.pf

Hi,

I've a vb dll with a function that i want to access from C#. I'm using
the following:

public class library
{
[DllImport("myDll.dll", CharSet = CharSet.Auto, EntryPoint =
"clsLibrary")]
public static extern void create();
}

and:

library.create();

but i'm getting Sytem.DllNotFoundException. Nothing helped to add the
library to the references of my C# project.

I don't know what can i be doing wrong. I don't know if i have to make
the call in another way, or maybe i've to compile my vb library in a
particular way. Can anybody help me?

Thank you very much for your time!
 
Hi,

| Hi,
|
| I've a vb dll with a function that i want to access from C#. I'm using
| the following:
|
| public class library
| {
| [DllImport("myDll.dll", CharSet = CharSet.Auto, EntryPoint =
| "clsLibrary")]
| public static extern void create();
| }

IIRC VB never generated native win32 dll, but COM dlls, if that is so all
you have to do to include your dll is select Add a Reference, go to COM and
look for it. This will create a wrapper to your dll that you can use
directly in your code as any other .NET namespace.
 
First of all, thanks for the answers!

At runtime, my library is not in the same folder even the same disk
than the code i'm executing, but the dll is registered in the system,m
i thought it should be enough. Where i should to place the library,
according the code?

Anyway, i added my library to the reference list (i don't know whether
as a COM object or not), but i'm still unable to us it as a .net
code...

Thanks!

JAUME
 
Finally i achieved that to work as a .net code... but there's still a
problem: at runtime, when i try to access to the library method, get an
'object required' exception
(system.runtime.InteropServices.COMException).

how can i solve that? have i to place my library in any special path?

thanks to all!

JAUME

First of all, thanks for the answers!

At runtime, my library is not in the same folder even the same disk
than the code i'm executing, but the dll is registered in the system,m
i thought it should be enough. Where i should to place the library,
according the code?

Anyway, i added my library to the reference list (i don't know whether
as a COM object or not), but i'm still unable to us it as a .net
code...

Thanks!

JAUME
Hi,

| Hi,
|
| I've a vb dll with a function that i want to access from C#. I'm using
| the following:
|
| public class library
| {
| [DllImport("myDll.dll", CharSet = CharSet.Auto, EntryPoint =
| "clsLibrary")]
| public static extern void create();
| }

IIRC VB never generated native win32 dll, but COM dlls, if that is so all
you have to do to include your dll is select Add a Reference, go to COM and
look for it. This will create a wrapper to your dll that you can use
directly in your code as any other .NET namespace.
 
Hi,

| First of all, thanks for the answers!
|
| At runtime, my library is not in the same folder even the same disk
| than the code i'm executing, but the dll is registered in the system,m
| i thought it should be enough. Where i should to place the library,
| according the code?

It does not matter, as long as the dll is registered in the system you are
ok.

| Anyway, i added my library to the reference list (i don't know whether
| as a COM object or not), but i'm still unable to us it as a .net
| code...

are you including the using directive?
like using Interop.MyDLL
 

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

Back
Top