Calling unmanaged member functions from C# (again) 
Author Message
 Calling unmanaged member functions from C# (again)

Hello, I can't belive there's no way to call member
functions from unmanaged DLLs using C#?!
Apparently DLLImport doesn't work since it seems to be
suitable only for global & static functions, and in case
of member functions when instance of the class has somehow
(HOW?!) be created so that 'this' is properly passed it
doesn't work.
In managed C++ using IJW feature it isn't a problem at
all, but writing managed wrapers in C++ in order to just
call them from C# sounds very tedious.
Doesn't C# which MS claims to be the most sutable language
for .NET development have something to address this
problem?
Thanks in advance,
Arthur.


Sun, 03 Apr 2005 23:51:41 GMT  
 Calling unmanaged member functions from C# (again)
Arthur,

    Unfortunately, no, but the key here is that we are talking about .NET
development, which your unmanaged code is not.  The best alternatives you
have now are to create managed wrappers or to expose them as COM object
(which might be easier).

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> Hello, I can't belive there's no way to call member
> functions from unmanaged DLLs using c#?!
> Apparently DLLImport doesn't work since it seems to be
> suitable only for global & static functions, and in case
> of member functions when instance of the class has somehow
> (HOW?!) be created so that 'this' is properly passed it
> doesn't work.
> In managed C++ using IJW feature it isn't a problem at
> all, but writing managed wrapers in C++ in order to just
> call them from C# sounds very tedious.
> Doesn't C# which MS claims to be the most sutable language
> for .NET development have something to address this
> problem?
> Thanks in advance,
> Arthur.



Sun, 03 Apr 2005 23:57:02 GMT  
 Calling unmanaged member functions from C# (again)
It is possible, but only by adding some code to the DLL.
Check sample for 'CallingConvention.ThisCall'

 ... FrameworkSDK\Samples\Technologies\Interop\PlatformInvoke\Custom\CS\ClassMethods.cs

sure, you have to write MUCH code.

Note, .NET is a new generation tool,
thus providing only limited interoperability with legacy code.

--
 Thomas Scheidegger - MVP .NET - 'NETMaster'
 http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/

Quote:

> Hello, I can't belive there's no way to call member
> functions from unmanaged DLLs using c#?!
> Apparently DLLImport doesn't work since it seems to be
> suitable only for global & static functions, and in case
> of member functions when instance of the class has somehow
> (HOW?!) be created so that 'this' is properly passed it
> doesn't work.
> In managed C++ using IJW feature it isn't a problem at
> all, but writing managed wrapers in C++ in order to just
> call them from C# sounds very tedious.
> Doesn't C# which MS claims to be the most sutable language
> for .NET development have something to address this
> problem?



Mon, 04 Apr 2005 02:54:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

2. problem passing unmanaged pointer from one managed member function to another

3. Call C# dll from unmanaged C++

4. Unmanaged C++ calling GUI in C#

5. Unmanaged DLL calling a C# class

6. example of unmanaged C++ calling C# ?

7. Calling unmanaged code from ASP.NET (C#)

8. Macro to check function return, calling function again?

9. Unmanaged C++ calling managed C# dll

10. Call C++ member function from C function ?

11. Calling C++ member function through C function callback

12. Calling an unmanaged DLL function that uses a std::string parameter

 

 
Powered by phpBB® Forum Software