By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Dll written in C++ 6.0, will it work in vb.net?

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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]
Nov 21 '05 #2

P: n/a
Aristotelis,

(copied from MSDN)

The Visual Basic 6.0 Long data type is now the Visual Basic .NET Integer
data type, and the Visual Basic 6.0 Integer data type is now the Visual
Basic .NET Short data type.

I hope this helps?

Cor

Nov 21 '05 #3

P: n/a
* "Aristotelis E. Charalampakis" <ar********@technologismikiREMOVEIT.com> scripsit:
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?


It will work with VB.NET.

Keywords: P/invoke, 'Declare', 'DllImportAttribute'. There is a lot of
information about these topics available in the documentation.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4

P: n/a
Sure it helps... Thanks both of you. 8-]

Well, I don't mind declaring the functions to return integer instead of
long... Since the double data type has not changed, I should be ok.

Howrver, the UDTs issue is very important; Up to now I worked like this:
/*
In order to use within VB, add these types:

Public Type wPoint2D
X As Single
Y As Single
End Type

Public Type wLine2D
P1 As wPoint2D
P2 As wPoint2D
End Type
*/

/*
================================================== =========================

w3Point2DIsLeft(): Test if a point is Left|On|Right of an infinite line

Input: Pointer to three wPoint2D structures, Pt0, Pt1, Pt2
Returns: >0 if Pt2 left of the line
=0 if Pt2 on the line
<0 if Pt2 right of the line
Use within VB:
Public Declare Function w3Point2DIsLeft Lib "mydll.dll" (wPoint2D0 As Any,
wPoint2D1 As Any, wPoint2D2 As Any) As Single

================================================== =========================
*/
float _stdcall w3Point2DIsLeft( wPoint2D* Pt0, wPoint2D* Pt1, wPoint2D* Pt2)
{
return (float)( (Pt1[0].X-Pt0[0].X)*(Pt2[0].Y-Pt0[0].Y)
- (Pt2[0].X-Pt0[0].X)*(Pt1[0].Y-Pt0[0].Y) );
}

also:

typedef struct {float X, Y;} wPoint2D;
typedef struct {wPoint2D P1, P2;} wLine2D;

Since I am not a master in C++, I am not really sure if this is the optimal
way to work.

I guess this is way off topic, though.

Thanx a lot.

A.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
Aristotelis,

(copied from MSDN)

The Visual Basic 6.0 Long data type is now the Visual Basic .NET Integer
data type, and the Visual Basic 6.0 Integer data type is now the Visual
Basic .NET Short data type.

I hope this helps?

Cor

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.