How to call unmanaged code from managed code?

Hi,

I am very new to the .Net frame work and the whole idea of managed and unmanaged code. I have a question though. The latest version of VC++.Net makes it so simple and easy to design UIs thanks to its drag and drop approach (which had been an integral part of VB). However, my program is supposed to perform some very intensive mathematical routines. For that part, I don't want my code to be managed as that would slow things down considerably (because CLR would be involved). Is there a way that I could do the math as unmanaged code and then call it in my managed code (comprising mainly of the front end). I came across a couple of articles on the web about calling managed code from unmanaged code but my case is sort of the opposite.

Any help would be appreciated.

Thanks a lot

M


Answer this question

How to call unmanaged code from managed code?

  • Joao Costa

    With Visual C++ nothing is simpler. You can easily mix managed and native classes and code. Here's a link to an article that will hopefully get you started.

    http://msdn2.microsoft.com/en-us/library/ms235282(en-US,VS.80).aspx



  • fast_

    That would depend on exactly how you decide to structure your application. You can compile 100% native C++ so that it runs on the CLR: just take a small 100% native C++ application and add /clr to the cmd-line and you'll see that it will compile and run).

    Or you can keep you native compiled for the native processor and use several mechanism to interface between the native code and the managed code. The article I linked (and several associated articles) address all these issue.

    I will say that as with all performance related questions measurement is the key. Do you know that your application will run slower on the CLR If so by how much Don't assume that the CLR is always slower - it isn't

  • RTS4ME

    Thanks Jonathan.. Just one quick question. Would this approach then make the code work faster, as the CLR would be bi-passed for the mathematical routines
  • How to call unmanaged code from managed code?