1) P/Invoke is suitable for calling exported functions in a DLL. You can certainly do that to call functions in a DLL. However, this is mainly viewed, INHO, as a transition step, particularly for Win32 APIs and such. You will suffer performance penalties with P/Invoke - Microsoft claims between "10 and 30 x86 instructions per call." That is for isomorphic types and no marshaling. With Marshaling it goes up from there.
2) IJW is a marvelous technology. Recompiling with the /clr switch does produce an assembly but the caution is none of the data is then managed. At this point, the code can only be used by other Managed C++ clients. However, what you can do, and I show in my chapter, is how to write a Managed C++ wrapper around the unmanaged code. Once you do this, your code can be accessible to VB.NET, C# and the all time best selling favorite Haskel.NET transparently as a managed piece of code. If you have the source code, and C++ knowledge, this is by far, the better way to go. IJW and then wrapper calls through C++ are faster than P/Invoke and you don't have to go through the Platform. You have a managed "façade" into/over your unmanaged code such that you can access it completely in the managed world. This is what I usually do. VB.NET to Managed C++ will at least all be managed. You will take a hit in the wrapper transitioning to unmanaged but not as much as P/Invoke. Also, this is a great first step to transitioning the C++ code to managed if you want to go that route. MC++ is the only language that allows you to mix managed and unmanaged in the same module, even same method. This allows you to migrate a little bit at at time - one line at a time if you want rather than all at once. IMHO, very powerful. I have employed this route with several clients and it has worked extremely well. HTH, Don't hesitate to ask more questions! Sam Gentile Co-Author Wrox Professional Visual C++.NET (ISBN 1861005962 ) [EMAIL PROTECTED] www.project-inspiration.com/sgentile http://www.project-inspiration.com/sgentile/DotNet.htm BLOG: http://radio.weblogs.com/0105852/ http://www.project-inspiration.com/sgentile/ScienceFiction.htm -----Original Message----- From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of Brad Wilson Sent: Thursday, May 16, 2002 10:18 AM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] IJW and P/Invoke Madhu Cheriyedath wrote: > 1) Use P/Invoke in Visual Basic.NET and call the functions in the DLL This should certainly work, and is the path of least resistance, especially since I'm assuming that the DLL currently just exports a bunch of functions (since you couldn't have directly consumed a C++ class from VB4). > 2) Recompile the C++ DLL using IJW switch so that it will be a managed one. Compiling with /CLR doesn't buy you anything until you have managed classes wrapping the existing C++ classes and/or functions. This is more work, but depending on your needs, may also offer more flexibility (because you get to move things into objects that can not only be created, but extended). >From what little details you provided, my guess is that you should probably start with #1, and really only approach #2 if you need additional support (especially if you plan to eventually port the unmanaged C++ to purely managed C++ or even C#). Brad -- Read my web log at http://www.quality.nu/dotnetguy/ You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.