On Tue, 17 Aug 2004 09:34:37 +0300, Aristotelis E. Charalampakis wrote:
Hello all,
I suppose that this question is not uncommon, but I am unable to google the
answer. I have written a dll in C++ 6.0 (Math only!) which works perfectly
with VB 6.0.
Now that I am ready to pass to the .NET era, the question is simple: Will it
work? Do I have to make some modifications? Are there any problems with the
data types (doubles, floats etc)? how about strings?
Any insight will be appreciated. I want to be certain about this before I
start improving the dll (I dont want this work to be wasted - I ve seen this
movie before!)
TIA,
A.
If it worked in VB6 - then it will work in VB.NET. There are a couple of
things to be aware of though :)
1. Data type sizes have changed. In VB6 Integer is 16-bit and Long was
32-bit. In VB.NET, Short is 16-bit, Integer is 32-bit, and Long is 64-bit.
What that means, is that where you used Long in VB6, you'll want to use
Integer in VB.NET.
2. Strings - hmm, I'm not sure how to answer this one... See, for the most
part VB.NET lets you marshall strings pretty much the same way as you did
in VB6 (though, you can now call Unicode functions directly)... This is
fine, except if the API call is going to actually modify the string buffer.
In those cases it is better to declare your function as taking
System.Text.StringBuilder rather then String. This is more efficeint -
since StringBuilder is designed to be a mutable buffer, where is string is
designed to be immutable. Besides, even if the overhead doesn't bother you
- you have to do it that way in C# :)
3. Passing of structures (UDT's in VB6) is a bit different, but much more
flexible - in fact, you can even simulate unions by applying the right
marshaling attributes... No more byte array and RtlMoveMemory tricks
(Yay!).
Anyway, if you look up P/Invoke in the docs, you should be on your way.
There is a section on default marshaling and such that would probably be
helpful to you. If you have any further questions problems, feel free to
post here and I'm sure someone can lend you a hand.
--
Tom Shelton [MVP]