PC Review


Reply
Thread Tools Rate Thread

calling from c# into a dll

 
 
=?Utf-8?B?QWwgdGhlIHByb2dyYW1tZXI=?=
Guest
Posts: n/a
 
      17th Mar 2005
I have a dll that consists of unmanaged C++ routines. I can call a function
in the dll from a C++ executable, but not from a C# executable. I am calling
an independent function, not a class. C# gives me a runtime exception saying
the entry point to the dll cannot be found.

I declare the function in C# with the following lines:
[DllImport("simpleDLL.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int fnsimpleDLL(int i);

I then call the function with the line:
fnsimpleDLL(1);

Any ideas?
 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      17th Mar 2005
Make sure the exported C function is not mangled (has C linkage), make also
sure the calling convention is cdecl (CallingConvention.Cdecl)]).

Willy.

"Al the programmer" <(E-Mail Removed)> wrote in
message news:1466DA50-01F4-4B7A-9324-(E-Mail Removed)...
>I have a dll that consists of unmanaged C++ routines. I can call a
>function
> in the dll from a C++ executable, but not from a C# executable. I am
> calling
> an independent function, not a class. C# gives me a runtime exception
> saying
> the entry point to the dll cannot be found.
>
> I declare the function in C# with the following lines:
> [DllImport("simpleDLL.dll", CallingConvention=CallingConvention.Cdecl)]
> public static extern int fnsimpleDLL(int i);
>
> I then call the function with the line:
> fnsimpleDLL(1);
>
> Any ideas?



 
Reply With Quote
 
=?Utf-8?B?QWwgdGhlIHByb2dyYW1tZXI=?=
Guest
Posts: n/a
 
      18th Mar 2005
Thanks for the info. I remember the mangling issue from when I had to call C
code from C++, but the C# docs are silent on the issue.

What do I do when I want to export a C++ class in a dll to a C# program?

Al


"Willy Denoyette [MVP]" wrote:

> Make sure the exported C function is not mangled (has C linkage), make also
> sure the calling convention is cdecl (CallingConvention.Cdecl)]).
>
> Willy.
>
> "Al the programmer" <(E-Mail Removed)> wrote in
> message news:1466DA50-01F4-4B7A-9324-(E-Mail Removed)...
> >I have a dll that consists of unmanaged C++ routines. I can call a
> >function
> > in the dll from a C++ executable, but not from a C# executable. I am
> > calling
> > an independent function, not a class. C# gives me a runtime exception
> > saying
> > the entry point to the dll cannot be found.
> >
> > I declare the function in C# with the following lines:
> > [DllImport("simpleDLL.dll", CallingConvention=CallingConvention.Cdecl)]
> > public static extern int fnsimpleDLL(int i);
> >
> > I then call the function with the line:
> > fnsimpleDLL(1);
> >
> > Any ideas?

>
>
>

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      18th Mar 2005

"Al the programmer" <(E-Mail Removed)> wrote in
message news:017E109C-8812-44AB-B950-(E-Mail Removed)...
> Thanks for the info. I remember the mangling issue from when I had to
> call C
> code from C++, but the C# docs are silent on the issue.
>
> What do I do when I want to export a C++ class in a dll to a C# program?
>
> Al
>
>


Check this....
http://msdn2.microsoft.com/library/e59b22c5.aspx

Willy.


 
Reply With Quote
 
=?Utf-8?B?QWwgdGhlIHByb2dyYW1tZXI=?=
Guest
Posts: n/a
 
      18th Mar 2005
Thanks for the info. The docs don't talk about importing a class, only
functions, but I know where to start looking in the future. For my current
project I need to access C functions, which I can do.

Al

"Willy Denoyette [MVP]" wrote:

>
> "Al the programmer" <(E-Mail Removed)> wrote in
> message news:017E109C-8812-44AB-B950-(E-Mail Removed)...
> > Thanks for the info. I remember the mangling issue from when I had to
> > call C
> > code from C++, but the C# docs are silent on the issue.
> >
> > What do I do when I want to export a C++ class in a dll to a C# program?
> >
> > Al
> >
> >

>
> Check this....
> http://msdn2.microsoft.com/library/e59b22c5.aspx
>
> Willy.
>
>
>

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      18th Mar 2005

"Al the programmer" <(E-Mail Removed)> wrote in
message news:66BAFFCC-886E-435D-BC81-(E-Mail Removed)...
> Thanks for the info. The docs don't talk about importing a class, only
> functions, but I know where to start looking in the future. For my
> current
> project I need to access C functions, which I can do.
>
> Al
>


It doesn't talk about importing a class because it isn't possible to access
unmanaged classes cross-language.
If you need this, your only option is to create a wrapper class using
managed C++ (or better the upcoming C++/CLI)., this wrapper simply delegates
the accesses from managed code into unmanaged C++.

Willy.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio jeeji Microsoft C# .NET 1 29th Jun 2006 10:43 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM
Fail to send fax when making international fax calling / calling c =?Utf-8?B?c2Ftd2lzZQ==?= Windows XP Help 1 28th Dec 2004 02:31 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= Microsoft ASP .NET 1 28th Sep 2004 01:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.