Problems with DllImport 
Author Message
 Problems with DllImport

Hi!
I'm trying to import a function from a Win32-dll in C#, but I get an
exception telling me "Unable to find an entry point named fnDllTest in DLL
DllTest.dll."

I tried import the dll (and lib) file in a Win32 console application and it
works just fine.

Here is my code:
DllTest.h
__declspec(dllexport) int fnDllTest(void);

LibWrap.cs
public class LibWrap
{
  public LibWrap()
  {
  }

  [DllImport("DllTest.dll" )]
  public static extern int fnDllTest();

Quote:
}

And in my main cs-file
int i = LibWrap.fnDllTest();

Can someone please tell me what I'm doing wrong?
/Henke



Mon, 28 Mar 2005 15:39:32 GMT  
 Problems with DllImport
Henke,

The function is probably exported with a mangled name. You can use
Dumpbin /exports or Dependency Walker to see the actualy export name.

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Mon, 28 Mar 2005 16:16:49 GMT  
 Problems with DllImport
Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)



it works fine.
So this is the way to do it, looking the name up with Depends and add the
entry point I mean?

/Henke


Quote:
> Henke,

> The function is probably exported with a mangled name. You can use
> Dumpbin /exports or Dependency Walker to see the actualy export name.

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Mon, 28 Mar 2005 17:48:30 GMT  
 Problems with DllImport
Henke, when you have a mangled name, yes, that's the way to do it.  If you
have control over the C dll you can force it not to mangle the name and save
yourself the importing trouble.

--
Greg Ewing [MVP]
http://www.claritycon.com/


Quote:
> Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)



> it works fine.
> So this is the way to do it, looking the name up with Depends and add the
> entry point I mean?

> /Henke



> > Henke,

> > The function is probably exported with a mangled name. You can use
> > Dumpbin /exports or Dependency Walker to see the actualy export name.

> > Mattias

> > ===

> > http://www.msjogren.net/dotnet/
> > Please reply only to the newsgroup.



Mon, 28 Mar 2005 21:48:37 GMT  
 Problems with DllImport
Ok ,Greg I guess that's what the extern "C" does isn't it?
/Henke



Quote:
> Henke, when you have a mangled name, yes, that's the way to do it.  If you
> have control over the C dll you can force it not to mangle the name and
save
> yourself the importing trouble.

> --
> Greg Ewing [MVP]
> http://www.claritycon.com/



> > Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)



now
> > it works fine.
> > So this is the way to do it, looking the name up with Depends and add
the
> > entry point I mean?

> > /Henke



> > > Henke,

> > > The function is probably exported with a mangled name. You can use
> > > Dumpbin /exports or Dependency Walker to see the actualy export name.

> > > Mattias

> > > ===

> > > http://www.msjogren.net/dotnet/
> > > Please reply only to the newsgroup.



Mon, 28 Mar 2005 22:58:26 GMT  
 Problems with DllImport
Yep.


Quote:
> Ok ,Greg I guess that's what the extern "C" does isn't it?
> /Henke



> > Henke, when you have a mangled name, yes, that's the way to do it.  If
you
> > have control over the C dll you can force it not to mangle the name and
> save
> > yourself the importing trouble.

> > --
> > Greg Ewing [MVP]
> > http://www.claritycon.com/



> > > Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)



> now
> > > it works fine.
> > > So this is the way to do it, looking the name up with Depends and add
> the
> > > entry point I mean?

> > > /Henke



> > > > Henke,

> > > > The function is probably exported with a mangled name. You can use
> > > > Dumpbin /exports or Dependency Walker to see the actualy export
name.

> > > > Mattias

> > > > ===

> > > > http://www.msjogren.net/dotnet/
> > > > Please reply only to the newsgroup.



Mon, 28 Mar 2005 23:09:00 GMT  
 Problems with DllImport
Hej Henke,

Quote:
>Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)

Jod? det f?r man v?l om man vill, men det minskar ju l?sarkretsen
drastiskt, och d?rmed chansen att f? ett bra svar.

Quote:
>So this is the way to do it, looking the name up with Depends and add the
>entry point I mean?

What Greg said.

In addition to that, you should set the calling convention (with
DllImport.CallingConvention) to cdecl to match the C code. It might
not matter in this case since the function doesn't take any
parameters, but for other functions it does.

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Tue, 29 Mar 2005 04:30:05 GMT  
 Problems with DllImport
Thanks everybody, it works fine now.
/Henke


Quote:
> Hej Henke,

> >Thanks Mattias, (man f?r inte skriva p? svenska h?r va?)

> Jod? det f?r man v?l om man vill, men det minskar ju l?sarkretsen
> drastiskt, och d?rmed chansen att f? ett bra svar.

> >So this is the way to do it, looking the name up with Depends and add the
> >entry point I mean?

> What Greg said.

> In addition to that, you should set the calling convention (with
> DllImport.CallingConvention) to cdecl to match the C code. It might
> not matter in this case since the function doesn't take any
> parameters, but for other functions it does.

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Tue, 29 Mar 2005 19:14:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. problem about dllimport

2. DllImport Problem

3. VC7 dllimport regression problem

4. dllimport and link warning problem

5. Help!!! dllimport and dllexport problem

6. dllimport problem ???

7. dllimport CString problem from VC7 to VC6

8. problem using dll in aplikation Link error: "__declspec(dllimport)

9. dllimport/export problem upgrading to STLPort 4.5 (under Visual C++ 6.0)

10. DllImport problem

11. Can a [WebMethod] supports DllImport and WMI?

12. DLLImport Decorating

 

 
Powered by phpBB® Forum Software